Jump to content

LIMIT?


Cooper94

Recommended Posts

My code is:

<? include 'db.php' ?>
<?php
  // coonnect to database
  if (isset($_GET['id'])) {
    $sql = "SELECT date FROM pirep WHERE username='{$_GET['id']}' LIMIT 0,5";
    if ($result = mysql_query($sql)) {
      $row = mysql_fetch_assoc($result);
    } else {
    echo "query failed ".mysql_error();
    }
  } else {
    echo "No User Selected";
  }

?>
<br>
<h1 align="center">Logged Flights</h1>
<table border="0" cellpadding="5" cellspacing="0" align="center" style="font-size: 9pt; border: solid 1px">

    <tr bgcolor="#b5d0e5">
<th bgcolor="#666666"><font color="#FFFFFF">Date</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Departure</font></th>
<th bgcolor="#666666"><font color="#FFFFFF">Arrival</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Aircraft</font></th>
        <th bgcolor="#666666"><font color="#FFFFFF">Time</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Comments</font></th>

    </tr>
    <tr>
<td align="center"><?echo $row['date']; ?></td>
<td align="center" height="11"><?echo $row['icao_orig']; ?></td>
<td align="center" height="11"><?echo $icao_dest; ?></td>
<td align="center" height="11"><?echo $aircraft; ?></td>
        <td align="center" height="11"><?echo $flthrs2;   ?></td>
<td align="center" height="11"><?echo $comments;  ?></td>

    </tr>
</table>

But it only show's one not three, am I doing something wrong?

Link to comment
https://forums.phpfreaks.com/topic/138343-limit/
Share on other sites

try

<?php include 'db.php' ?>
<?php
// coonnect to database
if (!isset($_GET['id'])) {
die("No User Selected");
}
$sql = "SELECT date FROM pirep WHERE username='{$_GET['id']}' LIMIT 0,5";
if (!$result = mysql_query($sql)) {
die("query failed " . mysql_error());
}
while (($row = mysql_fetch_assoc($result)) != false) {

?>
<br>
<h1 align="center">Logged Flights</h1>
<table border="0" cellpadding="5" cellspacing="0" align="center" style="font-size: 9pt; border: solid 1px">

    <tr bgcolor="#b5d0e5">
<th bgcolor="#666666"><font color="#FFFFFF">Date</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Departure</font></th>
<th bgcolor="#666666"><font color="#FFFFFF">Arrival</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Aircraft</font></th>
        <th bgcolor="#666666"><font color="#FFFFFF">Time</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Comments</font></th>

    </tr>
    <tr>
<td align="center"><? echo $row['date']; ?></td>
<td align="center" height="11"><? echo $row['icao_orig']; ?></td>
<td align="center" height="11"><? echo $icao_dest; ?></td>
<td align="center" height="11"><? echo $aircraft; ?></td>
        <td align="center" height="11"><? echo $flthrs2; ?></td>
<td align="center" height="11"><? echo $comments; ?></td>

    </tr>
</table>
<?php } ?>

you needed a loop

 

Scott.

 

Link to comment
https://forums.phpfreaks.com/topic/138343-limit/#findComment-723378
Share on other sites

just reshuffle the html

<?php include 'db.php' ?>
<?php
// coonnect to database
if (!isset($_GET['id'])) {
die("No User Selected");
}
$sql = "SELECT date FROM pirep WHERE username='{$_GET['id']}' LIMIT 0,5";
if (!$result = mysql_query($sql)) {
die("query failed " . mysql_error());
}
?>
<br>
<h1 align="center">Logged Flights</h1>
<table border="0" cellpadding="5" cellspacing="0" align="center" style="font-size: 9pt; border: solid 1px">
<?php
while (($row = mysql_fetch_assoc($result)) != false) {

?>

    <tr bgcolor="#b5d0e5">
<th bgcolor="#666666"><font color="#FFFFFF">Date</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Departure</font></th>
<th bgcolor="#666666"><font color="#FFFFFF">Arrival</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Aircraft</font></th>
        <th bgcolor="#666666"><font color="#FFFFFF">Time</font></th>
<th bgcolor="#006699"><font color="#FFFFFF">Comments</font></th>

    </tr>
    <tr>
<td align="center"><? echo $row['date']; ?></td>
<td align="center" height="11"><? echo $row['icao_orig']; ?></td>
<td align="center" height="11"><? echo $icao_dest; ?></td>
<td align="center" height="11"><? echo $aircraft; ?></td>
        <td align="center" height="11"><? echo $flthrs2; ?></td>
<td align="center" height="11"><? echo $comments; ?></td>

    </tr>
<?php } ?>
</table>

 

Scott.

 

Link to comment
https://forums.phpfreaks.com/topic/138343-limit/#findComment-723463
Share on other sites

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.