refiking Posted October 8, 2008 Share Posted October 8, 2008 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']; } Link to comment https://forums.phpfreaks.com/topic/127499-solved-how-do-i-go-about-this-kind-of-a-query/ Share on other sites More sharing options...
dr0p Posted October 8, 2008 Share Posted October 8, 2008 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++; } Link to comment https://forums.phpfreaks.com/topic/127499-solved-how-do-i-go-about-this-kind-of-a-query/#findComment-659680 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.