Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

blanks in field names

Status
Not open for further replies.

mikeba1

Programmer
Jan 2, 2005
235
0
0
GB
possibly moving access to sql and php
first attempt to list table with blanks in field names
ok on select but what about the echo !!

<html>
<head><title>MySQL Table List</title></head><body>

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "members";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT `membership no`, `first name`, surname FROM Members";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["membership no"]. " - Name: " . $row["first name"]. " " . $row["surname"]. "<br>";
}
} else {
echo "0 results";
}
$conn->close();
?>
 
that should be fine. the spaces will be honoured in the associative array.

or you can always change things in the select

Code:
select `membership no` as membershipNum, `first name` as firstName //etc

if you are using an object return (fetch_object) then you'd have to use this notation
Code:
$row->{"first name"}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top