xerox02 Posted July 2, 2010 Share Posted July 2, 2010 I wanted to know how to assign each column in my mysql table to a variable, and I want each column to not repeat, and also descending by rows starting from row 1. So it will print the same variables differently because it can't repeat, and it's in descending order. For example: echo $idcolumn; *////// this would equal 1 echo $idcolumn; *////// this would equal 2 echo $idcolumn; *////// this would equal 3 echo $idcolumn; *////// this would equal 4 I am sorry if I am explaining this poorly. If there is anything you would like me to elaborate please ask . Quote Link to comment https://forums.phpfreaks.com/topic/206499-getting-columns-from-mysql-and-inserting-into-a-variable/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 2, 2010 Share Posted July 2, 2010 Use an array. Arrays are for sets of same type data, i.e. the result set from your query. Creating a sequential list of variables is a waste of processor time, because you must now either keep track of how many you created and what they are named or you must hard-code the code that uses them. It's also most efficient to do any processing and output of data from a query inside of the loop that retrieves that data instead of processing the data twice, once to get it into variables and a second time to use those variables. Quote Link to comment https://forums.phpfreaks.com/topic/206499-getting-columns-from-mysql-and-inserting-into-a-variable/#findComment-1080220 Share on other sites More sharing options...
xerox02 Posted July 2, 2010 Author Share Posted July 2, 2010 Use an array. Arrays are for sets of same type data, i.e. the result set from your query. Creating a sequential list of variables is a waste of processor time, because you must now either keep track of how many you created and what they are named or you must hard-code the code that uses them. It's also most efficient to do any processing and output of data from a query inside of the loop that retrieves that data instead of processing the data twice, once to get it into variables and a second time to use those variables. oh awesome, is there a way I set each column to a variable, because on my website I need to put the data of the columns in different areas, and maybe there is a way to do this with an array that I am unaware of . Sample code would me much apppreciated . Quote Link to comment https://forums.phpfreaks.com/topic/206499-getting-columns-from-mysql-and-inserting-into-a-variable/#findComment-1080504 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.