Jump to content

[SOLVED] php variables and mysql


sanchez77

Recommended Posts

<?php
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db('test_database') or die(mysql_error());

$sql = "SELECT id, name FROM test_table LIMIT 1"; // This will take only one row bcause of limit.
$result = mysql_query($sql)  or die(mysql_error());
$result = mysql_fetch_array($result);
$myVariableName = $result[0]['name'];
$myVariableId = $result[0]['id'];

// print the variable contents
echo 'Name: ' . $myVariableName . ' and ID: ' . $myVariableId;

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.