Hello, I get the following error message after using the following script: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in <? //connect to mysql //change user and password to your mySQL name and password { include("../includes/dbconnect.php"); } //select which database you want to edit mysql_select_db("my_db"); $search=$_POST["search"]; //get the mysql and store them in $result //change whatevertable to the mysql table you're using //change whatevercolumn to the column in the table you want to search $result = mysql_query("SELECT * FROM downloads WHERE message LIKE '%$search%'"); //grab all the content while($row = mysql_fetch_array($result)) { //the format is $variable = $r["nameofmysqlcolumn"] //modify these to match your mysql table columns $title=$row["title"]; $description=$row["description"]; $filesize=$row["filesize"]; $url=$row["url"]; $cid=$row["cid"]; //display the row echo "$title <br> $description <br> $filesize <br> $url <br> $cid <br>"; } ?> Code (markup): Any help would be appreciated. Regards
Something wrong with MySQL Connect OR Selecting the DB? OR: Try using this result: $result = mysql_query("SELECT * FROM downloads WHERE message LIKE '%$search%'") or die (mysql_error()); Code (markup): And see what error does it show.
It turns out it's my lack of knowledge of PHP/MySQL. $result = mysql_query("SELECT * FROM downloads WHERE [COLOR="Red"]message[/COLOR] LIKE '%$search%'"); Code (markup): Message isn't a table in my db. So i've used title instead Now when I submit a search it reveals nothing, however i know there is data in the tables matching the search, but it reveals nothing. Thanks again
If you have PHPMyAdmin then just run the query in the search tab. After you run it you will see the results and it gives you the query it used. Just use the query in your code and it should work.
Your code $result = mysql_query("SELECT * FROM downloads WHERE message LIKE '%$search%'"); PHP: is saying.. Select everything in that "row" from the "table" downloads where the "field" message is like $search aka, whatever they are searching for. So you should have a field called message in the downloads table. Now it might not be returning anything because it couldnt find anything also. I would use a search that you know will return something.
Ok so I used search in phpMyAdmin as you said and was given 9 results as i thought. I then copy and pasted the query into my existing code but still there was no result. I viewed the source code and all thats being displayed is the 5 <br>'s at the bottom of the script. Any suggestions?
I don't understand why it's not displaying any results. I'm have a small script that displays the last 5 entries to the db 'downloads' in a simple html table on my home page. In this table are the words i'm using in my search. What does this indicate to you?
Try to count the result, to see if you get some info... $countQuery = mysql_num_rows($result); echo $countQuery; if not.. try go echo your search post: echo $search; you could also try to echo your whole $row array: print_r($row); Good luck