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
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>"; 
?>  




Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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

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.