php - MySQL link to return results -
i have image displayed table , want user able click image directs them page returns rest of data row. need php loop this? can't quite figure out. returns last name, first name, , image:
<?php if (isset($_get['lastname'])) { $ln = $_get['lastname']; } include 'connection.php'; $query = "select * residents lastname '$ln%' "; $result = mysql_query($query); while($person = mysql_fetch_array($result)) { ?> <div class="media col-sm-4"> <a class="pull-left" href="redirectionpage.php?<?php echo $person['id'];?>.php"> <img class="media-object" src="upload/<?php echo $person['picture'];?>" width="100" height="100"/> </a> <div class="media-body"> <h4 class="media-heading"><?php echo $person['lastname'] . ", " . $person['firstname']; ?></h4> </div> </div> <?php }>?
is best way accomplish redirecting user new page , using mysql statement display new data?
this code other page:
<?php //gets data database include ('header.php'); include ('footer.php'); include ('connection.php'); $query = "select * residents id = lastname limit 1"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $outputpicture.='<div><p><img src="upload/' . $row['picture'].'" width="450" height="550"/></p></div>'; $outputname.= $row['lastname'] . ", " . $row['firstname']. '<br />'; $outputspouse.= $row['spouse']. '<br />'; $outputrelatives.= $row['relatives']. '<br />'; $outputaddress.= $row['address']. '<br />'; $outputbirthday.= $row['birthday']. '<br />'; $outputbegan.= $row['beganresidence']. '<br />'; $outputended.= $row['endedresidence']. '<br />'; $outputformer.= $row['formerresidence']. '<br />'; $outputcareer.= $row['career']. '<br />'; $outputeducation.= $row['education']. '<br />'; $outputmaritalstatus.= $row['maritalstatus']. '<br />'; $outputsiblings.= $row['siblings']. '<br />'; $outputspecialinterests.= $row['specialinterests'].'<br />'; } ?>
the link needs changed to
<a class="pull-left" href="redirectionpage.php?id=<?php echo $person['id'];?>">
adding id=
allow access id parameter in redirectionpage.php
via $_get
superglobal.
$id = $_get['id'];
you can use $id
variable select specified row database. see lot of examples this:
$query = "select * residents id = $id";
this works should not it, because creates sql injection vulnerability. read prepared statements , create sql can pass id paramater.
$stmt = $pdo->prepare("select * residents id = :id"); $stmt->bindvalue(':id', $id, pdo::param_int); $stmt->execute();
this should applied code use select list of images.
assuming id key residents table, should select 1 record, not need while loop. can use 1 fetch.
Comments
Post a Comment