complex05 Posted October 16, 2006 Share Posted October 16, 2006 hello,I've seen a function before that does this but forgot what it was. Right now whenever I use $data = mysql_fetch_array($query) i do the following after:$name = $data["name"];$email = $data["email"];$phone = $data["phone"];etc etc etc... isn't there a function that will do all of this for me? Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/ Share on other sites More sharing options...
gijew Posted October 16, 2006 Share Posted October 16, 2006 Are you talking about storing values into an array? From what it looks like, you're taking the values from an array and storing them inside of a variable. Are you trying to put them back in an array? Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109625 Share on other sites More sharing options...
kenrbnsn Posted October 16, 2006 Share Posted October 16, 2006 If you use the function mysql_fetch_assoc() instead, you can then use the [url=http://www.php.net/]extract()[/url] function to do that. Why don't you just use the array references, which makes the code much more self-commenting.Ken Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109627 Share on other sites More sharing options...
alpine Posted October 16, 2006 Share Posted October 16, 2006 or --> list() --> http://no.php.net/manual/fi/function.list.phpor another old fashion way[code]<?php$col = mysql_fetch_array($select, MYSQL_ASSOC);foreach($col as $fieldname => $value){${$fieldname} = $value;}?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109628 Share on other sites More sharing options...
neoform Posted October 16, 2006 Share Posted October 16, 2006 [quote author=kenrbnsn link=topic=111674.msg452711#msg452711 date=1161020142]If you use the function mysql_fetch_assoc() instead, you can then use the [url=http://www.php.net/]extract()[/url] function to do that. Why don't you just use the array references, which makes the code much more self-commenting.Ken[/quote]I've always wondered how people came to use mysql_fetch_array() instead of mysql_fetch_assoc(), seems like everyone does it.. Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109631 Share on other sites More sharing options...
kenrbnsn Posted October 16, 2006 Share Posted October 16, 2006 The mysql_fetch_array() function came first. The myslq_fetch_assoc() function didn't come out until after version 4.0.3Ken Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109636 Share on other sites More sharing options...
.josh Posted October 16, 2006 Share Posted October 16, 2006 i use fetch_array, simply because it's all encompassing. I mean, fetch_assoc returns an associative array. fetch_row returns a numerical array. but fetch_array returns both by default. Or i can specify one or the other if i [i]really[/i] want to, with an optional argument. But i usually don't. I can simply use fetch_array and just use the numerical or associative version as i see fit. I feel it is less hassle. Maybe that's just me. Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109657 Share on other sites More sharing options...
neoform Posted October 16, 2006 Share Posted October 16, 2006 yeah, but that doubles the amount of ram being used by the array..i can't imagine that'd be a good rule to go by if you're using any sizable amount of data.. text.. blobs.. ? Quote Link to comment https://forums.phpfreaks.com/topic/24117-mysql_fetch_array-extracting-variables/#findComment-109661 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.