So I added a small table to a database for a small project per se. Now I need help pulling that data out and displaying it correctly.
Table info
CREATE TABLE IF NOT EXISTS `tab_dimensions` (
`id` int(11) NOT NULL,
`length` int(11) NOT NULL,
`height` int(11) NOT NULL,
`width` int(11) NOT NULL,
`offset` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
first piece of data I have
INSERT INTO `tab_dimensions` (`id`, `length`, `height`, `width`, `offset`) VALUES
(56301, 600, 255, 183, 480);
So that is the basic layout of it. I have started with
$sql = 'SELECT id, length, width, height, offset FROM tab_dimensions';
But am having trouble with what goes next. Sorry a newbie here trying to figure it out and learn.
Thanks in advance!
Update- I this is a existing DB that I am adding to so the connection is not needed it already has one as $db
I am trying to use this data to populate a mouseover image mapping, so I only need to pull data and then use my existing table to display it.
<div id="hauler-pole" style="display:none;">
<table border="0" width="300">
<tr>
<td><strong>front</strong></td>
<td>Length: </td>
<td>Width: </td>
<td>Height: </td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
<tr>
<td><strong>Rear</strong></td>
<td>Length: </td>
<td>Width: </td>
<td>Height: </td>
</tr>
</table>
</div>
So if i mouse over id# 56301 that data is displayed only in the table.
http://www.w3schools.com/php/php_mysql_select.asp
<?php
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT id, length, width, height, offset FROM tab_dimensions";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"];
echo "length: " . $row["length"];
echo "width: " . $row["width"];
echo "height: " . $row["height"];
echo "offset : " . $row["offset"];
}
} else {
echo "0 results";
}
$conn->close();
?>