I need help with this program

0 Kumi Festus · October 31, 2014
I want to query a database to display search queries instantly.
This is the warning message:mysql_fetch_assoc() expects parameter 1 to be resource, integer 

See The Code Below:
<form action="index.php" method="post">
Start Searching<input type="text" name="search_term" id="search" size="60"/>
<span id="search_results"></span>

The Script

    var search_term = $(this).val();


require 'db.php';
$search_term = mysql_real_escape_string(htmlentities($_POST["search_term"]));
    $search = mysql_query("SELECT place,description FROM tbl1 WHERE place LIKE '%$search_term%'");
    $result_count = mysql_num_rows($search);
    $suffix = ($result_count !=1) ? 's':'';
    while($results_row = mysql_fetch_assoc($result_count)){
    echo "<p><strong>",$results_row['place'],"</strong><br/>",$results_row['description'],"</p>";



I'm sure there is nothing wrong with code, well maybe.

Post a Reply


Oldest  Newest  Rating
+1 Ron Butcher · October 31, 2014
You are getting that message because it expects the argument passed to mysql_fetch_assoc to be the query resource, not the number of rows.

Change the while loop to this:

while($results_row = mysql_fetch_assoc($search))

One more thing, you should start looking at mysqli (MySQL Enhanced) or PDO instead of mysql.  That extension has been depreciated and is going to be removed from PHP all together pretty soon.
0 Kumi Festus · November 1, 2014
Thanks a lot. I figured that out later.

I will look into your suggestion, Thanks
0 Kumi Festus · November 2, 2014
I am testing this program on my local computer bundled with XAMPP. Is it possible to switch on the local computer?
0 Kumi Festus · November 2, 2014
I means this is not a program I am going to upload on a live server. I am learning now and this database is on XAMPP.
0 Ron Butcher · November 2, 2014
Yes you can use mysqli or PDO on your computer with XAMPP.  It is pretty simple really, here is a link to get you started:  http://php.net/manual/en/mysqli.quickstart.dual-interface.php.  

If you want to continue using the procedural way, the commands are almost the exact same, with a few differences.  
0 Kumi Festus · November 3, 2014
Thanks a bunch.
They do really look similar.
I will use that from now on. Thanks
  • 1



Server-side, HTML embedded scripting language used to create dynamic Web pages.