Jump to content

value of field not being extracted using php from sql query


essjay_d12

Recommended Posts

I have run the query in MySQL and it returns 'THRILLER'

When i echo $genre in php is just blank

[code] $sql = "SELECT FAVOURITES FROM users WHERE USERNAME = '$_SESSION[username]'";
$check = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($check))
{
$genre = ($row['FAVOURITES']);
echo $genre;
}[/code]

thanks

d
try running a little troubleshooting within your code itself:

[code]
$sql = "SELECT FAVOURITES FROM users WHERE USERNAME = '$_SESSION[username]'";
$check = mysql_query($query) or die(mysql_error());
if (mysql_num_rows($check) > 0)
  while ($row = mysql_fetch_array($check))
  {
    $genre = $row['FAVOURITES'];
    echo $genre;
  }
else
  echo "No records returned for query:<br /><pre>$sql</pre>\n";
[/code]

this way, if you don't return any records, you can also make sure that your query is exactly what you think it is.
but i know that query returns a value 'Thriller' .. so the query is fine.

the username is unique so i was wondering if

[code]
while ($row = mysql_fetch_array($check))
{
$genre = ($row['FAVOURITES']);
[/code]

was the correct way to extract a query that i know only has one row one value.

Thanks

d

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.