PDA

View Full Version : PHP/MYQSL brings back wrong value (resource ID #3)



izzysanime
09-26-2008, 04:10 PM
HI,

I'm trying to get the highest number from a table, but it brings back "resource ID #3". I have no idea where that comes from, because there is no resource id #3 or even 3 colums. Here is my code


mysql_select_db("mvy_fomcreds") or die(mysql_error());
$data = mysql_query("SELECT annon FROM `annon` ORDER BY `annon` DESC LIMIT 1")
or die(mysql_error());
$new = $annon + $data;
mysql_select_db("mvy_fomcreds") or die(mysql_error());
mysql_query("INSERT INTO `annon` (`annon`) VALUES ('$new');
");
Print "Thank you for your submission.";
echo "$data";
?>

Thanks,
Josh

techietim
09-26-2008, 04:17 PM
You cannot echo your raw query. You must first grab the information it is returning with a function such as mysql_fetch_array() (http://php.net/mysql_fetch_array)

izzysanime
09-26-2008, 05:19 PM
OK, i still get the same response. Is this what you meant?


mysql_select_db("mvy_fomcreds") or die(mysql_error());
$data = mysql_query("SELECT annon FROM `annon` ORDER BY `annon` DESC LIMIT 1")
or die(mysql_error());
$new = $annon + $info['annon'];
mysql_select_db("mvy_fomcreds") or die(mysql_error());
mysql_query("INSERT INTO `annon` (`annon`) VALUES ('$new');
");
Print "Thank you for your submission.";

while($info = mysql_fetch_array( $data ))
{
echo "</head>
<body>";

Print $info['annon'] ;
}

?>

izzysanime
09-26-2008, 06:03 PM
Hmm, got it working. not really sure where it got #3, I just renamed a few things and it works.


mysql_select_db("mvy_fomcreds") or die(mysql_error());
$data = mysql_query("SELECT * FROM `annon` ORDER BY `annonCount` DESC LIMIT 1")
or die(mysql_error());


Print "Thank you for your submission.";

while($info = mysql_fetch_array( $data ))
{

echo "</head>
<body> <br />";
$new = 1 + $info['annonCount'];

Print $new ;
}
mysql_select_db("mvy_fomcreds") or die(mysql_error());
mysql_query("INSERT INTO `annon` (`annonCount`) VALUES ('$new')")
or die(mysql_error());
?>