Skip to content

Instantly share code, notes, and snippets.

@brucenorton
Created September 12, 2016 17:50
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 brucenorton/df87dd28acb18375788601674e91e6e2 to your computer and use it in GitHub Desktop.
Save brucenorton/df87dd28acb18375788601674e91e6e2 to your computer and use it in GitHub Desktop.
hypertext select join statement
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>php mySQLi prepared statments</title>
</head>
<body>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>php mySQLi prepared statments</title>
</head>
<body>
<?php
include '_includes/connect.php';
//define table
$tbl = "items";//change to your table i.e. John_app
$tbl2 = "photos";
//write query
$query = "SELECT $tbl.itemID, $tbl.title, $tbl.description, $tbl.price, $tbl2.src FROM $tbl, $tbl2 WHERE $tbl.itemID = $tbl2.itemID";
//prepare statement, execute, store_result
if($displayStmt = $mysqli->prepare($query)){
$displayStmt->execute();
$displayStmt->store_result();
$numrows = $displayStmt-> num_rows;
echo("<br>results: $numrows");
}
//bind results
$displayStmt->bind_result($itemIDResult, $titleResult, $descriptionResult, $priceResult, $srcResult);
//fetch results
while($displayStmt->fetch()){
echo("<br>results: $itemIDResult, $titleResult, $descriptionResult, $priceResult, $srcResult<br>");
echo ("<img src=\"images/$srcResult\"><br>");
}
?>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment