I am trying to display information from an SQL query that should only have one result. I want to display the different columns in different places (with different formatting).
Here is my current code:
$query = "SELECT artist_ID, name, description, years_active FROM artist WHERE name LIKE ?;";
if (!($stmt = $conn->prepare($query))) {
echo "Prepare failed: (" . $conn->errno . ") " . $conn->error;
}
if (!$stmt->bind_param("s", $artist)) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
}
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->bind_result($artist_ID, $name, $description, $years_active);
while ($stmt->fetch()) {
printf("%s", $name);
printf("\n");
printf("%s", $description);
}
Even though I've included the newline character, it just prints these two results on one line. And I can't figure out how to print them without a while loop. Any insight?
`) if you're using HTML to echo the results. – Jay Blanchard Dec 07 '16 at 20:07