Forum Moderators: coopster

Message Too Old, No Replies

Can't Query Table Values!

         

flamesrock

10:03 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Ok..no matter what I do, the value returned is ALWAYS zero.

First the code:

$region = mysql_query('SELECT * FROM `regions` WHERE 1');
if (!$region) {
die('Invalid query: ' . mysql_error());
}
echo "<br>";
echo "
<div style=\"margin-bottom: 10px; width: 100%; height: 149\">
- <b>Total Population</b>: ".number_format($region['total_pop'])."
<br>
&nbsp;&nbsp;
<b>R</b>: ".number_format($region['total_R'])."
<br>
&nbsp;&nbsp;
<b>C</b>: ".number_format($region['total_C'])."
<br>
&nbsp;&nbsp;
<b>I</b>: ".number_format($region['total_I'])."
<p>

And the table values (only one exists)
id --1 name --city total_pop--2468 total_R--1234 total_C--1234

It should not return zero, but it does! I assume the problem has something to do with:
$region = mysql_query('SELECT * FROM `regions` WHERE 1');

$region = mysql_query('SELECT 1 FROM regions');
doesn't work either

Any ideas?

-thanks in advance

uncle_bob

10:42 am on Nov 11, 2004 (gmt 0)

10+ Year Member



try using select * from regions where id=1

baertyp

11:01 am on Nov 11, 2004 (gmt 0)

10+ Year Member



Flamesrock,

just saw that you forgot to actually fetch your row from the result identyfier. See [de3.php.net ]
for more info.

Try something like


...
mysql_connect("hostname","user","password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
//
$sql = "SELECT * FROM regions";
$query = mysql_query($sql);
//
if ($query) {
while ($row = mysql_fetch_row($query)) {
... your code here
}
} else {
die("NULL query: $sql");
}
...

Hope this helps.

Regards
Markus