Ryuujin Posted December 25, 2007 Share Posted December 25, 2007 Hey guys, I am coding this script, and I want it to display only 1 record instead of 2. The database has 2 records in it, 1 for the ad, and one for the record of the person clicking the ad. Here is my code that either displays the ad as a link, or not as a link depending on if the person has clicked it before: <?php $date = date('d, H'); $result = mysql_query("SELECT * FROM members WHERE username='$_SESSION[username]'"); while($row = mysql_fetch_array($result)) $money = $row['money']; $result = mysql_query("SELECT * FROM ads WHERE active='1'"); while($row = mysql_fetch_array($result)) { $id = $row['id']; $result = mysql_query("SELECT * FROM ads WHERE clicker='$_SESSION[username]' AND clicker_clicked='$date' AND ad_id_clicked='$id'"); $clicked = mysql_num_rows($result); if($clicked == "1") { echo "<td>".$row['name']."</td> <td>".$row['clicks']."</td> <td>".$row['clicks_left']."</td></tr>"; } else { echo "<td><a href='surf.php?id=".$row['id']."'>".$row['name']."</a></td> <td>".$row['clicks']."</td> <td>".$row['clicks_left']."</td></tr>"; } } ?> Now, it displays the ad, plus one blank field (the one where it logs that the user clicked the ad), how can I modify my code to remove that blank field but keep the other one how it is? If you need screenshots they can be provided. Thanks, -Ryu Link to comment https://forums.phpfreaks.com/topic/83093-displaying-2-records-should-be-only-1/ Share on other sites More sharing options...
~n[EO]n~ Posted December 25, 2007 Share Posted December 25, 2007 You can use limit SELECT * FROM members WHERE username='$_SESSION[username] LIMIT 1; this will limit the record to 1 Link to comment https://forums.phpfreaks.com/topic/83093-displaying-2-records-should-be-only-1/#findComment-422747 Share on other sites More sharing options...
redarrow Posted December 25, 2007 Share Posted December 25, 2007 SESSIONS WERE WRONG ASWELL <?php $date = date('d, H'); $result = mysql_query("SELECT * FROM members WHERE username='".$_SESSION['username']."' LIMIT 1"); while($row = mysql_fetch_array($result)) $money = $row['money']; $result = mysql_query("SELECT * FROM ads WHERE active='1'"); while($row = mysql_fetch_array($result)) { $id = $row['id']; $result = mysql_query("SELECT * FROM ads WHERE clicker='".$_SESSION['username']."' AND clicker_clicked='$date' AND ad_id_clicked='$id'"); $clicked = mysql_num_rows($result); if($clicked == "1") { echo "<td>".$row['name']."</td> <td>".$row['clicks']."</td> <td>".$row['clicks_left']."</td></tr>"; } else { echo "<td><a href='surf.php?id=".$row['id']."'>".$row['name']."[/url]</td> <td>".$row['clicks']."</td> <td>".$row['clicks_left']."</td></tr>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/83093-displaying-2-records-should-be-only-1/#findComment-422837 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.