Jump to content

[SOLVED] running index for accesskey, while loop, need help


bradkenyon

Recommended Posts

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>

 

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.