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 Quote Link to comment 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 Quote Link to comment 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>"; } } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.