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>

 

 

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>

 

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>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.