Skip to main content
Inspiring
March 5, 2008
Question

defining recordset according to first three digits of code

  • March 5, 2008
  • 1 reply
  • 514 views
I need to create a recordset which contains records matching the first three digits only of a URL parameter.

I have a recordset that contains records matching the code exactly (attached below)

I need also to create a recordset which contains records that match the first three digits ONLY of a URL parameter.
I guess it may also be an option to duplicate the parameter in the URL and restrict the duplicate to three digits only - that way making the creation of the recordset easy - but I don't know how to do that either.

Can anyone help me out with this one?

Cheers


Dave

This topic has been closed for replies.

1 reply

Inspiring
March 6, 2008
You could create a substring from your parameter and then use that in your query, if the URL variable was named strParam, you could do this in php
$param = $_GET['strParam'];
$paramThree = substr($param,0,3);
Then use the $paramThree in your query, you might want to include the sprintf for security.
Check this link
http://us3.php.net/manual/en/function.substr.php
Inspiring
March 6, 2008
Thanks Mike,

looks like that's probably the answer but when I start to make changes the Dreamweaver recordset panel doesn't seem to like it too much. Maybe I'm better just working in the code:

Anyway I've given it a go a few times and got myself pretty mixed up now. Here's the code I ended up with. Any idea where I'm going wrong?

Dave
Inspiring
March 7, 2008
What error message are you getting, probably in this line

$query_rs_allcourses = sprintf("SELECT * FROM courses WHERE coursecode LIKE '$strippedcode'", GetSQLValueString($colname_rs_allcourses, "text"));

Try this:
$query_rs_allcourses = sprintf("SELECT * FROM courses WHERE coursecode LIKE '%$strippedcode%'");