homepage Welcome to WebmasterWorld Guest from 54.166.122.65
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Combining While and For Loops
itledi

5+ Year Member



 
Msg#: 3586616 posted 12:06 am on Feb 28, 2008 (gmt 0)

Hello,

I'm trying to output some content from a MySQL table using a while loop:

$query=mysql_query("SELECT * FROM table LIMIT 9");
while($result=mysql_fetch_array($query)) $mobile.="<a href=\"".$result["link"]."\">".$result["title"]."</a>";

Works great.

Now I'm trying to make it so I have an accesskey value that increases with each new link.

$query=mysql_query("SELECT * FROM table LIMIT 9");
while($result=mysql_fetch_array($query)){
$accesskey=1;
$mobile.="<a href=\"".$result["link"]."\" accesskey=\"".$accesskey."\">".$result["title"]."</a>";
$accesskey++;}

No luck.

How can I make it so each new row has a different accesskey?

Thanks

 

jatar_k

WebmasterWorld Administrator jatar_k us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3586616 posted 12:12 am on Feb 28, 2008 (gmt 0)

you have your counter initializing inside your while loop, put it before the loop

$query=mysql_query("SELECT * FROM table LIMIT 9");
$accesskey=1;
while($result=mysql_fetch_array($query)){
$mobile.="<a href=\"".$result["link"]."\" accesskey=\"".$accesskey."\">".$result["title"]."</a>";
$accesskey++;}

should work then

itledi

5+ Year Member



 
Msg#: 3586616 posted 12:19 am on Feb 28, 2008 (gmt 0)

Awesome, it works! Thanks

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved