zemax Posted October 27, 2007 Share Posted October 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted October 27, 2007 Share Posted October 27, 2007 I guess we need to see more code and a more precise explanation of what's not happening. Quote Link to comment Share on other sites More sharing options...
zemax Posted October 27, 2007 Author Share Posted October 27, 2007 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>"; ?> Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted October 27, 2007 Share Posted October 27, 2007 Why do you have the anchor within the <head> tag? Quote Link to comment Share on other sites More sharing options...
zemax Posted October 27, 2007 Author Share Posted October 27, 2007 Even if I remove head tags it still does not work from navigational pages. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted October 27, 2007 Share Posted October 27, 2007 This is very confusing... what do you wanna do? <a href="home.htm">Home</a> placed between the body tags will link to www.yourdomain.com/home.htm (<document_root>/home.htm) and almost can not work. Quote Link to comment Share on other sites More sharing options...
marcus Posted October 27, 2007 Share Posted October 27, 2007 <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 Quote Link to comment Share on other sites More sharing options...
zemax Posted October 27, 2007 Author Share Posted October 27, 2007 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. Quote Link to comment Share on other sites More sharing options...
zemax Posted October 27, 2007 Author Share Posted October 27, 2007 <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. Quote Link to comment Share on other sites More sharing options...
marcus Posted October 27, 2007 Share Posted October 27, 2007 No problem. Mark as solved. Quote Link to comment Share on other sites More sharing options...
Wuhtzu Posted October 27, 2007 Share Posted October 27, 2007 Wasn't easy guessing he/you weren't in the home directory already But good it got solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.