Jump to content

[SOLVED] How Do I Go About This Kind Of A Query


refiking

Recommended Posts

OK.  So, I need help with this one for real.  I need to pull 2 records from the database.  The record in the query just before $var and just after.  How can I pull just those two records. I am trying to set them as $before and $after variables.  Here's all I have:

 

$sql = mysql_query("SELECT * FROM `logs` WHERE `id` = $id'");
while($row = mysql_fetch_assoc($sql)){
//I need record 3 and record 5
$before = $row['reas'];
$after = $row['tres'];
}

 

Asdf, I know this isn't the most efficient way but I'm not exactly sure how to do it with SQL, but this should work.

 

$sql = mysql_query("SELECT * FROM `logs` WHERE `id` = '$id' LIMIT 5");
$i = 1;
while($row = mysql_fetch_assoc($sql)){
if ($i == 3) {
$before = $row['reas'];
} elseif ($i == 5) {
$after = $row['tres'];
}
$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.