Page 1 of 1

How to convert MySql data into variables?

Posted: Wed May 16, 2012 11:50 pm
by mcc_shane
Hi Everyone,

I'm trying to convert my MySql data into variables so I can use them on my website. For example, if I want to convert a city or even first or last name into a variable. How would I go about doing that? Thanks everyone!

Re: How to convert MySql data into variables?

Posted: Thu May 17, 2012 9:30 am
by social_experiment
Depending on how you retrieve the results (mysql_fetch_object, mysql_fetch_array, mysql_fetch_row) you can use that to access the values.

Code: Select all

<?php
 // 
 $obj = mysql_fetch_object($sql);

 echo $obj->field1; // $obj->field1 contains data present in 'field1' of your table
 // etc.
?>
If you want to create and use (other) variables you can equate the above values like this -

Code: Select all

<?php
 $field1 = $obj->field1;

 echo $field1;
?>