bradkenyon Posted July 29, 2008 Share Posted July 29, 2008 I have this code below that I want to run an index for accesskey, to it goes 1 thru 8, and for each line item, i want it to number the accesskey accordingly, for example. <li accesskey="1">content</li> <li accesskey="1">content</li> so on and so forth... this is the code i have for it, but it just spits out 0 for each accesskey <? include('db.php'); $query = "SELECT * FROM news ORDER BY tstamp DESC LIMIT 8"; $result=mysql_query($query); ?> <ol> <? while($row = mysql_fetch_array($result)) { $i = 0; $t = 1; while($i <=0) { print '<li accesskey="'.$i.'"><a href="/news/?id='.$row['id'].'">'.$row['subj'].'</a></li>'; $i++; $t++; } } ?> </ol> Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 29, 2008 Share Posted July 29, 2008 it spits out 0 for all the access keys because you have set up the variable inside the while loop, so every time the while loop runs it resets $i to equal 0 <? include('db.php'); $query = "SELECT * FROM news ORDER BY tstamp DESC LIMIT 8"; $result=mysql_query($query); ?> <ol> <? $i = 0; while($row = mysql_fetch_array($result)) { print '<li accesskey="'.$i.'"><a href="/news/?id='.$row['id'].'">'.$row['subj'].'</a></li>'; $i++; } ?> </ol> Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted July 29, 2008 Author Share Posted July 29, 2008 thanks for the explanation. how would i set a variable to count up as each line is printed, setting the running tally to each accesskey of each line. so it will be... <li accesskey="1">content</li> <li accesskey="2">content</li> <li accesskey="3">content</li> <li accesskey="4">content</li> <li accesskey="5">content</li> <li accesskey="6">content</li> Quote Link to comment Share on other sites More sharing options...
paul2463 Posted July 29, 2008 Share Posted July 29, 2008 as my edited code above shows set up $i outside the while loop then increment $i every loop through the while loop Quote Link to comment Share on other sites More sharing options...
bradkenyon Posted July 29, 2008 Author Share Posted July 29, 2008 didn't see you removed one of the loops, thanks! Quote Link to comment 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.