0

Hello, i'm trying to solve this problem for 2 weeks with no luck. I'm using sql lite to pull data from my database but it doesnt show up the last item.
I've tried to use an other server but again nothing! Even if i try to re-create the database the problem is still the same. Its a simple query which should be working fine but by database choose to be unique and not displaying what it should! Below you will find my code, i hope you could help me with this.

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
$con=mysqli_connect("127.0.0.1","root","123","pcbuilds");
if (mysqli_connect_errno()){
    session_start();
    $_SESSION['sqlerror'] = mysqli_connect_error();
    header ("Location: /pcbuilds/sqlerr.php");
}
$card_data =  mysqli_query($con, 
    "SELECT * FROM builds_test 
    WHERE approved = 'yes' 
    ORDER BY build_id 
    DESC 
    LIMIT 0, 10");
$card_data_result = mysqli_fetch_array($card_data);
while ($list = mysqli_fetch_array($card_data)){
    echo $list['build_name'];
    echo "<br />";
}

[IMG]http://img845.imageshack.us/img845/2841/wxbq.png[/IMG]
As you can see theres 5 items in the database but the script will only display 4 of them. In this case it will not display the number 5 because i have the DESC command on the query. If i remove the DESC it will show the item 5 but not the item 1 (the last item).
Note them i'm not geting any error from the script when in runs and in the phpmyadmin is working perfect!
[IMG]http://img593.imageshack.us/img593/6531/6wgn.png[/IMG]
Please i really need your help!

2
Contributors
1
Reply
13
Views
3 Years
Discussion Span
Last Post by cereal
1

Hi,

this is probably caused by the mysqli_fetch_array() at line 16, it will move the internal pointer to the following row, so the loop will display only the last four items. To include the first one remove line 16, i.e.:

$card_data_result = mysqli_fetch_array($card_data);

Otherwise simply use the variable:

echo $card_data_result['build_name'];

In alternative use data_seek() to reset the pointer:

$card_data_result = mysqli_fetch_array($card_data);
mysqli_data_seek($card_data, 0);
while ($list = mysqli_fetch_array($card_data)){

Docs: http://www.php.net/manual/en/mysqli-result.data-seek.php

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.