Jump to content

help with multiple mysql rows?


joecooper

Recommended Posts

Hi,

 

i have a site im building, its like one of those sites that update daily with funny videos / games.

 

i have a mysql database with a game title, description and link.

 

I need the last 2 enterys added (using the ID field) to be seperate at the top (featured), and then the rest to be on a table as a list, 10 on each page.

 

i used to use this before but was a while ago and since lost the code i had.

 

thanks.

Link to comment
https://forums.phpfreaks.com/topic/121752-help-with-multiple-mysql-rows/
Share on other sites

You could do this:

 

<?php

$query = mysql_query("SELECT fields FROM table");

$i = 1;
while ($row = mysql_fetch_assoc($query)){

   if ($i == 1 || $i == 2){
      //this is where you put the code for the two featured posts
   } else {
      //this is where you put the code for all the other posts
   }

$i++;
}

?>

 

include("db.php");
     $query = mysql_query("Select * FROM games");

$i = 1;
while ($row = mysql_fetch_assoc($query)){

   if ($i == 1 || $i == 2){
      echo("$row['title']");
   } else {
      //this is where you put the code for all the other posts
   }

$i++;
}

 

that always returns a blank page, no errors or anything. and even the HTML that comes after is cleared.

Try

 

<?php
include("db.php");

$query = mysql_query("SELECT * FROM games")or die(mysql_error());

$i = 1;
while ($row = mysql_fetch_assoc($query)){

   if ($i == 1 || $i == 2){
      echo $row['title'] .'<br>';
   } else {
      //this is where you put the code for all the other posts
   }

$i++;
}

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.