Re: Turning result into array from columns

From: Date: Fri, 22 Sep 2006 21:43:19 +0000
Subject: Re: Turning result into array from columns
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-42387@lists.php.net to get a copy of this message
$realones = $row['id'];
This line needs to be
$realones[] = $row['id'];
...then you will be filling an array instead of just overwriting the same variable repeatedly! -Stephen ----- Original Message ----- From: "Dave W" <dabbaking@gmail.com> To: "PHP DB" <php-db@lists.php.net> Sent: Friday, September 22, 2006 10:35 PM Subject: [PHP-DB] Turning result into array from columns
So I'm trying to pull id's and put them into an array. I know I need to iterate through them, but it doesn't seem to turn into an array. Here's the function that I'm trying: function checkID($id) { $q = sprintf("SELECT id FROM content"); $result = $this->query($q); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $realones = $row['id']; } if(in_array($id,array($realones))) { return true; } else { return false; } } It's only grabbing the first row id and putting it into the array. It won't put any of the other ones in. If I just echo $row['id'], it will show both of them, just not put both of them into an array. -- Dave W


« previous php.db (#42387) next »