Jump to content

PHP and mySQL


Ju-Pao

Recommended Posts

How can I retrieve a data from my mySQL database using PHP and save the data in a variable in in my PHP code

 

for example i have this table in the database

 

First name          Last Name

  Juan                  Punkista

 

I would like to store 'Juan' in variable $first and 'Punkista' in variable $last

 

thank you for your notice

Link to comment
https://forums.phpfreaks.com/topic/41752-php-and-mysql/
Share on other sites

How can I retrieve a data from my mySQL database using PHP and save the data in a variable in in my PHP code

 

for example i have this table in the database

 

First name           Last Name

   Juan                  Punkista

 

I would like to store 'Juan' in variable $first and 'Punkista' in variable $last

 

thank you for your notice

 

Do like this:

After ur query write this,

$first= $row-> First Name

$last= $row-> Last Name

Link to comment
https://forums.phpfreaks.com/topic/41752-php-and-mysql/#findComment-202393
Share on other sites

Hi,

 

You will have to change the follow with reference to your Database

1. ocalhost

2. DB_User

3. password

4. DB

 

You will have to change the follow with reference to your Table

1. table_name

2. first_name

3. last_name

 

Try this....

 


# Create DB connection

$dbhost = 'localhost';
$dbusername = 'DB_User';
$dbpasswd = 'password';
$database_name = 'DB';

#under here, don't touch!
$connection = mysql_pconnect("$dbhost","$dbusername","$dbpasswd")
    or die ("Couldn't connect to server.");
$db = mysql_select_db("$database_name", $connection)
    or die("Couldn't select database.");

/* Let's get the user info */
$sql = mysql_query("SELECT * FROM table_name");
$data = mysql_fetch_array($sql);

$first = $data[first_name];
$last = $data[last_name];

 

 

Link to comment
https://forums.phpfreaks.com/topic/41752-php-and-mysql/#findComment-202394
Share on other sites

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.