Query not selecting all records

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Query not selecting all records

Post 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?
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: Query not selecting all records

Post 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
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: Query not selecting all records

Post 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!
Post Reply