This code works but I am trying to work out how to change the $rose = mysql_fetch_assoc($stmt); section to 'prepared statement style'. Anyone know?
$rose_id = $_GET['rose_id'];
//prepare the statement
$stmt = $conn2->prepare("SELECT * FROM rosename
LEFT JOIN rosevariety ON (rosename.variety_name = rosevariety.variety_name)
WHERE rose_id = ?");
//bind the parameters
$stmt->bind_param("i", $rose_id);
//$sql = mysql_query($query, $conn);
$stmt->execute();
//was there a good response?
if ($stmt) {
$rose = mysql_fetch_assoc($stmt);
//echo out rose information
echo "<h1>".$rose['latin_name']."</h1>";
echo "<h2>".$rose['common_name']."</h2>";
If using PDO:
$rose = $stmt->fetch(PDO::FETCH_ASSOC);
http://www.php.net/manual/en/pdostatement.fetch.php
If using mysqli:
$result = $stmt->get_result();
$rose = $result->fetch_assoc();
http://www.php.net/manual/en/mysqli-stmt.get-result.php
http://php.net/manual/en/mysqli-result.fetch-assoc.php
If PDO is used, $stmt->fetch(PDO::FETCH_ASSOC) would be the answer.
http://www.php.net/manual/en/mysqli-stmt.fetch.php
while ($rose = $stmt->fetch()) {
//$rose = current row;
}
Actually I think to use it correctly you need to do
while(($rose = $stmt->fetch()) !== false){
//$rose = current row;
}