Re: mysqli fetch_assoc() straight to array [message #186009 is a reply to message #186008] |
Fri, 30 May 2014 20:25 |
Lew Pitcher
Messages: 60 Registered: April 2013
Karma:
|
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
|
|
|