Jump to content

[SOLVED] Database search


_absurd

Recommended Posts

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++;
}
}

Link to comment
https://forums.phpfreaks.com/topic/120906-solved-database-search/
Share on other sites

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 __

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.