Jump to content


Photo

value of field not being extracted using php from sql query


  • Please log in to reply
2 replies to this topic

#1 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 27 March 2006 - 07:45 PM

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

When i echo $genre in php is just blank

$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;
}

thanks

d

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 27 March 2006 - 07:50 PM

try running a little troubleshooting within your code itself:

$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";

this way, if you don't return any records, you can also make sure that your query is exactly what you think it is.
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 essjay_d12

essjay_d12
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 27 March 2006 - 08:01 PM

but i know that query returns a value 'Thriller' .. so the query is fine.

the username is unique so i was wondering if

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

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

Thanks

d




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users