Jump to content

Archived

This topic is now archived and is closed to further replies.

essjay_d12

value of field not being extracted using php from sql query

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

Share this post


Link to post
Share on other sites
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.

Share this post


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

Share this post


Link to post
Share on other sites

×

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.