Jump to content

[SOLVED] Home link from navigation page


zemax

Recommended Posts

I got a code which helps me to create navigational links and only show 4 results per page. Now I want to add a link on each page such that if anyone clicks on that link it takes it to HOME page. I have added

 

<a href="Home.htm"><b><font size="4">Home!!</font></b></a>

 

inside the loop that generates NEXT and PREVIOUS page link but whenever I click on HOME it does nothing at all. Please help.

Link to comment
https://forums.phpfreaks.com/topic/75037-solved-home-link-from-navigation-page/
Share on other sites

Here is the code that I used.

 


<!--ON EACH PAGE I WANT TO HAVE A LINK TO HOME PAGE-->
<head>
<h2>POST</h2>
<a href="Home.htm"><b><font size="4">Home!!</font></b></a>
</head>



<?php


// CODE FOR RETRIEVING RESULTS FROM MYDB AND THEN GENERATING PAGES SO THAT EACH PAGE ONLY DISPLAYS 5 RESULTS PER PAGE.
if(!isset($_GET['page'])){ 
    $page = 1; 
} else { 
    $page = $_GET['page']; 
} 

// Define the number of results per page 
$max_results = 5; 

// Figure out the limit for the query based 
// on the current page number. 
$from = (($page * $max_results) - $max_results);  

// Perform MySQL query on only the current page number's results 

$sql = mysql_query("SELECT * FROM MYDB LIMIT $from, $max_results"); 

while($row = mysql_fetch_array($sql)){ 

echo "<hr>";

   	echo "<b><font color='#660000' size='4'>".$row['NAME']."</font></b>";
echo "<br>\n";
    
    } 

// Figure out the total number of results in MYDB: 
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM MYDB"),0); 

$total_pages = ceil($total_results / $max_results); 

// Build Page Number Hyperlinks 
echo "<hr><center>Select Page<br />"; 

// Build Previous Link 
if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> "; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
    } 
} 

// Build Next Link 
if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>"; 
} 
echo "</center>"; 
?>  




 

Sorry I am a very new programmer. All I want to do is that, from my navigational pages (i.e. I only want to display 4 results per page, so if I have 20 results then I will have 5 pages) I want to have a link to HOME page so that if user clicks on HOME link from any page he goes to HOME page.

<a href="/home.htm">Home</a>

 

The slash before home.htm tells you that you want to go back to the home directory, aka www or public_html

 

Great that fixed my problem. I am sorry for asking/doing very basic mistake. I just started using html/php about 3 days ago. Thanks.

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.