Forum Moderators: coopster

Message Too Old, No Replies

mysql query not pulling correct results

         

TheSpeshulK

2:46 pm on Oct 20, 2008 (gmt 0)

10+ Year Member



I am trying to pull an array from a database table but it is not pulling correctly. I have outputted the query to the screen and copy and pasted that into the phpMyAdmin SQL field and I get exactly what I am looking for. The problem I am having is that my following code is returning an empty array and the number of rows from my result is returning zero. The script also does not die after the mysql query so i see no error messages. Does anybody have any idea what i might be doing wrong? Thanks in advance

$query="SELECT region_name FROM regions_tbl WHERE region_is_popular=1 && region_is_state=0";
$result=mysql_query($query)or die("mysql error ".mysql_error());
$popularArray=array();
$count=0;
echo $num_rows;
while($row=mysql_fetch_array($result)){
$popularArray[$count]=$row[0];
$count++;
}
print_r($popularArray);

Anyango

3:49 pm on Oct 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try

$query="SELECT region_name FROM regions_tbl WHERE region_is_popular=1 && region_is_state=0";
$result=mysql_query($query)or die("mysql error ".mysql_error());
$popularArray=array();
$count=0;
echo $num_rows;
while($row=mysql_fetch_array($result)){
$popularArray[$count]=$row["region_name"];
$count++;
}
print_r($popularArray);