FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Database not returning correct value when queried.





ThomasDesigns
PHPMyAdmin says that the [6] value in this array (the value for rating) should be 3.5 .
However, as you can see, the query returns a 0.
What is going on here.

Does anyone know what might cause this?

Here is the PHP code used to access and display the data:

(I have removed parts of code because it is unimportant. So don't worry about undefined variables you see.)
Code:

<?php
$con = mysql_connect("localhost","foo","bar");
   if (!$con)
     {
     die('Could not connect: ' . mysql_error());
     }
   mysql_select_db("foobar", $con);
   $result = mysql_query("SELECT * FROM news WHERE id = '$id'");
   $Crating = mysql_fetch_row($result);
   if($Crating[6] = 0){
      $newrating = $Urating;
   }
   else{
      $newrating = (($Urating + $Crating[6])/2);
   }
   print_r($Crating);
?>

and here is the result I get:
Code:

Array ( [0] => 74 [1] => 2007-10-03 19:37:22 [2] => Woa. [3] => [article text is here]
[4] => Author [5] => 3 [6] => 0 )
//[6] is supposed to be the rating. This value is supposed to be 3.5 right now...


What's going on here?
kv
There is an error in your if statement

Quote:

if($Crating[6] = 0){
$newrating = $Urating;
}
else{
$newrating = (($Urating + $Crating[6])/2);
}


Change it to this

Code:

 if($Crating[6] == 0){ // <-- use the == operator for if condition
      $newrating = $Urating;
   }
   else{
      $newrating = (($Urating + $Crating[6])/2);
   }
manav
dude if($something==somevalue)

remember this always....

its the same in c and c++ also....

re read your php book again Very Happy Smile
Related topics
Creating a new Operating System
Football Manager 2005 (PC) Review feat screeshots
Defalut Value in MySql
PHP script trouble
Domain?
PHP/MySQL challenge, take it if you dare
Good vs. Evil--A Philosophical Question...
[Edit] mySQL Count
Email Trouble - Automatic spam filters?
Help me find the error in my code... mysql_fetch_array():
Erroring or Erring?
Joomla
File/Folder(s) Owner/Group
if statement not working
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.