![]() |
![]() |
||||||
|
|||||||
| Tags: according, defining, digits, first, ofcode, recordset, three |
![]() |
|
|||
|
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 $query_rs_allcourses = sprintf("SELECT * FROM courses WHERE coursecode LIKE CONCAT('%%', %s, '%%') ORDER BY title ASC", GetSQLValueString($colname_rs_allcourses, "text")); $rs_allcourses = mysql_query($query_rs_allcourses, $con_dcc) or die(mysql_error()); $row_rs_allcourses = mysql_fetch_assoc($rs_allcourses); $totalRows_rs_allcourses = mysql_num_rows($rs_allcourses); |
| Sponsored Links |
|
|||
|
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 |
|
|||
|
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 $unstrippedcode = $_GET['code']; $strippedcode = substr($unstrippedcode,0,3); $colname_rs_allcourses = "-1"; if (isset($strippedcode)) { $colname_rs_allcourses = (get_magic_quotes_gpc()) ? $strippedcode : addslashes($strippedcode); } mysql_select_db($database_con_dcc, $con_dcc); $query_rs_allcourses = sprintf("SELECT * FROM courses WHERE coursecode LIKE '$strippedcode'", GetSQLValueString($colname_rs_allcourses, "text")); $rs_allcourses = mysql_query($query_rs_allcourses, $con_dcc) or die(mysql_error()); $row_rs_allcourses = mysql_fetch_assoc($rs_allcourses); $totalRows_rs_allcourses = mysql_num_rows($rs_allcourses); |
|
|||
|
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%'"); |
|
|||
|
Thanks Mike,
Before I made your changes I had no error message just no data in the drop down menu thats populated by the recordset. After I change the line you suggested I get a white screen with - 'Query was empty" on it. Seems your changes are getting me closer. Any more suggestions. Cheers Dave |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise