_absurd Posted August 22, 2008 Share Posted August 22, 2008 Been working on this for the better part of the morning. Still can't figure it out. Feel free to criticize anything. Namely though, line 19 and 30 are the ones that are giving me a headache. $_GET['q'] = $q; $_GET['what'] = $what; if (!$q) { stop ('<h3>Error: missing parameter.</h3>'); } if (!$what) { stop ('<h3>Error: missing parameter.</h3>'); } echo '<h1>Search Results</h1>'; echo '<b>Note:</b> Do not use wildcards (*, etc). Maximum number of results is always 25.<hr />'; echo ''.$q.''; if ($what == 'artist') { $num = 0; while ($myrow = mysql_fetch_array (mysql_query ('SELECT * from `artists` WHERE `artistname` LIKE '.$q.' LIMIT 0,25'))) { echo '<br /><br />'; echo ''.$num.': <a href="artist.php?id='.$myrow['artistid'].'">'.$myrow['artistname'].'</a><br /><br />'; $num++; } } if ($what == 'album') { $q = '%'.str_replace(' ','%',$q).'%'; $num = 0; while ($myrow = mysql_fetch_array (mysql_query ('SELECT * from `albums` WHERE `albumname` LIKE '.$q.' LIMIT 0,25'))) { echo '<br /><br />'; echo ''.$num.': <a href="album.php?id='.$myrow['albumid'].'">'.$myrow['albumname'].'</a><br /><br />'; $num++; } } Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/ Share on other sites More sharing options...
marcus Posted August 22, 2008 Share Posted August 22, 2008 Line 19 and 30 are } Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623238 Share on other sites More sharing options...
_absurd Posted August 22, 2008 Author Share Posted August 22, 2008 Oh, heh, I only copied a selection of the document, so the lines are off. The lines that need help are actually: 14 and 25 (the two 'while' loops). Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623239 Share on other sites More sharing options...
marcus Posted August 22, 2008 Share Posted August 22, 2008 Do the queries before hand and make sure they're correct. Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623242 Share on other sites More sharing options...
Lamez Posted August 22, 2008 Share Posted August 22, 2008 what is happening that you do not like? in other words what is wrong? Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623243 Share on other sites More sharing options...
_absurd Posted August 22, 2008 Author Share Posted August 22, 2008 Tried that: $_GET['q'] = $q; $_GET['what'] = $what; if (!$q) { stop ('<h3>Error: missing parameter.</h3>'); } if (!$what) { stop ('<h3>Error: missing parameter.</h3>'); } echo '<h1>Search Results</h1>'; echo '<b>Note:</b> Do not use wildcards (*, etc). Maximum number of results is always 25.<hr />'; if ($what == 'artist') { $q = '%'.str_replace(' ','%',$q).'%'; $sql = 'SELECT * from `artists` WHERE `artistname` LIKE '.$q.' LIMIT 0,25'; $result = mysql_query($sql); $num = 0; while ($myrow = mysql_fetch_array($result)) { echo '<br /><br />'; echo ''.$num.': <a href="artist.php?id='.$myrow['artistid'].'">'.$myrow['artistname'].'</a><br /><br />'; $num++; } } if ($what == 'album') { $q = '%'.str_replace(' ','%',$q).'%'; $sql = 'SELECT * from `albums` WHERE `albumname` LIKE '.$q.' LIMIT 0,25'; $result = mysql_query($sql); $num = 0; while ($myrow = mysql_fetch_array($result)) { echo '<br /><br />'; echo ''.$num.': <a href="album.php?id='.$myrow['albumid'].'">'.$myrow['albumname'].'</a><br /><br />'; $num++; } } Still no luck The error is: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/hell/public_html/search.php on line __ Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623248 Share on other sites More sharing options...
marcus Posted August 22, 2008 Share Posted August 22, 2008 mysql_query('query') or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623258 Share on other sites More sharing options...
_absurd Posted August 22, 2008 Author Share Posted August 22, 2008 $sql = "SELECT * from `artists` WHERE `artistname` LIKE '$q' LIMIT 0,25"; That seemed to work. Thanks for the help guys. Quote Link to comment https://forums.phpfreaks.com/topic/120906-solved-database-search/#findComment-623263 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.