Skip to content

Instantly share code, notes, and snippets.

@erinbush
Created October 13, 2012 00:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erinbush/3882422 to your computer and use it in GitHub Desktop.
Save erinbush/3882422 to your computer and use it in GitHub Desktop.
Joining tables and combining results in a table.
<p>
<p><h2>Details</h2></p>
<p>Details of all the executions by state with lat/long data.</p>
<p><table border='1' cellpadding='10'>
<tr><th>First Name</th><th>Last Name</th><th>Crime</th><th>State</th><th>Lat</th><th>Long</th></tr>
<?php
$result = mysql_query("SELECT * FROM executions INNER JOIN statelatlong ON executions.statelatlongid = statelatlong.id", $connection);
if (!$result) {
die("Database query failed: ");
}
/* Organize results of Query into a table */
while($row = mysql_fetch_array($result)) {
// set up a row for each record
echo "<tr>";
echo "<td>" . $row['first'] . "</td>";
echo "<td>" . $row['last'] . "</td>";
echo "<td>" . $row['crime']. "</td>";
echo "<td>" . $row['state']. "</td>";
echo "<td>" . $row['lat']. "</td>";
echo "<td>" . $row['long']. "</td>";
echo "</tr>";
}
?>
</table></p>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment