Jump to content

Getting Columns from Mysql and inserting into a variable


xerox02

Recommended Posts

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 :).

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.

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 :).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.