/    Sign up×
Community /Pin to ProfileBookmark

php mysql -while($row=mysql_fetch_array($result))

I have a straightforward query on a straightforward table as …

$validity=”Y”;
$query=”SELECT * FROM employees WHERE office=’$asking’ AND validity=’$validity'”;
$result=mysql_query($query) or die(mysql_error());
$num=mysql_num_rows($result);
$row=mysql_fetch_array($result,MYSQL_ASSOC);
if($num>0){
while($row=mysql_fetch_array($result))
{
echo'<tr>
<td>’,$row[reference],’ ‘,$num,'</td>
</tr>’;}

I know there are three valid rows and $num confirms this but I am only getting the last two out following while($row=………….

If I change $row=mysql_fetch_array($result,MYSQL_ASSOC); to be
$row=mysql_fetch_row($result,MYSQL_ASSOC);
Then I get all three rows but they are accompanied by a WARNING as

Warning: Wrong parameter count for mysql_fetch_row() in /home/cauli/public_html/malcolm/delete-agentoffice2.php on line 84

Have to say its driving me …..

Help

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogJul 31.2006 — This line...
[code=php]$row=mysql_fetch_array($result,MYSQL_ASSOC);[/code]
...is reading the first row of the result set [i]and moving the pointer to the next row.[/i] Either delete this line if you aren't actually doing anything with it (in your code snippet you don't), or else do this before your loop to reset the pointer to the first row:
[code=php]
mysql_data_seek($result, 0);
[/code]
×

Success!

Help @cauli 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...