Jump to content


Photo

**solved** limiting data that is displayed from an array


  • Please log in to reply
2 replies to this topic

#1 blev

blev
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 23 April 2006 - 10:09 PM

I have this code and only wish display the first three records from the array. I've tried using the LIMIT 3 in the sql statement but this does not work. Can anyone help me please???? thanks

foreach ($club_score_array as $key => $val) 
            {        
                    $query3 = mysqli_query($conn, "SELECT * FROM event, venue WHERE event.venue = venue.venueName AND event.date <= '$mysqlWeek' AND event.eventID = '$key' LIMIT 3") or die('Error, query failed'); 
                      while ($row = mysqli_fetch_array($query3))
                        {
                            $i++;
                            
                            $details = $row['details'];
                            $details_short = substr($details, 0,100);
                            echo "<table width='800'>
                            <tr><td><span class='h1'>$i</span></td><td>&nbsp;</td></tr>
                               <tr>
                                 <td width='700'><span class='h2'><a class=h2link href='eventDisplay.php?eventID=".$row['eventID']."'>".$row['eventName']."</a> @ <a class=h2link href='clubnightDisplay.php?clubname=".$row['club']."'>".$row['club']."</a></span></td>
                                 <td width='100' rowspan='4' align='right'><img src='images/flyers/".$row['flyerName']."' width='50' /></td>
                               </tr>
                               <tr>
                                 <td><span class='h2'><a class=h2link href='venueDisplay.php?venueName=".$row['venue']."'>".$row['venue']."</a>, ".$row['location']."</span></td>
                                </tr>
                               <tr>
                                 <td><span class='h3'>".$row['time']." -> ".$row['admission']."</span></td>
                                </tr>
                               <tr>
                                       
                                    
                                 <td>".$row['lineup']." -> $details_short...</td>
                                </tr>
                             </table><br />";
                        }
                        mysqli_free_result($query3);
            }


#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 23 April 2006 - 11:32 PM

Something like this?

$keys = array_keys(array_slice($club_score_array, 3, 0));
$keylist = join ("','", $keys);

$query3 = mysqli_query($conn, "SELECT * FROM event, venue
          WHERE event.venue = venue.venueName
          AND event.date <= '$mysqlWeek'
          AND event.eventID IN ('$keylist')")
           or die('Error, query failed');

          while ($row = mysqli_fetch_array($query3))
            {
                 # process results
            }

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#3 blev

blev
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 24 April 2006 - 07:51 PM

Thanks alot. The code didn't directly work but used the functions to gain the required result




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users