strange issue of mysql query and array

Links for php scripts

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 1
Joined: Thu Nov 07, 2013 6:14 am

strange issue of mysql query and array

Postby bartsimpson » Thu Nov 07, 2013 7:02 am

I have a strange issue in this script.
There is a table of primenumbers. and when selecting them in Asc. order to populate the array it removes the 1st entry (no. 3 (prime)). But is always there when selecting the records in Desc. order.
I just can't figure it out why?

here is part of the code.

Code: Select all

$inputNumber    = 69;
$primedataArray = array();

$query = "SELECT * FROM primesets where primenumber <= " . $inputNumber . " order by primenumber asc" ;
$data = mysql_query($query)  or die(mysql_error());

/* Get all Records from the table upto the Input number */
$dataArray = mysql_fetch_array( $data ) ;

while($dataArray = mysql_fetch_array( $data ))
  $primedataArray[] = $dataArray['primenumber'];

echo "<pre>";
  print_r ($primedataArray) ;
echo "</pre>";

And yes the table has value 3 in there. The first record itself.
Can anyone shed some light here please?

(pseudo)Bart Simpson

Return to “PHP Scripts”

Who is online

Users browsing this forum: No registered users and 3 guests