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
https://forums.phpfreaks.com/topic/17498-help-with-hyperlink/
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
https://forums.phpfreaks.com/topic/17498-help-with-hyperlink/#findComment-74438
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
https://forums.phpfreaks.com/topic/17498-help-with-hyperlink/#findComment-74446
Share on other sites

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.