Jaume_hernandez Posted July 21, 2011 Share Posted July 21, 2011 Hi all!!!I've adapted the code of http://www.w3schools.com/php/php_ajax_livesearch.aspto my MySQL table so I can show a live search with AJAX. Evething looks fine but when I choose the category a get an error mesage:Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\UsedMachines\getuser.php on line 25PLEASE! anyone can help??????JaumeI copy the code---------------------------------------------------------------------------------------<?php$q=$_GET["q"];$con = mysql_connect('localhost', 'UsedMachines', 'jauman');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("usedmachines", $con);$sql="SELECT * FROM usedmachines WHERE family = '".$q."'";$result = mysql_query($sql);echo "<table aling=center><tr><th>Family</th><th>Model</th><th>Hours</th><th>Price</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Family'] . "</td>"; echo "<td>" . $row['Model'] . "</td>"; echo "<td>" . $row['Hours'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?>------------------------------------------------------------------------------------- Link to comment Share on other sites More sharing options...
HungryMind Posted July 21, 2011 Share Posted July 21, 2011 Hi all!!!I've adapted the code of http://www.w3schools.com/php/php_ajax_livesearch.aspto my MySQL table so I can show a live search with AJAX. Evething looks fine but when I choose the category a get an error mesage:Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\UsedMachines\getuser.php on line 25PLEASE! anyone can help??????JaumeI copy the code---------------------------------------------------------------------------------------<?php$q=$_GET["q"];$con = mysql_connect('localhost', 'UsedMachines', 'jauman');if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("usedmachines", $con);$sql="SELECT * FROM usedmachines WHERE family = '".$q."'";$result = mysql_query($sql);echo "<table aling=center><tr><th>Family</th><th>Model</th><th>Hours</th><th>Price</th></tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['Family'] . "</td>"; echo "<td>" . $row['Model'] . "</td>"; echo "<td>" . $row['Hours'] . "</td>"; echo "<td>" . $row['Price'] . "</td>"; echo "</tr>"; }echo "</table>";mysql_close($con);?>-------------------------------------------------------------------------------------IF your Database Field(Family) Nature Is Set To (Int), Then Try Without Single Quotes(')Yours: $sql="SELECT * FROM usedmachines WHERE family = '".$q."'";Mine: $sql="SELECT * FROM usedmachines WHERE family = ".$q;But This Code Is Working At My Side Link to comment Share on other sites More sharing options...
ShadowMage Posted July 21, 2011 Share Posted July 21, 2011 The error message means that your query failed. Try adding this code after you run the query: $result = mysql_query($sql); //This is where you run the query//Add this codeif (!$result) { die(mysql_error());} That should print out the last mysql error that occured, which should tell you why the query failed. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.