Forum Moderators: coopster
I am a complete newbie to PHP and am currently trying to get to grips with the language. I have a database of music tracks and am trying to create a search function for them. So far I have the following code:
$sql = "SELECT * FROM `track_info`";
if($trackId!="" ¦¦ $trackName!="" ¦¦ $albumName!="" ¦¦ $artistName!="" ¦¦ $genre!="")
{
$sql.=" WHERE";
if($trackId!="")
{
$addAnd = "true";
$sql.= " `trackid`='$trackId'";
}
if($trackName!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.= " `trackname`='$trackName'";
$addAnd = "true";
}
if($artistName!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.= " `artistname`='$artistName'";
$addAnd = "true";
}
if($albumName!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.= " `albumname`='$albumName'";
$addAnd = "true";
}
if($genre!="")
{
if($addAnd == "true")
{
$sql.= " AND";
}
$sql.=" `genre`=$'genre'";
$addAnd = "true";
}
}
$result = mysql_query($sql);
while($row = mysql_fetch_array($result,MYSQL_ASSOC));
{
print_r($row);
}
The problem is that nothing from the array is getting printed out. I have taken the sql statement that is built and executed it in ems mysql and the correct rows were selected so I know the sql is fine.
Also if I take out the while loop the first row from the array is printed as expected. It just seems to be when I include the while loop that nothing at all is printed out. Would anyone have any ideas to what the problem might be?
Many Thanks
[edited by: jatar_k at 8:45 pm (utc) on Feb. 15, 2007]
[edit reason] fixed formatting [/edit]
By the way, Welcome to WebmasterWorld, pomalley! :)