ScrewLooseSalad Posted March 13, 2013 Share Posted March 13, 2013 (edited) My code seems to output a line short, I can't seem to make it output the first line, I've tried tinkering, but can't seem to get that first line out, can anyone point out what I'm doing wrong? Thanks $queryitem = "SELECT * FROM `delnoteitems` WHERE `deliverNote` LIKE '$DeliverNote';"; $result = $db2->query($queryitem); if(!$result) {echo "Query two of two failed<br>$queryitem"; exit(0);} $num_results = $result->num_rows; $row = $result->fetch_assoc(); $i=0; while ($row = $result->fetch_assoc()) { $i++; $itemDesc[$i] = $row['itemDesc']; $itemQuantity[$i] = $row['itemQuantity']; } $max=$i; Edited March 13, 2013 by ScrewLooseSalad Quote Link to comment https://forums.phpfreaks.com/topic/275595-first-line-not-outputting-when-reading-from-mysql-database/ Share on other sites More sharing options...
yomanny Posted March 13, 2013 Share Posted March 13, 2013 I think I've spotted the problem. You increase $i before populating the arrays, which means $itemDesc[0] and $itemQuantity[0] are empty. So simply try changing your while to this: while ($row = $result->fetch_assoc()) { $itemDesc[$i] = $row['itemDesc']; $itemQuantity[$i] = $row['itemQuantity']; $i++; } Now you'll start populating $itemDesc[0] and go up. - W Quote Link to comment https://forums.phpfreaks.com/topic/275595-first-line-not-outputting-when-reading-from-mysql-database/#findComment-1418348 Share on other sites More sharing options...
ScrewLooseSalad Posted March 13, 2013 Author Share Posted March 13, 2013 I think I've spotted the problem. You increase $i before populating the arrays, which means $itemDesc[0] and $itemQuantity[0] are empty. - W The $i is initiated at '0' and increases first so that $i is only incremented as many times as there are entries, in theory, so that only the amount of entries are printed later, as you can see $i is only used in the variable names that I'll be calling later on in the script. There is a problem here but I don't think this is the solution, I did try it, and two entries went missing, as the second entry disappeared into $i=0, so it wasn't called at the bottom of the script; I've tried calling $itemDesc[$i=0] before but of course nothing was in there, perhaps the problem could be where I call the variable? $i=1; while($i<=$max) { echo "<p align='center'>$itemDesc[$i]</p>"; $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/275595-first-line-not-outputting-when-reading-from-mysql-database/#findComment-1418349 Share on other sites More sharing options...
Solution davidannis Posted March 13, 2013 Solution Share Posted March 13, 2013 line 164 reads line 0, does nothing with it then 166 reads line 1. just kill 164. Quote Link to comment https://forums.phpfreaks.com/topic/275595-first-line-not-outputting-when-reading-from-mysql-database/#findComment-1418372 Share on other sites More sharing options...
ScrewLooseSalad Posted March 13, 2013 Author Share Posted March 13, 2013 line 164 reads line 0, does nothing with it then 166 reads line 1. just kill 164. Thanks! Works perfectly now! Quote Link to comment https://forums.phpfreaks.com/topic/275595-first-line-not-outputting-when-reading-from-mysql-database/#findComment-1418387 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.