Jump to content

Help with <LI> hyperlink


AdRock

Recommended Posts

Can someone please help get this linking right?
I have the 5 latest news articles listed so the last entry is the first listed and is displayed on the first page.
I need to change the link so instead of using the article id it uses the the list item number (1-5) so if the user clicks on the 1st article it goes to page 1 etc

Is it possible to use a for loop add increment the link page by 1 each time and if so how?

If you check out my site you'll see what I mean under latest news

[url=http://www.project-sw.co.uk/jack]http://www.project-sw.co.uk/jack[/url]

[code]include_once("includes/connection.php");
$q = mysql_query("SELECT id, title FROM news ORDER BY id DESC LIMIT 5");
echo "<OL id=\"blah\">";
while($articles = mysql_fetch_object($q)) {
    echo "<LI><a class=\"one\" href=\"http://www.project-sw.co.uk/jack/index.php?page=news&limit=1&pagenum=".$articles->id."\">".$articles->title."</a></LI>";
} [/code]
Link to comment
Share on other sites

It will be much more friendly for your users to click a string of words than to click a single digit.  The numbers in an ordered list are not accessible in the way you want.  If you really want to have numbers, then drop the ordered list concept and simply modify your output code to echo a link to a counter that starts at 1 and increments in your output loop.
Link to comment
Share on other sites

I've done it.

You gave me an idea about using a counter.  I just changed the code to this

[code]$counter = 1;
$q = mysql_query("SELECT id, title FROM news ORDER BY id DESC LIMIT 5");
echo "<OL id=\"blah\">";
while($articles = mysql_fetch_object($q)) {
    echo "<LI><a class=\"one\" href=\"http://www.project-sw.co.uk/jack/index.php?page=news&limit=1&pagenum=".$counter."\">".$articles->title."</a></LI>";
$counter = $counter + 1;
} [/code] echo"</OL>";
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.