php - Using 2 while loops to get data from 2 tables -
i'm trying id users database can link about.php?id=$id1 , i'm using 2 while loops that. end getting want, about.php?id=$id1 there duplicate entries...
here's code.
<?php require("connect.php"); require("header.php"); $max = 5; //amount of articles per page. change want $p = $_get['p']; if(empty($p)) { $p = 1; } $limits = ($p - 1) * $max; //view news article! $id = isset($_get['id']) ? $_get['id'] : false; if($id && is_numeric($id)){ $id = $_get['id']; $sql = mysql_query("select * blogdata id = '$id'"); while($r = mysql_fetch_array($sql)) { echo $total; $id = $r['id']; $date = $r['date']; $title = $r['title']; $content = $r['content']; $email = $r['author_email']; $cat = $r['category']; $author = $r['author']; $query1 = mysql_query("select * users"); while ($row1 = mysql_fetch_array($query1)){ $id1 = $row1['id']; echo "<center> <table border='0' width='100%' cellspacing='10'> <tr> <td width='20%' valign='top'><div class='title'><a href=\"?id=$id\">$title</a></div> <div class='info'><i>$date</i><br /> <a href='$id1'>$author</a><br /> $cat</div> </td> <td width='80%' valign='top'>"; echo nl2br($content); echo "</td> </tr> </table> <hr /> <a href='index'>← rewind.</a> </center>"; } } }else{ //view news articles in rows $sql = mysql_query("select * blogdata order id desc limit ".$limits.",$max") or die(mysql_error()); //the total rows in table $totalres = mysql_result(mysql_query("select count(id) tot blogdata"),0); //the total number of pages (calculated result), math stuff... $totalpages = ceil($totalres / $max); while($r = mysql_fetch_array($sql)) { $id = $r['id']; $date = $r['date']; $title = $r['title']; $content = $r['content']; $email = $r['author_email']; $cat = $r['category']; $author = $r['author']; $query1 = mysql_query("select * users"); while ($row1 = mysql_fetch_array($query1)){ $id1 = $row1['id']; echo "<center> <table border='0' width='100%' cellspacing='10'> <tr> <td width='20%' valign='top'><div class='title'><a href=\"?id=$id\">$title</a></div> <div class='info'><i>$date</i><br /> <a href='$id1'>$author</a><br /> $cat</div> </td> <td width='80%' valign='top'>"; echo nl2br($content); echo "</td> </tr> </table> <hr /> </center>"; } } //close table echo "</tr></table><center>"; $page = $_get['p']; for($i = 1; $i <= $totalpages; $i++) { if ( $page == $i ) { echo "<b>$i</b>"; } else { echo "<a href='?p=$i'>$i</a>"; } if ($i < $totalpages) echo " <font color=\"#666\">•</font> "; } } echo "<br />"; require("footer.php"); ?>
couldn't question, select distinct column_name table
you? selects distinct rows table.
Comments
Post a Comment