/    Sign up×
Community /Pin to ProfileBookmark

First row not being returned

For some reason, I’m not getting the first row from any selection. I even verified it in PHPMyAdmin and ran the query there; it returned all the correct rows. It’s only when I run the script on a page that the first row doesn’t get returned. Anyone know why? Could it be the mysql_fetch_array ?

Here’s my script:

[CODE]
mysql_connect(“”, “”, “”) or die(mysql_error());
mysql_select_db(“DBNAME”) or die(mysql_error());
$result = mysql_query(“select * from cars where(model='”.$_POST[‘model’].”‘)”) or die(mysql_error());
$row = mysql_fetch_array( $result );

echo ‘<select>’;
while($row = mysql_fetch_array($result)){
echo “<option>”.$row[‘Trim’].”</option>”;
}
echo ‘</select>’;
[/CODE]

Thanks for any help you may have.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJun 30.2008 — The (apparently useless) call to mysql_fetch_array() before you start the while loop is advancing the result set row pointer, thus the first row does not get accessed within the loop.
Copy linkTweet thisAlerts:
@stinkysGTIauthorJun 30.2008 — What can I use instead of the fetch array? I'm kinda new to mysql :
Copy linkTweet thisAlerts:
@NogDogJun 30.2008 — As far as I can see from the code provided, there is no reason for that first fetch (before the while loop), so just delete (or comment out) that line.
Copy linkTweet thisAlerts:
@stinkysGTIauthorJun 30.2008 — Thanks NogDog; after you mentioned it, I realized that was in there twice and for no reason really.

Now it works just right ?

Thank you
×

Success!

Help @stinkysGTI spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...