Jump to content

Creating the query


unknown101

Recommended Posts

Hi Guys I have the following in my code: (im pretty new this as you will probably tell).

 

	
$genre_query = mysql_query("SELECT Genre FROM artist_tbl WHERE Artist={$user_search}")
or die(mysql_error());; 

$user_result = mysql_fetch_array( $user_search );

 

Basically when an artist is entered, I want to check in my "artist_tbl" if that artist is in there and if so print out the genre. 

 

Example... Enter Metallica, this is found in my artist_tbl, genre is Metal, which is then returned to the user.  I know im missing the last part of the above code, so could anyone give me a hand please?

 

Thanks in advance

 

 

Link to comment
https://forums.phpfreaks.com/topic/100103-creating-the-query/
Share on other sites

Give this a go, its almost 3am here so hopefully its right <chuckle> I'll take a look back first thing tomorrow if you cant get it! Best of luck

 

$genre_query = "SELECT Genre FROM artist_tbl WHERE Artist='$user_search'";

$result = mysql_query($genre_query) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/100103-creating-the-query/#findComment-511847
Share on other sites

Thanks for the reply but I managed to get it working with:

 


	$result=mysql_query("select Genre from artist_tbl where Artist='$user_search'"); 

	while ($row = mysql_fetch_array($result))
	{ 
	echo $row['Genre'];
	}

 

It now prints out the Artist entered and the genre from the db, which brings me to the next stage:| 

 

Now I want to be able to say....

 

if genre = metal, rock, heavyRock,

 

Select 5 random artists with the genre metal, heavyrock from artist_tbl .. but im a little stuck with coding this.. can anyone give a helping hand please?

 

Many thanks

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/100103-creating-the-query/#findComment-511859
Share on other sites

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.