Turning result into array from columns
Turning result into array from columns
am 22.09.2006 23:35:31 von Dave W
------=_Part_35323_29596572.1158960931268
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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
------=_Part_35323_29596572.1158960931268--
Re: Turning result into array from columns
am 22.09.2006 23:43:19 von Stephen Brooks
> $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"
To: "PHP DB"
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
>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Turning result into array from columns
am 23.09.2006 12:01:23 von Matthias Willerich
Hello,
> $q = sprintf("SELECT id FROM content");
This has nothing to do with your problem, but why don't you just do the
following?
$q = 'SELECT id FROM content';
But here's your problem. Change
> $realones = $row['id'];
into
$realones[] = $row['id'];
And you get your desired result.
Matthias
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Turning result into array from columns
am 23.09.2006 15:08:48 von Dave W
------=_Part_3894_24392316.1159016928879
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Yea, thanks. I forgot to hit reply to all. I usually use sprintf for mysql
injection stuff. I use that function from php.net for
mysql_real_escape_string.
On 9/23/06, Matthias Willerich wrote:
>
> Hello,
> > $q = sprintf("SELECT id FROM content");
> This has nothing to do with your problem, but why don't you just do the
> following?
> $q = 'SELECT id FROM content';
>
> But here's your problem. Change
> > $realones = $row['id'];
> into
> $realones[] = $row['id'];
> And you get your desired result.
>
> Matthias
>
>
>
--
Dave W
------=_Part_3894_24392316.1159016928879--