FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Re: mysqli fetch_assoc() straight to array
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Re: mysqli fetch_assoc() straight to array [message #186008] Fri, 30 May 2014 20:23 Go to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
<noreply(at)example(dot)com> wrote:

>
> Is there a way to make it simpler to just load an array based upon the
> results of $row?
> Rather than having to assign each individual column one at a time?

/This/ is the sort of posting that I was talking about earlier.

Richard, this isn't a mysql issue. Mysql does not define how PHP manages
array assignments, PHP does.

> $array=$row
> Versus
> $array[col1]=$row[col1]
> $array[col2]=$row[col2]
>
>
> while ($y<=69){
> while ($n<=40){
>
> if ($n<10){$n="0".$n;}
> $x=$y.$n;
> $sql = "SELECT * FROM top20 where songs='$x'";
> $result = $mysqli->query($sql);
> $row = $result->fetch_assoc();
>
> echo $n.") ".$row['songs']."<br>";
>
> $n++;
>
> }
> $n=1;
> $y++;
> }

Followup set to comp.lang.php

FWIW, PHP permits assignment of arrays, so
$row = $result->fetch_assoc();
$array = $row;
echo $n.") ".$array['songs']."<br>";
is legal PHP code.

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: mysqli fetch_assoc() straight to array [message #186009 is a reply to message #186008] Fri, 30 May 2014 20:25 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Friday 30 May 2014 16:23, in comp.lang.php, "Lew Pitcher"
<lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:

>
> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
> <noreply(at)example(dot)com> wrote:
>
>>
>> Is there a way to make it simpler to just load an array based upon the
>> results of $row?
>> Rather than having to assign each individual column one at a time?
>
> /This/ is the sort of posting that I was talking about earlier.
>
> Richard, this isn't a mysql issue. Mysql does not define how PHP manages
> array assignments, PHP does.
>
>> $array=$row
>> Versus
>> $array[col1]=$row[col1]
>> $array[col2]=$row[col2]
>>
>>
>> while ($y<=69){
>> while ($n<=40){
>>
>> if ($n<10){$n="0".$n;}
>> $x=$y.$n;
>> $sql = "SELECT * FROM top20 where songs='$x'";
>> $result = $mysqli->query($sql);
>> $row = $result->fetch_assoc();
>>
>> echo $n.") ".$row['songs']."<br>";
>>
>> $n++;
>>
>> }
>> $n=1;
>> $y++;
>> }
>
> Followup set to comp.lang.php
>
> FWIW, PHP permits assignment of arrays, so
> $row = $result->fetch_assoc();
> $array = $row;
> echo $n.") ".$array['songs']."<br>";
> is legal PHP code.

As is, FWIW
$row = $result->fetch_assoc();
$array[$n] = $row;
echo $n.") ".$array[$n]['songs']."<br>";

Or even
$row[$n] = $result->fetch_assoc();
echo $n.") ".$row[$n]['songs']."<br>";



--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: mysqli fetch_assoc() straight to array [message #186010 is a reply to message #186008] Fri, 30 May 2014 20:54 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Fri, 30 May 2014 16:23:32 -0400, Lew Pitcher wrote:

> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
> <noreply(at)example(dot)com> wrote:
>
>>
>> Is there a way to make it simpler to just load an array based upon the
>> results of $row?
>> Rather than having to assign each individual column one at a time?
>
> /This/ is the sort of posting that I was talking about earlier.
>
> Richard, this isn't a mysql issue. Mysql does not define how PHP manages
> array assignments, PHP does.
>
>> $array=$row
>> Versus
>> $array[col1]=$row[col1]
>> $array[col2]=$row[col2]
>>
>>
>> while ($y<=69){
>> while ($n<=40){
>>
>> if ($n<10){$n="0".$n;}
>> $x=$y.$n;
>> $sql = "SELECT * FROM top20 where songs='$x'";
>> $result = $mysqli->query($sql);
>> $row = $result->fetch_assoc();
>>
>> echo $n.") ".$row['songs']."<br>";
>>
>> $n++;
>>
>> }
>> $n=1;
>> $y++;
>> }
>
> Followup set to comp.lang.php
>
> FWIW, PHP permits assignment of arrays, so
> $row = $result->fetch_assoc();
> $array = $row;
> echo $n.") ".$array['songs']."<br>";
> is legal PHP code.

Thank you sir.
At least you said "why".
The others just say it is not an issue in mysql but refused to say why.
But my question was dealing with a mysql function.
I just figured there had to be some way of being able to assign the columns
within the function, but apparently not.
Re: mysqli fetch_assoc() straight to array [message #186011 is a reply to message #186010] Fri, 30 May 2014 21:08 Go to previous messageGo to next message
Jrgen Exner is currently offline  Jrgen Exner
Messages: 14
Registered: March 2013
Karma: 0
Junior Member
On Fri, 30 May 2014 16:54:02 -0400, richard <noreply(at)example(dot)com> wrote
in comp.databases.mysql:

> On Fri, 30 May 2014 16:23:32 -0400, Lew Pitcher wrote:
>
>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>> <noreply(at)example(dot)com> wrote:
>>
>>>
>>> Is there a way to make it simpler to just load an array based upon the
>>> results of $row?
>>> Rather than having to assign each individual column one at a time?
>>
>> /This/ is the sort of posting that I was talking about earlier.
>>
>> Richard, this isn't a mysql issue. Mysql does not define how PHP manages
>> array assignments, PHP does.
>>
>>> $array=$row
>>> Versus
>>> $array[col1]=$row[col1]
>>> $array[col2]=$row[col2]
>>>
>>>
>>> while ($y<=69){
>>> while ($n<=40){
>>>
>>> if ($n<10){$n="0".$n;}
>>> $x=$y.$n;
>>> $sql = "SELECT * FROM top20 where songs='$x'";
>>> $result = $mysqli->query($sql);
>>> $row = $result->fetch_assoc();
>>>
>>> echo $n.") ".$row['songs']."<br>";
>>>
>>> $n++;
>>>
>>> }
>>> $n=1;
>>> $y++;
>>> }
>>
>> Followup set to comp.lang.php
>>
>> FWIW, PHP permits assignment of arrays, so
>> $row = $result->fetch_assoc();
>> $array = $row;
>> echo $n.") ".$array['songs']."<br>";
>> is legal PHP code.
>
> Thank you sir.
> At least you said "why".
> The others just say it is not an issue in mysql but refused to say why.

Oh please, don't tell us you didn't know that in those ~15 lines of code
there is exactly one and only one mysql statement:
SELECT * FROM top20 where songs='$x'
I would find that extraordinarily hard to believe.

> But my question was dealing with a mysql function.

No, it had nothing to do with any mysql function (or was it related to
the one and only SQL-statement that I quoted above) but everything with
the programming language you are using for the application layer.

> I just figured there had to be some way of being able to assign the columns
> within the function, but apparently not.

As mentioned before that depends solely on your appliation layer
programming language. If you choose e.g. Perl or PowerShell or some
dozen other languages, then yes, those languages do support assigment of
arrays and hashes.
But because you didn't even say which application layer language you are
using, there was no way of telling if it is possible in the language of
your choice.

jue
Re: mysqli fetch_assoc() straight to array [message #186012 is a reply to message #186010] Fri, 30 May 2014 21:11 Go to previous messageGo to next message
Christoph Michael Bec is currently offline  Christoph Michael Bec
Messages: 207
Registered: June 2013
Karma: 0
Senior Member
richard wrote:

> I just figured there had to be some way of being able to assign the columns
> within the function, but apparently not.

Maybe you're looking for mysqli_stmt_bind_result()[1]?

[1] <http://www.php.net/manual/en/mysqli-stmt.bind-result.php>

[xpost and fup2 comp.lang.php]

--
Christoph M. Becker
Re: mysqli fetch_assoc() straight to array [message #186013 is a reply to message #186009] Fri, 30 May 2014 21:36 Go to previous messageGo to next message
Mr Oldies is currently offline  Mr Oldies
Messages: 241
Registered: October 2013
Karma: 0
Senior Member
On Fri, 30 May 2014 16:25:10 -0400, Lew Pitcher wrote:

> On Friday 30 May 2014 16:23, in comp.lang.php, "Lew Pitcher"
> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>
>>
>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>> <noreply(at)example(dot)com> wrote:
>>
>>>
>>> Is there a way to make it simpler to just load an array based upon the
>>> results of $row?
>>> Rather than having to assign each individual column one at a time?
>>
>> /This/ is the sort of posting that I was talking about earlier.
>>
>> Richard, this isn't a mysql issue. Mysql does not define how PHP manages
>> array assignments, PHP does.
>>
>>> $array=$row
>>> Versus
>>> $array[col1]=$row[col1]
>>> $array[col2]=$row[col2]
>>>
>>>
>>> while ($y<=69){
>>> while ($n<=40){
>>>
>>> if ($n<10){$n="0".$n;}
>>> $x=$y.$n;
>>> $sql = "SELECT * FROM top20 where songs='$x'";
>>> $result = $mysqli->query($sql);
>>> $row = $result->fetch_assoc();
>>>
>>> echo $n.") ".$row['songs']."<br>";
>>>
>>> $n++;
>>>
>>> }
>>> $n=1;
>>> $y++;
>>> }
>>
>> Followup set to comp.lang.php
>>
>> FWIW, PHP permits assignment of arrays, so
>> $row = $result->fetch_assoc();
>> $array = $row;
>> echo $n.") ".$array['songs']."<br>";
>> is legal PHP code.
>
> As is, FWIW
> $row = $result->fetch_assoc();
> $array[$n] = $row;
> echo $n.") ".$array[$n]['songs']."<br>";
>
> Or even
> $row[$n] = $result->fetch_assoc();
> echo $n.") ".$row[$n]['songs']."<br>";

I wasn't sure if that would work or not.
But I only have a few columns in the table anway so I just did the
assignments one item at a time.
Re: mysqli fetch_assoc() straight to array [message #186014 is a reply to message #186010] Fri, 30 May 2014 23:27 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 30 May 2014 16:54:02 -0400, richard wrote:

> On Fri, 30 May 2014 16:23:32 -0400, Lew Pitcher wrote:

>> Followup set to comp.lang.php
>>
>> FWIW, PHP permits assignment of arrays, so
>> $row = $result->fetch_assoc(); $array = $row;
>> echo $n.") ".$array['songs']."<br>";
>> is legal PHP code.
>
> Thank you sir.
> At least you said "why".
> The others just say it is not an issue in mysql but refused to say why.

Richard, this is blatant fucking bullshit.

We have spent several posts recently trying to educate you as to the
difference between "mysql" the rdbms and "mysql[i]" the php application
layer. Previous posts in this thread have referred you back to those
discussions. Don't come out with such fucking bullshit as "no-one else
said why."

> But my question was dealing with a mysql function.

Your question was dealing with php mysql[i] functions. If you didn't
realise that you're even dumber than I thought.

> I just figured there had to be some way of being able to assign the
> columns within the function, but apparently not.

If and when you explain what you mean by "assign the columns within the
function" and you ask in the right place, you may get an answer, but at
the moment it still sounds to me as if you're asking how to do what
you're already doing with the php statements you're using.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: mysqli fetch_assoc() straight to array [message #186015 is a reply to message #186010] Sat, 31 May 2014 00:52 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2014 4:54 PM, richard wrote:
> On Fri, 30 May 2014 16:23:32 -0400, Lew Pitcher wrote:
>
>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>> <noreply(at)example(dot)com> wrote:
>>
>>>
>>> Is there a way to make it simpler to just load an array based upon the
>>> results of $row?
>>> Rather than having to assign each individual column one at a time?
>>
>> /This/ is the sort of posting that I was talking about earlier.
>>
>> Richard, this isn't a mysql issue. Mysql does not define how PHP manages
>> array assignments, PHP does.
>>
>>> $array=$row
>>> Versus
>>> $array[col1]=$row[col1]
>>> $array[col2]=$row[col2]
>>>
>>>
>>> while ($y<=69){
>>> while ($n<=40){
>>>
>>> if ($n<10){$n="0".$n;}
>>> $x=$y.$n;
>>> $sql = "SELECT * FROM top20 where songs='$x'";
>>> $result = $mysqli->query($sql);
>>> $row = $result->fetch_assoc();
>>>
>>> echo $n.") ".$row['songs']."<br>";
>>>
>>> $n++;
>>>
>>> }
>>> $n=1;
>>> $y++;
>>> }
>>
>> Followup set to comp.lang.php
>>
>> FWIW, PHP permits assignment of arrays, so
>> $row = $result->fetch_assoc();
>> $array = $row;
>> echo $n.") ".$array['songs']."<br>";
>> is legal PHP code.
>
> Thank you sir.
> At least you said "why".
> The others just say it is not an issue in mysql but refused to say why.
> But my question was dealing with a mysql function.
> I just figured there had to be some way of being able to assign the columns
> within the function, but apparently not.
>

Richard, if you had ANY intelligence at all, people wouldn't NEED to
explain WHY.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: mysqli fetch_assoc() straight to array [message #186016 is a reply to message #186012] Sat, 31 May 2014 00:53 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/30/2014 5:11 PM, Christoph Michael Becker wrote:
> richard wrote:
>
>> I just figured there had to be some way of being able to assign the columns
>> within the function, but apparently not.
>
> Maybe you're looking for mysqli_stmt_bind_result()[1]?
>
> [1] <http://www.php.net/manual/en/mysqli-stmt.bind-result.php>
>
> [xpost and fup2 comp.lang.php]
>

No, he's not...

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: mysqli fetch_assoc() straight to array [message #186022 is a reply to message #186013] Sat, 31 May 2014 14:32 Go to previous messageGo to next message
Lew Pitcher is currently offline  Lew Pitcher
Messages: 60
Registered: April 2013
Karma: 0
Member
On Friday 30 May 2014 17:36, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:

> On Fri, 30 May 2014 16:25:10 -0400, Lew Pitcher wrote:
>
>> On Friday 30 May 2014 16:23, in comp.lang.php, "Lew Pitcher"
>> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>>
>>>
>>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>>> <noreply(at)example(dot)com> wrote:
>>>
>>>>
>>>> Is there a way to make it simpler to just load an array based upon the
>>>> results of $row?
>>>> Rather than having to assign each individual column one at a time?
>>>
>>> /This/ is the sort of posting that I was talking about earlier.
>>>
>>> Richard, this isn't a mysql issue. Mysql does not define how PHP manages
>>> array assignments, PHP does.
>>>
>>>> $array=$row
>>>> Versus
>>>> $array[col1]=$row[col1]
>>>> $array[col2]=$row[col2]
>>>>
>>>>
>>>> while ($y<=69){
>>>> while ($n<=40){
>>>>
>>>> if ($n<10){$n="0".$n;}
>>>> $x=$y.$n;
>>>> $sql = "SELECT * FROM top20 where songs='$x'";
>>>> $result = $mysqli->query($sql);
>>>> $row = $result->fetch_assoc();
>>>>
>>>> echo $n.") ".$row['songs']."<br>";
>>>>
>>>> $n++;
>>>>
>>>> }
>>>> $n=1;
>>>> $y++;
>>>> }
>>>
>>> Followup set to comp.lang.php
>>>
>>> FWIW, PHP permits assignment of arrays, so
>>> $row = $result->fetch_assoc();
>>> $array = $row;
>>> echo $n.") ".$array['songs']."<br>";
>>> is legal PHP code.
>>
>> As is, FWIW
>> $row = $result->fetch_assoc();
>> $array[$n] = $row;
>> echo $n.") ".$array[$n]['songs']."<br>";
>>
>> Or even
>> $row[$n] = $result->fetch_assoc();
>> echo $n.") ".$row[$n]['songs']."<br>";
>
> I wasn't sure if that would work or not.

All the above suggestions work.
First off, the PHP language guarantees that they work, so they work in
principle. Secondly, I've tried them all, and they work in practice

> But I only have a few columns in the table anway so I just did the
> assignments one item at a time.

Your problem, your loss.

--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
Re: mysqli fetch_assoc() straight to array [message #186023 is a reply to message #186022] Sat, 31 May 2014 17:21 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Sat, 31 May 2014 10:32:44 -0400, Lew Pitcher wrote:

> On Friday 30 May 2014 17:36, in comp.lang.php, "richard"
> <noreply(at)example(dot)com> wrote:
>
>> On Fri, 30 May 2014 16:25:10 -0400, Lew Pitcher wrote:
>>
>>> On Friday 30 May 2014 16:23, in comp.lang.php, "Lew Pitcher"
>>> <lew(dot)pitcher(at)digitalfreehold(dot)ca> wrote:
>>>
>>>
>>>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>>>> <noreply(at)example(dot)com> wrote:
>>>>
>>>>
>>>> > Is there a way to make it simpler to just load an array based upon
>>>> > the results of $row?
>>>> > Rather than having to assign each individual column one at a time?
>>>>
>>>> /This/ is the sort of posting that I was talking about earlier.
>>>>
>>>> Richard, this isn't a mysql issue. Mysql does not define how PHP
>>>> manages array assignments, PHP does.
>>>>
>>>> > $array=$row Versus $array[col1]=$row[col1]
>>>> > $array[col2]=$row[col2]
>>>> >
>>>> >
>>>> > while ($y<=69){
>>>> > while ($n<=40){
>>>> >
>>>> > if ($n<10){$n="0".$n;}
>>>> > $x=$y.$n;
>>>> > $sql = "SELECT * FROM top20 where songs='$x'";
>>>> > $result = $mysqli->query($sql);
>>>> > $row = $result->fetch_assoc();
>>>> >
>>>> > echo $n.") ".$row['songs']."<br>";
>>>> >
>>>> > $n++;
>>>> >
>>>> > }
>>>> > $n=1;
>>>> > $y++;
>>>> > }
>>>>
>>>> Followup set to comp.lang.php
>>>>
>>>> FWIW, PHP permits assignment of arrays, so
>>>> $row = $result->fetch_assoc(); $array = $row;
>>>> echo $n.") ".$array['songs']."<br>";
>>>> is legal PHP code.
>>>
>>> As is, FWIW
>>> $row = $result->fetch_assoc(); $array[$n] = $row;
>>> echo $n.") ".$array[$n]['songs']."<br>";
>>>
>>> Or even
>>> $row[$n] = $result->fetch_assoc();
>>> echo $n.") ".$row[$n]['songs']."<br>";
>>
>> I wasn't sure if that would work or not.
>
> All the above suggestions work.
> First off, the PHP language guarantees that they work, so they work in
> principle. Secondly, I've tried them all, and they work in practice
>
>> But I only have a few columns in the table anway so I just did the
>> assignments one item at a time.
>
> Your problem, your loss.

I think I have now parsed his original problem, although he still hasn't
stated it clearly.

I think that what he wants to do is retrieve an array containing all the
rows returned by the query in one go, instead of row by row.

Now this is where the smart cookie would read the php mysqli::result
class information to see what function they might want:

http://www.php.net/manual/en/class.mysqli-result.php

And there the really smart cookie might notice the function fetch_all

http://www.php.net/manual/en/mysqli-result.fetch-all.php

And it's possible that, depending on whether he wants the sub arrays
indexed by column number or column name, that what richard is actually
after is something like:

$sql = "select name from songs order by name";
$result = mysqli_query( $sql );
if ( $result !== false ) {
$data = mysqli_fetch_all( $result, MYSQLI_ASSOC );
}
else {
/* handle the error dumbass */
}

(where MYSQLI_ASSOC could also be MYSQLI_NUM or MYSQLI_BOTH)

which might then give him an array of arrays whose keys looked like:

$data[0]["name"]
$data[1]["name"]
$data[2]["name"]
......
$data[n]["name"]

But I'm still not sure if this is what he actually wants to do, it's just
my best guess. It's certainly not the obvious solution to the originally
posted question.

There's also a caution on using the fetch_all function. It's memory
hungry and can exceed your process memory limits! That's probably not
going to be a clean exit!

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: mysqli fetch_assoc() straight to array [message #186024 is a reply to message #186016] Sat, 31 May 2014 17:26 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 30 May 2014 20:53:17 -0400, Jerry Stuckle wrote:

> On 5/30/2014 5:11 PM, Christoph Michael Becker wrote:
>> richard wrote:

>>> I just figured there had to be some way of being able to assign the
>>> columns within the function, but apparently not.

>> Maybe you're looking for mysqli_stmt_bind_result()[1]?

> No, he's not...

I think I know what he's looking for, but his OP was so badly worded
regarding what he's trying to do that it's really hard to tell.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
Re: mysqli fetch_assoc() straight to array [message #186025 is a reply to message #186024] Sat, 31 May 2014 19:08 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/31/2014 1:26 PM, Denis McMahon wrote:
> On Fri, 30 May 2014 20:53:17 -0400, Jerry Stuckle wrote:
>
>> On 5/30/2014 5:11 PM, Christoph Michael Becker wrote:
>>> richard wrote:
>
>>>> I just figured there had to be some way of being able to assign the
>>>> columns within the function, but apparently not.
>
>>> Maybe you're looking for mysqli_stmt_bind_result()[1]?
>
>> No, he's not...
>
> I think I know what he's looking for, but his OP was so badly worded
> regarding what he's trying to do that it's really hard to tell.
>

You're doing better than I am then, Denis. I'm definitely unsure of
what he really wants.

--
==================
Remove the "x" from my email address
Jerry Stuckle
jstucklex(at)attglobal(dot)net
==================
Re: mysqli fetch_assoc() straight to array [message #186026 is a reply to message #186025] Sun, 01 June 2014 10:35 Go to previous message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Sat, 31 May 2014 15:08:05 -0400, Jerry Stuckle wrote:

> On 5/31/2014 1:26 PM, Denis McMahon wrote:
>> On Fri, 30 May 2014 20:53:17 -0400, Jerry Stuckle wrote:
>>
>>> On 5/30/2014 5:11 PM, Christoph Michael Becker wrote:
>>>> richard wrote:
>>
>>>> > I just figured there had to be some way of being able to assign the
>>>> > columns within the function, but apparently not.
>>
>>>> Maybe you're looking for mysqli_stmt_bind_result()[1]?
>>
>>> No, he's not...
>>
>> I think I know what he's looking for, but his OP was so badly worded
>> regarding what he's trying to do that it's really hard to tell.
>>
>>
> You're doing better than I am then, Denis. I'm definitely unsure of
> what he really wants.

In his original post, he's using fetch_assoc and talking about getting
all the columns, and also talking about 2d arrays.

Of course fetch_assoc does get all the columns, as a 1d array.

I think he's confusing columns and rows, and what he means is that he
wants to fetch all the rows as a 2d array.

As we almost all (except richard and maybe a couple of others) know, php
doesn't really have multi-dimensional arrays, but it has a simulation of
them by nesting 1d arrays n-levels deep[1].

I think he's thrown us all of scent of what he actually wants by the
typical richardism of getting the words "rows" and "columns" mixed up.

fetch_assoc fetches one row of columns as a 1d array

What he wants is (what he calls) a 2d array (and is actually nested 1d
arrays to 2 levels) containing all the rows of the result set.

So his example code to do this with fetch_assoc should have looked
something like:

while ( $row = mysqli_fetch_assoc( $result ) !== FALSE )
$rows[] = $row;

Whereas the single call method he's actually looking for is:

$rows = mysqli_fetch_all( $result, MYSQLI_ASSOC );

This is probably where I need to say "richard, read the fucking manual
for mysqli_fetch_all, especially the note about memory useage!" and
richard ignores me, only to come back later moaning that
mysqli_fetch_assoc doesn't work, when it does, but his process doesn't
have enough memory allocated by the hosting service for his screwed up
database design to use it.

Of course, to us[2] this is just another good reason to normalise a
database, but then we all know that richard doesn't do normal.

[1] For the ignorant, a true multi-d array is keyed arr[a,b,c,d .... ],
not arr[a][b][c][d]....[]

[2] People who understand databases.

--
Denis McMahon, denismfmcmahon(at)gmail(dot)com
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: mysqli fetch_assoc() straight to array (-> comp.lang.php)
Next Topic: ArrayAccess interface, Traversable interface and foreach
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Thu Nov 21 12:58:06 GMT 2024

Total time taken to generate the page: 0.05119 seconds