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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

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

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.