Page 1 of 1

php mysql result

Posted: Sun Oct 09, 2005 2:52 pm
by birdie
hi, ive made this script but it doesnt work..

Code: Select all

<?
mysql_connect("localhost","root","password");
mysql_select_db("dave");
$voteresult = mysql_query("SELECT number FROM votegood WHERE dave=1");
$number = mysql_result($voteresult);
mysql_query("UPDATE votegood SET number=$number+1 } WHERE dave=1");
mysql_close();
?>


could someone please tell me whats wrong with that, error messages say its this part, "$number = mysql_result($voteresult);". thanks

Posted: Sun Oct 09, 2005 3:21 pm
by shiznatix
http://ee.php.net/manual/en/function.mysql-result.php

what do you need mysql_result for? this i often not nessicary.

Posted: Sun Oct 09, 2005 3:26 pm
by birdie
well i'm just trying to get it to work. would this help?.. i have a table in mysql like this..

------
|n|id|
------
|1|2|
------

i want to echo the "1" in the "n" column. how do i do this?

Posted: Sun Oct 09, 2005 8:18 pm
by xtjdx
The way I usually do MySQL results is:

Code: Select all

<?
$query = 'Select field From table Where value=\'value\'';
$result = mysql_query($query);
$result = mysql_fetch_array($result);
echo $result['field'];
?>
Never used mysql_result().