Page 1 of 1

data extraction??

Posted: Tue Nov 18, 2003 12:57 pm
by suziecorbett
hey guys, I'm having a problem that's really driving me mad and i'd really appreciate any help ye could give me! Basically I'm trying to print out a value from a database onto a web page, but everytime i try the following code, regardless of which table i try it on, it prints out
id resourse #3.
it will compare the data fine. like if its a number it will print out wether it's greater that ten etc.

Any ideas??I'm using php as my scripting language



//query the level reached from the database
$query = " SELECT Exam1 FROM Users WHERE username='$username'";
$result = mysql_query( $query )
or die( "sss" );

echo($result);
?>
?>

Posted: Tue Nov 18, 2003 1:10 pm
by m3mn0n
[php_man]mysql_fetch_array[/php_man]()

Posted: Thu Nov 20, 2003 7:03 am
by suziecorbett
thanks a million sami, that worked great, the code is now printing out the value held in the database, my problem now is that i need to compare that value with another as follows,

$result = mysql_query(" SELECT Exam1 FROM Users WHERE username='$username'");
while($row=mysql_fetch_array($result))
{
printf("Score: %s", $row[0]);
}
if($row[0]>=4){
echo("Passed");}
else echo ("Failed");


mysql_free_result($result);


printing the score is working fine, but it's printing out failed regardless of what number is stored in the array.
any ideas ye have would be greatly appreciated.

Posted: Thu Nov 20, 2003 9:47 am
by twigletmac
Try:

Code: Select all

$result = mysql_query("SELECT Exam1 FROM Users WHERE username='$username'");

$row = mysql_fetch_assoc($result);
$score = $row['Exam1'];

echo 'Score: '.$score.'<br />';

if ($score >= 4) {
    echo 'Passed';
} else {
    echo 'Failed';
}
Mac

Posted: Thu Nov 20, 2003 10:13 am
by Weirdan

Code: Select all

$result = mysql_query(" SELECT Exam1 FROM Users WHERE username='$username'"); 
while($row=mysql_fetch_array($result)) 
{ 
   printf("Score: %s", $row[0]); 
   if($row[0]>=4) 
     echo("Passed"); 
   else echo ("Failed"); 
} 

mysql_free_result($result);
?