PHP help please..

Discussion in 'PHP' started by lowridertj, Aug 7, 2007.

Thread Status:
Not open for further replies.
  1. #1
    in my code

    
    
    <? 
    $get = mysql_query("SELECT id,src,dest,msg,time,del,crew FROM $tab[mail] WHERE dest='$id' AND inbox='attacks' AND del='no' ORDER BY time DESC LIMIT $r,10;")or die("Invalid query: " . mysql_error());
       if((fetch("SELECT COUNT(msg) FROM $tab[mail] WHERE inbox='attacks' AND del='no' AND dest='$id';") == 0) && (!$del)){echo"<strong>you have no new attacks</strong>";}
    else{
        while ($sole = mysql_fetch_array($get))
              {
              $pmp = mysql_fetch_array(mysql_query("SELECT pimp,crew FROM $tab[pimp] WHERE id='$sole[1]';"));
              $crw = mysql_fetch_array(mysql_query("SELECT id,icon,name FROM $tab[crew] WHERE id='$pmp[1]';"));
              ?>
    
    
    PHP:
    what this will do is list down the name of someone that attacked you in past 24 hours. However what its doing right now is listing that person that attacked you in last 24 hours its listing them for every attack. How can I have it show only 1 time if a member has attacked in last 24 hours.

    Full code with html output listed below.
    
    
    <table width="100%">
     <tr>
      <td align="center"><b>showing revenges</b>
      <br>
    
      </td>
     </tr> <tr>
               <td><div align="center"><a href="revenges.php?cid=<?=$cid?>&r=<?=$prev?>&tru=<?=$tru?>">Previous Page </a>  -||-  <a href="revenges.php?cid=<?=$cid?>&r=<?=$next?>&tru=<?=$tru?>">Next Page</a></div></td>
    		           </tr>
     <tr>
      <td align="center" width="80%">
    <? 
    $get = mysql_query("SELECT id,src,dest,msg,time,del,crew FROM $tab[mail] WHERE dest='$id' AND inbox='attacks' AND del='no' ORDER BY time DESC LIMIT $r,10;")or die("Invalid query: " . mysql_error());
       if((fetch("SELECT COUNT(msg) FROM $tab[mail] WHERE inbox='attacks' AND del='no' AND dest='$id';") == 0) && (!$del)){echo"<strong>you have no new attacks</strong>";}
    else{
        while ($sole = mysql_fetch_array($get))
              {
              $pmp = mysql_fetch_array(mysql_query("SELECT pimp,crew FROM $tab[pimp] WHERE id='$sole[1]';"));
              $crw = mysql_fetch_array(mysql_query("SELECT id,icon,name FROM $tab[crew] WHERE id='$pmp[1]';"));
              ?>
              <table width="98%" height="100%" cellspacing="0" cellpadding="3" background="2nimages/bg.gif">
               <tr bgcolor="#000000">
                <td>
                <table width="100%" cellspacing="0" cellpadding="0">
                 <tr>
                    <td valign="middle" align="left">attacked by 
                      <?if($crw[1]){?>
                      <a href="crew.php?cid=<?=$crw[0]?>&tru=<?=$tru?>"><img border="0" align="absmiddle" src="<?=$crw[1]?>" width="15" height="15"></a> 
                      <?}?>
                      <a href="pimp.php?pid=<?=$pmp[0]?>&tru=<?=$tru?>"> 
                      <?=$pmp[0]?>
                      </a> revenge recieved "<font color="#3366FF"> 
                      <?=countdown($sole[4])?>
                      ago</font>"</td>
                  <td valign="middle" align="right"><b><a href="hit.php?pid=<?=$pmp[0]?>&tru=<?=$tru?>&revenge=1">attack back</a></td>             
    			  </tr>
                </table>
                </td>
               </tr>
              </table>
              <?}
        }
    ?>
    
      </td>
     </tr> <tr>
               <td><div align="center"><a href="revenges.php?cid=<?=$cid?>&r=<?=$prev?>&tru=<?=$tru?>">Previous Page </a>  -||-  <a href="revenges.php?cid=<?=$cid?>&r=<?=$next?>&tru=<?=$tru?>">Next Page</a></div></td>
    		           </tr>
    </table>
    
    
    
    PHP:
    I thank you greatly in advance..

    TJ
     
    lowridertj, Aug 7, 2007 IP
  2. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Use DISTINCT. I gave up looking around your queries after a few seconds because it's giving me a headache :p

    EDIT:
    I realised that won't work, well maybe if you use more efficient queries, particularly JOINs.

    A quick solution may be to add the names into an array in the "while ($sole = mysql_fetch_array($get))" loop. Then use an in_array to check if the name has already been listed.
     
    krt, Aug 7, 2007 IP
  3. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #3
    it was very simple really.

    If $pmp[0] is shown up more then 1 time in $sole[1]

    I want it to show only 1 time. But its listing it however many times its shown in the fetch array.
     
    lowridertj, Aug 7, 2007 IP
  4. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #4
    I was referring to your queries, not the code.

    Also, I edited my post after you posted.
     
    krt, Aug 8, 2007 IP
  5. lowridertj

    lowridertj Well-Known Member

    Messages:
    2,882
    Likes Received:
    40
    Best Answers:
    0
    Trophy Points:
    195
    #5
    thanks. rep added
     
    lowridertj, Aug 8, 2007 IP
Thread Status:
Not open for further replies.