mysql - Show the data with mysql_query php -


i have 2 tables on database, table 'songs', , 'genre'.

  • table 'songs' has 3 columns: id_song (pk), song_title, lyric, id_genre
  • table 'genre' has 2 columns: id_genre (pk), genre

in table 'genre', have:

|| id_genre | genre ||

||.......1.......|..pop...||

||.......2.......|..rock..||

||.......3.......|..jazz...||

||.......4.......|.classic.||

relation between 2 tables:

song.id_genre fk genre.id_genre

i have variable this:

$search_genre = 'pop'; 

and want search song $search_genre.

$query = mysql_query("select song.id_song, song.song_title, genre.genre song genre='$search_genre' inner join genre on song.id_genre=genre.id_genre order id_song"); 

but, doesn't work. should do? help.

question 2: how show result in php?

first!

please, don't use mysql_* functions in new code. no longer maintained and officially deprecated. see red box? learn prepared statements instead, , use pdo or mysqli - this article decide which. if choose pdo, here tutorial.

second!

if you've started mysql_* @ least escape parameters! otherwise you're leaving gaping sql injection security vulnerability waiting next l33t wannabe hacker hack site!

$search_genere = mysql_real_escape_string($search_genere); $query = mysql_query("select song.id_song, song.song_title, genre.genre song inner join genre on song.id_genre=genre.id_genre genre.genre='".$search_genre."' order id_song"); 

but please please read link in box above.

the reason you've had error because of syntax error.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -