Jump to content


Photo

only getting so many records from database


  • Please log in to reply
4 replies to this topic

#1 blev

blev
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 19 April 2006 - 12:21 PM

I have this piece of code which uses values from an array to get data from a database. Where/how do i make a simple for/ foreach loop to collect, say the first 3 records. thanks in advance

while(list($key, $val) = each($club_score_array)) 
    {
        $query3 = mysqli_query($conn, "SELECT * FROM event, venue WHERE event.venue = venue.venueName AND event.date <= '$mysqlTwoDays' AND event.eventID = '$key'") or die('Error, query failed'); 
             while ($row = mysqli_fetch_array($query3))
            {
            echo "<table width='700'>
                <tr>
                <td width='600'><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></span></td>
                                </tr>
                                
                            
                             </table><br />";
                        }
                        mysqli_free_result($query3);
            }


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 19 April 2006 - 01:27 PM

Do it with the query ... SELECT whatever FROM table WHERE conditions ... LIMIT 3
Legend has it that reading the manual never killed anyone.
My site

#3 freshrod

freshrod
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 19 April 2006 - 01:29 PM

Greetings

I'm a noob as well, but I think I may be able to help on this one. Either way you might want to take my advice with a grain of salt.

If you use the LIMIT command in your query, it should only return that many rows.

Example: $query3 = mysqli_query($conn, "SELECT * FROM event, venue WHERE event.venue = venue.venueName AND event.date <= '$mysqlTwoDays' AND event.eventID = '$key' LIMIT 3") or die('Error, query failed');

You can also specify which row to start at and how many to return like this:
SELECT * FROM event BLAH, BLAH whatever LIMIT 12, 5;
This would return rows 12 to 16 from the event table.

I hope this helps.
Nothing is foolproof to a talented fool.

#4 blev

blev
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 19 April 2006 - 01:46 PM

brilliant! thanks alot

#5 blev

blev
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 19 April 2006 - 04:03 PM

i've tried this on the above code with no joy. any idea's???

i've also tried it in a seperate piece of code it works fine. :-(




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users