0
$query = mysql_query("SELECT `code`, `file` FROM `files` WHERE id >= '$idimg' ORDER BY id ASC LIMIT 1, 8");
while ($result = mysql_fetch_assoc($query)) {
    if (strlen($result['title']) < 12) {
        echo '<div id="recomimage5"><div id="linkstyle"><strong><a href="http://localhost/edu/1111111111111/download.php?code='. $result['code'] . ' "><img src="files/thumbs/' . $result['code'] . '/' . $result['file'] . '" alt="' . $result['title'] . '"></a></strong></div></div>';
    }
    else {
        echo '<div id="recomimage5"><div id="linkstyle"><strong><a href="http://localhost/edu/1111111111111/download.php?code='. $result['code'] . ' "><img src="files/thumbs/' . $result['code'] . '/' . $result['file'] . '" alt="' . $result['title'] . '"></a></strong></div></div>';   
    }
}

I order eight images from a MySQL database.

Result this query:

My id images for example is '5'

Results now is: '6' '7' '8' '9' '10' '11' '12' '13' // id numbers images

But I want a result like this - for example my images in reloaded page is '5'

Result must be: '1' '2' '3' '4' '5' '6' '7' '8'     // id numbers images
8
  • Have you tried removing the first parameter to your LIMIT clause? SELECT code, file FROM files WHERE id >= '$idimg' ORDER BY id ASC LIMIT 8 Commented Mar 10, 2013 at 7:31
  • Example id = '5' Result: '5' '6' '7' '8' '9' '10' '11' '12' Commented Mar 10, 2013 at 7:33
  • 1
    u have mentioned id should be greater than or equal to 5, so it's returning right, what you are getting....change your where conditions Commented Mar 10, 2013 at 7:36
  • 1
    If you're trying to return the 4 results to the left and 3 results to the right of the id, then change your WHERE clause to WHERE id >= $idimg - 4. Note: This is assuming $idimg has been sanitized. Commented Mar 10, 2013 at 7:38
  • 1
    Is there any error? If id is of type varchar, you may need to cast it for substraction. WHERE CAST(id AS UNSIGNED) >= CAST(id AS UNSIGNED) - 4 Commented Mar 10, 2013 at 7:53

1 Answer 1

1

please refer http://dev.mysql.com/doc/refman/5.0/en/select.html chnage WHERE id >= $idimg - 4 and limit 0,8 as initial row is 0 not 1

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.