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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.