I need to echo a row from mysql database. When i echo this in the start (php) it works, but when in html, it doesn't work. Do i need to include something or what? I'm not very good with php, just learning...
1条回答 默认 最新
- dousao6313 2017-11-07 14:22关注
It doesn't work in html because $row variable is visible only in the while loop scope!
while($row = $result->fetch_assoc()) { if($_GET['email'] != $row["email"]){ echo "ERROR: Emails don't match! <br>"; echo "Please try again!"; exit(); $conn->close(); } echo "Ticket Information: <br>"; echo "Ticket: #" . $row["id"]. " - Name: " . $row["username"]. " - Message: " . $row["Message"]. "<br>"; echo "MySQL: "; echo $row["email"]; }
Try something like this:
while($row = $result->fetch_assoc()) { if($_GET['email'] != $row["email"]){ echo "ERROR: Emails don't match! <br>"; echo "Please try again!"; exit(); $conn->close(); } $rowId = $row["id"]; echo "Ticket Information: <br>"; echo "Ticket: #" . $row["id"]. " - Name: " . $row["username"]. " - Message: " . $row["Message"]. "<br>"; echo "MySQL: "; echo $row["email"]; }
In HTML:
<!DOCTYPE html> <html lang="en"> <head> <title>MrRockis's Website</title> </head> <body> // Here i want to echo my ticket ID! <b>Ticket ID:<b> <?php echo $rowId; ?> </body> </html>
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报