jarv Posted June 6, 2013 Share Posted June 6, 2013 hi, I would like to display a number next to each of my books ie: Book Title 1: Mr. TickleBook Title 2: Mr. GreedyBook Title 3: Mr. Topsy-TurvyBook Title 4: Little Miss BossyBook Title 5: Mr. Uppity but instead (as they are being output as an array) I get: Book Title 0: Mr. TickleBook Title 1: Mr. GreedyBook Title 2: Mr. Topsy-TurvyBook Title 3: Little Miss BossyBook Title 4: Mr. Uppity here is my code $pagecount=0; $qry="SELECT BookID,BookTitle,BookInfo FROM mrmen"; $cur=mysql_query($qry); if(!$cur){ echo $cur.'<br />'.mysql_error(); } while($i=mysql_fetch_row($cur)) {$BookID[$pagecount]=$i[0]; $BookTitle[$pagecount]=$i[1]; $BookInfo[$pagecount]=$i[2]; $pagecount++; } for ($i=0;$i<$pagecount;$i++){ echo 'Book Title '.$i.': '.$BookTitle[$i].'<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/ Share on other sites More sharing options...
davidannis Posted June 6, 2013 Share Posted June 6, 2013 (edited) change echo 'Book Title '.$i.': '.$BookTitle[$i].'<br />'; to echo 'Book Title '.($i+1).': '.$BookTitle[$i].'<br />'; Edited June 6, 2013 by davidannis Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/#findComment-1434447 Share on other sites More sharing options...
jarv Posted June 6, 2013 Author Share Posted June 6, 2013 I have tried this and I get: [06-Jun-2013 15:39:58] PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in /Applications/MAMP/htdocs/mrmen/index.php on line 11 Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/#findComment-1434449 Share on other sites More sharing options...
Zane Posted June 6, 2013 Share Posted June 6, 2013 use $i++ instead of $i+1 Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/#findComment-1434453 Share on other sites More sharing options...
jarv Posted June 6, 2013 Author Share Posted June 6, 2013 I have tried this and it just displays 0, 2, 4 Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/#findComment-1434456 Share on other sites More sharing options...
TOA Posted June 6, 2013 Share Posted June 6, 2013 for ($i=0;$i<$pagecount;$i++){ $n = $i+1; echo 'Book Title '.$n.': '.$BookTitle[$i].'<br />'; } Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/#findComment-1434457 Share on other sites More sharing options...
davidannis Posted June 6, 2013 Share Posted June 6, 2013 jarv, you need the parentheses around ($i+1). I edited the post but not before you saw it. or TOA's solution will work. Quote Link to comment https://forums.phpfreaks.com/topic/278845-counting-records/#findComment-1434462 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.