SHOW THE RESULT FROM QUERY DATABASE PHP

Jayden Bell

Total Post:110

Points:774
Posted by  Jayden Bell
PHP 
PHP
 1539  View(s)
Ratings:
Rate this:
Hi Mindstickians!

I have a code like this:

$genre = 'jazz';
$what_genre = mysql_real_escape_string($genre);
$query = mysql_query("SELECT song.id, song.title, genre.genre FROM song INNER JOIN genre ON song.id_genre=genre.id_genre WHERE genre.genre = '" .$what_genre. "' ORDER BY id");

if(mysql_num_rows($query) > 0)
{
    while($result = mysql_fetch_array($query))
    {
        echo $result['id'];
        echo $result['title'];
        echo $result['genre'];
    }
}
I want to show the result, but it failed. The system give me an error report:

A PHP Error was encountered

Severity: Warning

Message: mysql_num_rows() expects parameter 1 to be resource, boolean given

What should I do?
Thanks in advance! 

  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Show the result from query database php

    Hi Jayden!


    Change your query from id to song.id like this

    "SELECT song.id, song.title, genre.genre FROM song INNER JOIN genre ON song.id_genre=genre.id_genre WHERE genre.genre = '" .$topiknya. "' ORDER BY song.id";

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!