LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   PHP: storing all data form a db row in variables with the same name as the db column (https://www.linuxquestions.org/questions/programming-9/php-storing-all-data-form-a-db-row-in-variables-with-the-same-name-as-the-db-column-654671/)

konqi 07-09-2008 02:43 PM

PHP: storing all data form a db row in variables with the same name as the db column
 
its maybe a bit unclear.

What i want to do is getting all the data out of a db row, and storing this data in a variable with the name of the db column. To explain it:
Code:

\\ This is what i use right now
$sql = "SELECT * FROM pages";
$query = mysql_query($sql);
while ($output = mysql_fetch_array($query) {
  $pageName = $output["pageName"];
  $pageTitle = $output["pageTitle"]
}

But what i want is that it automaticly assigns the data of $output["pageName"] (and pageTitle) to a variable with the name of the column in the database.
I think i have to do someting with a foreach, but i'm not sure.

Hope this was clear.

AdaHacker 07-09-2008 07:57 PM

You could just use extract().

konqi 07-10-2008 05:13 AM

yes it works, thanks!


All times are GMT -5. The time now is 08:09 AM.