Jump to content

Displaying 2 records, should be only 1


Ryuujin

Recommended Posts

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

 

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>";
         }
      }
   ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.