Page 1 of 1

Query not selecting all records

Posted: Fri Jun 25, 2010 6:33 pm
by gazzieh
I have the following code:

Code: Select all

<?php
$getarticle = $connector->query('SELECT ID,title,creator,created,last_edited FROM cmsarticles ORDER BY created ASC');
$articles = $connector->fetchArray($getarticle);
$creator = $connector->query('SELECT user FROM cmsusers');
$creators = $connector->fetchArray($creator);
						
while ($articles = $connector->fetchArray($getarticle))
{
echo '<p><a href="article.php?id='.$articles['ID'].'&act=v">';
echo $articles['title'];
echo '</a>';
echo '<br>Created by: '
.$creators['user'].'&nbsp;|&nbsp;Created on: '
.substr($articles['created'], 0, 10).'&nbsp;|&nbsp;Last edited: '
.substr($articles['last_edited'], 0, 10);
echo '</p>';
}
?>
This does as expected except that it does not pull in all records. If I do a DESC order then the first record is not displayed but if I do as above and do a ASC then I do not get the last record. If I do neither then I may as well do a DESC.

Why?

Re: Query not selecting all records

Posted: Fri Jun 25, 2010 7:17 pm
by mikosiko
gazzieh wrote:$getarticle = $connector->query('SELECT ID,title,creator,created,last_edited FROM cmsarticles ORDER BY created ASC');
$articles = $connector->fetchArray($getarticle);
because in the line above you are getting the first record of your record set and you are not doing nothing with it .... you are getting and processing the remaining records in the while loop.

your query is getting all the records the problem is how are you processing the results

Re: Query not selecting all records

Posted: Sat Jun 26, 2010 8:03 am
by gazzieh
Thanks for the reply. As soon as I read it I realised my mistake.

I really should not keep coding when I am tired.

Again, thanks!