简体   繁体   中英

MySQL PHP won't fetch all rows

While trying to make an overview of added "friends", the following code only returns the last added friend.

mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name WHERE bruger1='$usrname' AND status='Godkendt'";
$result=mysql_query($sql);
while($rows=mysql_fetch_array($result)){
  $venner=$rows['bruger2'];
}
$tbl_name="brugere";
$sql="SELECT * FROM $tbl_name WHERE email LIKE '$venner%'";
$result=mysql_query($sql);
?>
<div id="searchcenter">
  <div id="searchtop"></div>
<?php
  while($rows=mysql_fetch_array($result)){
?>
  <a href="http://festbook.dk/profil/start.php?r=profil&id=<? echo $rows['id']; ?>" class="profilresult">
    <img src="<? echo $rows['profilbilled']; ?>">
    <p><b>Navn: </b><? echo $rows['navn']; ?></p>
    <p><b>Mail: </b><? echo $rows['email']; ?></p>
    <p><b>Hjem: </b><? echo $rows['adresse']; ?></p>
    <p><b>FacebookID: </b><? echo $rows['facebook']; ?></p>
  </a>
  <?php
    }
  ?>
  </div>
</div>
</body>

What can I do to make it work correctly? Ideas?

I solved it by querying multiple tables...

$tbl_name="brugere";
$tbl_name2="venner";
$sql="SELECT * FROM $tbl_name, $tbl_name2 WHERE email=bruger2 AND status='Godkendt'";
$result=mysql_query($sql);

Thanks for the help anyways! :D

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM