Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #13764 > unrolled thread

Re: mysqli fetch_assoc() straight to array

Started byLew Pitcher <lew.pitcher@digitalfreehold.ca>
First post2014-05-30 16:23 -0400
Last post2014-05-30 20:52 -0400
Articles 14 — 6 participants

Back to article view | Back to comp.lang.php

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: mysqli fetch_assoc() straight to array Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-05-30 16:23 -0400
    Re: mysqli fetch_assoc() straight to array Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-05-30 16:25 -0400
      Re: mysqli fetch_assoc() straight to array richard <noreply@example.com> - 2014-05-30 17:36 -0400
        Re: mysqli fetch_assoc() straight to array Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2014-05-31 10:32 -0400
          Re: mysqli fetch_assoc() straight to array Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-31 17:21 +0000
    Re: mysqli fetch_assoc() straight to array richard <noreply@example.com> - 2014-05-30 16:54 -0400
      Re: mysqli fetch_assoc() straight to array Jürgen Exner <jurgenex@hotmail.com> - 2014-05-30 14:08 -0700
      Re: mysqli fetch_assoc() straight to array Christoph Michael Becker <cmbecker69@arcor.de> - 2014-05-30 23:11 +0200
        Re: mysqli fetch_assoc() straight to array Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-30 20:53 -0400
          Re: mysqli fetch_assoc() straight to array Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-31 17:26 +0000
            Re: mysqli fetch_assoc() straight to array Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-31 15:08 -0400
              Re: mysqli fetch_assoc() straight to array Denis McMahon <denismfmcmahon@gmail.com> - 2014-06-01 10:35 +0000
      Re: mysqli fetch_assoc() straight to array Denis McMahon <denismfmcmahon@gmail.com> - 2014-05-30 23:27 +0000
      Re: mysqli fetch_assoc() straight to array Jerry Stuckle <jstucklex@attglobal.net> - 2014-05-30 20:52 -0400

#13764 — Re: mysqli fetch_assoc() straight to array

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2014-05-30 16:23 -0400
SubjectRe: mysqli fetch_assoc() straight to array
Message-ID<9N5iv.502150$l83.240869@fx28.iad>
On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
<noreply@example.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

[toc] | [next] | [standalone]


#13765

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2014-05-30 16:25 -0400
Message-ID<HO5iv.487909$Qz3.353198@fx07.iad>
In reply to#13764
On Friday 30 May 2014 16:23, in comp.lang.php, "Lew Pitcher"
<lew.pitcher@digitalfreehold.ca> wrote:

> 
> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
> <noreply@example.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

[toc] | [prev] | [next] | [standalone]


#13769

Fromrichard <noreply@example.com>
Date2014-05-30 17:36 -0400
Message-ID<1of7bjh9t6y8i$.vwkqjwemznls.dlg@40tude.net>
In reply to#13765
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.pitcher@digitalfreehold.ca> wrote:
> 
>> 
>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>> <noreply@example.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.

[toc] | [prev] | [next] | [standalone]


#13773

FromLew Pitcher <lew.pitcher@digitalfreehold.ca>
Date2014-05-31 10:32 -0400
Message-ID<hKliv.262901$QE3.62710@fx16.iad>
In reply to#13769
On Friday 30 May 2014 17:36, in comp.lang.php, "richard"
<noreply@example.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.pitcher@digitalfreehold.ca> wrote:
>> 
>>> 
>>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>>> <noreply@example.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

[toc] | [prev] | [next] | [standalone]


#13774

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-05-31 17:21 +0000
Message-ID<lmd32k$rv9$8@dont-email.me>
In reply to#13773
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@example.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.pitcher@digitalfreehold.ca> wrote:
>>> 
>>> 
>>>> On Friday 30 May 2014 07:59, in comp.databases.mysql, "richard"
>>>> <noreply@example.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@gmail.com

[toc] | [prev] | [next] | [standalone]


#13766

Fromrichard <noreply@example.com>
Date2014-05-30 16:54 -0400
Message-ID<1jha1xk2xj4hw.1012a4ildu9nd.dlg@40tude.net>
In reply to#13764
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@example.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.

[toc] | [prev] | [next] | [standalone]


#13767

FromJürgen Exner <jurgenex@hotmail.com>
Date2014-05-30 14:08 -0700
Message-ID<3dsho91hm377sla3774usis0qs2gjgps2h@4ax.com>
In reply to#13766
On Fri, 30 May 2014 16:54:02 -0400, richard <noreply@example.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@example.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

[toc] | [prev] | [next] | [standalone]


#13768

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-05-30 23:11 +0200
Message-ID<5388f400$0$6665$9b4e6d93@newsspool3.arcor-online.net>
In reply to#13766
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

[toc] | [prev] | [next] | [standalone]


#13772

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-05-30 20:53 -0400
Message-ID<lmb95p$d3e$2@dont-email.me>
In reply to#13768
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#13775

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-05-31 17:26 +0000
Message-ID<lmd3c0$rv9$9@dont-email.me>
In reply to#13772
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@gmail.com

[toc] | [prev] | [next] | [standalone]


#13776

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-05-31 15:08 -0400
Message-ID<lmd9ag$277$1@dont-email.me>
In reply to#13775
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@attglobal.net
==================

[toc] | [prev] | [next] | [standalone]


#13777

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-06-01 10:35 +0000
Message-ID<lmevla$9bn$1@dont-email.me>
In reply to#13776
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@gmail.com

[toc] | [prev] | [next] | [standalone]


#13770

FromDenis McMahon <denismfmcmahon@gmail.com>
Date2014-05-30 23:27 +0000
Message-ID<lmb45d$rv9$7@dont-email.me>
In reply to#13766
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@gmail.com

[toc] | [prev] | [next] | [standalone]


#13771

FromJerry Stuckle <jstucklex@attglobal.net>
Date2014-05-30 20:52 -0400
Message-ID<lmb94h$d3e$1@dont-email.me>
In reply to#13766
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@example.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@attglobal.net
==================

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web