Re: mysqli fetch_assoc() straight to array [message #186011 is a reply to message #186010] |
Fri, 30 May 2014 21:08 |
Jrgen Exner
Messages: 14 Registered: March 2013
Karma:
|
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
|
|
|