0

I have these codes to display content on my website.

Index.php

$rest = new rest;
$list = $rest->fetch_all();

<?php foreach ($rest->fetch_all() as $rest) { ?>
<br>
<a href="episode.php?id=<?php echo $rest['cast_id']; ?>">
#<?php echo $rest['cast_id']; ?>: <?php echo $rest['cast_title']; ?>
<br>
<font size="2" color="red">
<?php echo $rest['cast_about']; ?></font></a><br>
<br><div class="divider"> </div><br>

<?php } ?>

And include.php

class rest { public function fetch_all(){ global $pdo;

    $query = $pdo->prepare("SELECT * FROM podcast ORDER BY cast_id DESC");
    $query->execute();

    return $query->fetchAll();
} }

Please can someone tell me how I can get this to show results but not the latest result?

All fields are numbered using an ID tag in mysql.

On my site I have the latest entry listed above this list so I do not require the latest one appearing here.

Please help.

Thank you.

kevstarlive
  • 260
  • 4
  • 20
  • `LIMIT 18446744073709551615 OFFSET 10` in the end of query will ignore 10 top rows. Try it. (Based on [this question](http://stackoverflow.com/questions/255517/mysql-offset-infinite-rows)) – BlitZ Oct 23 '13 at 17:24
  • Nope. Just displays no results. – kevstarlive Oct 23 '13 at 17:29
  • 1
    Try this: `SELECT * FROM podcast ORDER BY cast_id DESC LIMIT 1000000 OFFSET 1`. – BlitZ Oct 23 '13 at 17:30

2 Answers2

0

The easiest way to do this is to discard the row in the application. You can do it in SQL by using a calculated limit. Calculate it as (SELECT COUNT(*) FROM podcast) - 1.

Or:

SELECT *
FROM podcast
EXCEPT
SELECT TOP 1 *
FROM podcast
ORDER BY cast_id ASC

Excluding the last row.

Joren
  • 3,068
  • 25
  • 44
0

You can either use array_shift or array_pop depending on your query sorting as shown bellow:

Assuming the latest result is the first raw on your query result.

$rest = new rest;
$list = $rest->fetch_all();
$latest = array_shift($list);

<?php foreach ($list as $rest) { ?>
<br>
<a href="episode.php?id=<?php echo $rest['cast_id']; ?>">
#<?php echo $rest['cast_id']; ?>: <?php echo $rest['cast_title']; ?>
<br>
<font size="2" color="red">
<?php echo $rest['cast_about']; ?></font></a><br>
<br><div class="divider"> </div><br>

<?php } ?>

If it's the last raw that you need to hide, then use array_pop

Rachid
  • 812
  • 6
  • 7