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);
?>
?>
data extraction??
Moderator: General Moderators
-
suziecorbett
- Forum Newbie
- Posts: 3
- Joined: Wed Nov 12, 2003 5:59 am
- Location: dublin-ireland
-
suziecorbett
- Forum Newbie
- Posts: 3
- Joined: Wed Nov 12, 2003 5:59 am
- Location: dublin-ireland
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.
$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.
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Try:
Mac
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';
}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);