Ich hoffe wirklich, ich bin nicht nur dumm. Ich versuche anhand der Benutzer-ID zwei Werte aus einer vorhandenen Datenbank abzurufen. Ich habe ein paar verschiedene Dinge versucht, also habe ich einen kommentierten Code für den Fall, dass ich in der Nähe bin!Kann nicht MySQL Tabelleneintrag in PHP Variable
Ich verwende eine SELECT-Anweisung, um die Werte zu erhalten, und versuche dann, sie an PHP-Variablen zu übergeben. Ich bekomme die Werte von der DB, nur nicht als PHP-Variablen.
<?php
//declare database variables
header('Content-type: text/html; charset=utf-8');
$username = "ishuttle";
$password = "";
$hostname = "localhost";
$dbname = "ishuttle_taxi-location";
$conn = mysql_connect($hostname, $username, $password);
if(! $conn)
{
die('Could not connect: ' . mysql_error());
}
//search database for driver location
mysql_select_db('ishuttle_taxi-location');
$sql = "SELECT _id, Latitude, Longitude
FROM driver_location
WHERE _id = 2";
$retval = mysql_query($sql, $conn);
if(! $retval)
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval))
{
echo "Lat :{$row['Latitude']} <br> ".
"Long: {$row['Longitude']} <br> ".
"--------------------------------<br>";
}
echo "Fetched data successfully\n";
$Lat = $retval[1];
$Long = $retval[2];
echo "$Lat";
?>
Prost im Voraus :)
Überprüfen Sie unsere mysqli_ oder PDO. Die msql_ für alle Intents tot in neueren Version von PHP. – nerdlyist