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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.