Closed Thread Icon

Topic awaiting preservation: Beginner search through database (mysql) using php question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12642" title="Pages that link to Topic awaiting preservation: Beginner search through database (mysql) using php question (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: Beginner search through database (mysql) using php question <span class="small">(Page 1 of 1)</span>\

 
shattered
Obsessive-Compulsive (I) Inmate

From:
Insane since: Feb 2003

posted posted 03-09-2003 08:18

Hello all,
This is part of my code, if this looks familiar, it's taken from devshed.com:

code:
$getresults = mysql_query("SELECT * FROM Music_Library LIKE '%$search%'");

$resultsnumber = mysql_numrows($getresults);

IF ($resultsnumber == 0){
PRINT "Your search returned no results. Try other keyword(s).";
}

ELSEIF ($resultsnumber > 0){
PRINT "Your search returned $resultsnumber results<BR><BR>";
for($count = 0; $count<$resultsnumber; $count++){
$body = mysql_result($getresults,$count);
//tighten up the results
$body2print = substr($body, 0, 100);
$cnote = $count+1;
PRINT "$cnote. <a href=main.php>
<i>$body2print...</i></a><BR>";
}
}

?>




1. I'm getting this error
"Warning: Supplied argument is not a valid MySQL result resource in /home/omis107/main.php on line 45"
I believe line 45 is "$resultsnumber = mysql_numrows($getresults);"

Can anyone tell me what the problem might be?

2. And in this line
$getresults = mysql_query("SELECT * FROM Music_Library LIKE '%$search%'");
What code should I write for $search if I want to perform a search of a string taken from the search engine text box?

3. And if you would look at http://www.radio.deltapath.com/search_artist.html , notice the alphabets at the top of the page. I'm hoping that if let's say I click on "A", it would bring up a list of data from my music_library table that starts with "A". How should I do that? Is there any reference that you can link me to?

Thank you very much!

[This message has been edited by shattered (edited 03-09-2003).]

[This message has been edited by shattered (edited 03-09-2003).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 03-09-2003 14:15

shattered: OK your questions:

1. Yes the function isn't mysql_numrows its:

mysql_num_rows()

2. It depends on what you call the input that is your search engine box or you can grab the variable the box is sending through and gab that and use it for $search (hmmmmm I suspect that is unclear - we'll see).

3. See:

:FAQ:

___________________
Emps

FAQs: Emperor

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-09-2003 18:51

as always, I'm short on minutes...

so for three:
-the quick answer is you'd use a where statment (which is missing in front of the like in your query, line 1, which might be the real reason for your problem no 1),
with 'mycolumn like "A%"' which means (just seeing, you're also missing the column name in front of the like ;-). You did create the table first, did you?)) anything starting with a 'A' (small or big, doesn't care either way)

-the long answer: http://www.mysql.com/doc - Chapter titled like 'string comparison functions'.

so long,

Tyberius Prime

shattered
Obsessive-Compulsive (I) Inmate

From:
Insane since: Feb 2003

posted posted 03-10-2003 00:57

Hey guys,
I still have the same old
"Warning: Supplied argument is not a valid MySQL result resource in /home/omis107/main.php on line 45"

even though I changed to mysql_num_rows().. can anyone help?
Thanks!

« BackwardsOnwards »

Show Forum Drop Down Menu