jd2007 Posted July 9, 2007 Share Posted July 9, 2007 <?php if (!$n) { include("search.php"); echo"No search term given."; } $name=explode(" ", $n); $namelen=count($name); if ($namelen==0) { include("connectdb.php"); $query = "SELECT * FROM Searching WHERE tags LIKE '%".$name."%'"; $result = mysql_query($query); while ($record = mysql_fetch_assoc($result)) { while (list($fieldname, $fieldvalue) = each ($record)) { echo $fieldname.": <B>".$fieldvalue."</B><BR>"; } echo "<BR>"; } } else {} ?> Link to comment https://forums.phpfreaks.com/topic/59053-is-there-anything-wrong-with-this-code/ Share on other sites More sharing options...
ToonMariner Posted July 9, 2007 Share Posted July 9, 2007 <?php if (!$_REQUEST['n']) { include("search.php"); echo"No search term given."; exit(); } $name=str_replace(' ','%', $_REQUEST['n']); $namelen=count($name); if ($namelen > 0) { include("connectdb.php"); $query = "SELECT * FROM Searching WHERE tags LIKE '%".$name."%'"; $result = mysql_query($query); while ($record = mysql_fetch_assoc($result)) { //while (list($fieldname, $fieldvalue) = each ($record)) { // echo $fieldname.": <strong>".$fieldvalue."</strong><br />"; //} echo "<br />"; } } else {} ?> I have commented out the the while loop as that part is a little confusing... list() only works on numerical arrays and mysql_fetch_assoc returns associative arrays (fieldnames as keys instead of numbers). it also relys on there being the correct fields in the correct order from the mysql_fetch_assoc. Now as I said mysql_fetch_assoc returns an associative array and we need a numerical one so that must change to mysql_fetch_row and the select query should select only the fields you want in the correct order... Link to comment https://forums.phpfreaks.com/topic/59053-is-there-anything-wrong-with-this-code/#findComment-293136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.