Jump to content
Larry Ullman's Book Forums

Data Types From Mysqli/php List

Recommended Posts

Hi Larry,


On page 493 you describe the list() function as well as its use in combination with a 'while' loop from a database select.  I have used this successfully innumerable times but I don't understand the following:


while(list($var1, var2, var3) = mysqli_fetch_row($result)) ....


The $var1, $var2 sources are in the database as tinyints, length 1. Yet if I do a vardump on the results of the list ($var1, $var2) they are strings, length 1.  Yet one can use those values as numeric array keys?


Can you please help me understand what's going on here?


Many thanks, and as always, Cheers from Oz.

Link to comment
Share on other sites

OK, I think that I understand what happens.


1) mysqli_fetch_row returns an array of strings - according to the w3schools manual which in my case get loaded into the PHP variables via the list.

2) in the php.net manual re arrays, it says "strings containing valid integers will be typecast to the integer type cast"


So while my MySQL data type is a tinyint, the mysqli_fetch_row returns its value as a string, but then that string is converted to an integer when it is inserted into an array as a key.


Please let me know if I've got it correctly.



Edited by Necuima
Link to comment
Share on other sites

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...