A landing page on my website displays all the links relating to that section (recipes), using a for loop. This works fine. But I then need to extract the id generated in that for loop, to populate the page being generated.
I can't figure how to extract that id value (neither $_REQUEST['id']
nor $_REQUEST['id=?']
; i suspect both are definitely wrong). Is it through manipulating the URL string or is there another way? Following is the related code:
<?php
$id = intval($_REQUEST['id']);
if ($id) {// user gets here by clicking on link with id
$query = "SELECT * FROM recipes WHERE uniqno = $id";
$result = $conn->query($query);
$row = mysqli_fetch_all($result, MYSQLI_ASSOC);
$data = $row // fetch data from database
?>
<p><?php echo $data['ingredcontent']; ?></p>
<?php }
else {
foreach ($reciperow as $recipe) { ?>
<a href="?id=<?php echo $recipe['uniqno'];?>"><h2><?php echo $recipe['rectitle'];?></h2></a>
<p class="subhead"><?php echo $recipe['recsummary']; ?></p>
<?php }} ?>
Would appreciate if anyone could advise what I should pass to $_REQUEST to ensure it pulls out the 'id' defined in the foreach loop. (note: I'm intentionally staying away from PHP routing since this is a very basic project).