Jump to content

hakmir

Members
  • Posts

    35
  • Joined

  • Last visited

    Never

Everything posted by hakmir

  1. Hi Guys, I tried to put pagination code into my search results but every time I get an ugly error. Can you guys help me please?I just want to put 5 results per page. Why does it have to be so complicated. I am just asking something very simple (Well, it shows that you don't know anything about php dude! ( I am just talking to myself)) <a href="search.php">Search</a><br> <br> <?php include("connect.php"); $first_name = "%" . $_POST["first_name"] . "%"; $last_name = "%" . $_POST["last_name"] . "%"; $age = "%" . $_POST["age"] . "%"; $query= "SELECT * FROM `contacts` WHERE `first_name` LIKE '$first_name' AND `last_name` LIKE '$last_name' AND `age` LIKE '$age' ORDER BY `contacts`.`first_name` ASC LIMIT 0, 30 "; $result = mysql_query($query); $num = mysql_num_rows ($result); mysql_close(); if ($num > 0 ) { $i=0; while ($i < $num) { $first_name = mysql_result($result,$i,"first_name"); $last_name = mysql_result($result,$i,"last_name"); $age = mysql_result($result,$i,"age"); $id = mysql_result($result,$i,"id"); echo "<b>first name:</b> $first_name<br>"; echo "<b>last name:</b> $last_name<br>"; echo "<b>age:</b> $age<br>"; echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>"; echo "<br><br>"; ++$i; } } else { echo "No Results"; }?>
  2. Thanks for reply. I wish there were something light. Like an firefox addon. I don't know why they still didn't make an addon like this. Is it so complex? Just put a simple editor in it even if you don't make it colorful.
  3. I am using fireftp and doing the editing in notepad2. It's so cool that when I make any change in notepad it updates on your website too. But what I want is that I want ftp and code editor in same browser (splited). Is there such thing? I made an image about what I want. You'll understand better what I mean. I saw firebug. It is nice but it doesn't edit the file as it is . Like php file. [attachment deleted by admin]
  4. is it possible that one php file will redirect all the requested pages like this: for example when people type these addresses it will first go to redirect.php then depends on what they type after www.yoursite.com, it will redirect those pages. www.yoursite.com/firstpage www.yoursite.com/secondpage www.yoursite.com/thirdpage I know that for every request you can make a separate page but I just want one page to redirect all. Thanks in advance
  5. Hi Guys, php page worked in my localhost with no problem. But when I uploaded to web, it gave me this warning Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home/takasa1/public_html/toupload/immigration.php:7) in /home/takasa1/public_html/toupload/immigration.php on line 38 Should I worry about this? I just put @ in the beginning to hide the message. Is that ok? Thanks in advance
  6. Hi guys, My captcha used to work perfect. But today I checked the sites in my localhost and no captcha image is showing in the forms. I am using wamp server. Do you know why this could happen? I didn't move image folder or other files. I didn't change anything since it was working perfectly .Thanks in advance.
  7. I solved the problem. I used $_POST[...] to take the value to top of the page then from there I used if and if else. Thanks for helping
  8. I thought about it but didn't want to mess things up. I will try that. Thank you. Is there any code that when the page reloads it goes to certain place in the page?
  9. Hi guys, I want to echo this code if(($countryfiled=="please select")||($visatype=="please select")) { $notice="<h3>PLEASE DO NOT LEAVE COUNTRY OR VISA TYPE EMPTY</h3>"; echo "<FONT color='red'>$notice</font>"; } at top of the page. Now it is echoing at the bottom. I don't want it to echo at the bottom of the page. Because visitor may not see it and think that their form is successfully submitted. But I don't know how to echo it on top of the page. Action is SELF. Thanks in advance
  10. I solved the problem. Thanks a lot. short_open_tag = On
  11. That's a good idea. But I have some study materials and almost all of them has <? instead of <?php. I will still use <?php but How can I change the setting so that it will recognize <? too. I checked php.ini file but couldn't do it.
  12. <?php works but <? doesn't work. I don't know why it is behaving that way. I have the latest version of wamp server. can you help? Thanks in advance.
  13. I realized something. First page url is like this: http://localhost/Copy_of_src/reciperesults.php?country=USA&typeoffood=DESERT&Search=Search When I go to second page URL is like this and of course there is nothing on the page http://localhost/Copy%20of%20src/reciperesults.php?pageno=2 Then I started to play with URL and came up with this which is working: http://localhost/Copy%20of%20src/reciperesults.php?pageno=2&country=USA&typeoffood=DESERT&Search=Search Problem is the same, I don't know what or how to do to get this result everytime when I clicked next or try to go to another page. I feel I am so close to result. I can even smell it but Still I can not touch it.
  14. Thanks a lot guys. I really appreciate. genericnumber1, I made the changes you said but problem is still there. I forgot to tell about another problem. I don't know if it causes this problem. It always shows the number of pages of everything in the table not the number of pages that I selected from form. $queryCount = 'SELECT count(*) FROM '.$tablename;
  15. I am exhausted. I've been looking for a dynamic pagination sample for decades(a little exaggerated). There are many pagination tutorials and none of them gives a code if it is dynamic. When I use this code everything works perfect. It gives all the results page by page: $query = "SELECT * FROM $tablename"; But when I use this code (which I want) It just shows first page and other pages are empty. It doesn't carry my request to other pages. $query = "SELECT * FROM $tablename WHERE country='$country' AND typeoffood='$typeoffood'"; A lot of people explains like this : The problem is that your posted vars do not carry over from page to page. They are only passed to the page from the initial form submission. To keep them persisting, you need to either make them session variables or else add them to the links to be passed through the url and retrieved via the GET method (like the other vars). If you are using a lot of posted info I would suggest using sessions, as there is a limit on how long a url string can be. Also, sessions are more secure. The problem is I don't know how to make it. All I am looking is a Sample code (for dynamic pagination) I checked the whole internet and not even one person made an example like this. Everybody is making pagination if you select everything from table and if you want dynamic they just give advice. I even saw a lot of people like me and they couldn't solve their problem either. Does anybody know a sample for dynamic pagination and with those session variables stuff in it? Thanks. By the way here is my full code to get results page by page: reciperesults.php <?php ////////////////////////////////////////// //// MySQL Database Connection /////////// ////////////////////////////////////////// $host = "localhost"; $user = "root"; $db_name= "recipetime"; $pass= ""; $conn = mysql_connect($host, $user, $pass) or die(mysql_error()); mysql_select_db($db_name, $conn) or die(mysql_error()); ///////////////////////////////////////// ////// Prevent Injection Attack ///////// ///////////////////////////////////////// if(isset($_GET['pageno'])) { if(!is_numeric($_GET['pageno'])) { return 'Error: '.$_GET['pageno']; exit(); } $pageno = $_GET['pageno']; } else { $pageno=1; } ///////////////////////////////////////// /////////// PAGES FUNCTION ////////////// ////////////// by Leo /////////////////// /////// www.webdeveloperwannabe.com////// ///////////////////////////////////////// function pages($tablename, $pageno, $perPage, $query) { $output = ''; $queryCount = 'SELECT count(*) FROM '.$tablename; $resultCount = mysql_query($queryCount); $fetch_row = mysql_fetch_row($resultCount); $numrows = $fetch_row[0]; // if there is no results if($numrows == 0) { return 'Query returned 0 results.'; exit(); } $lastpage = ceil($numrows/$perPage); $pageno = (int)$pageno; if($pageno<1) { $pageno=1; } elseif($pageno>$lastpage) { $pageno=$lastpage; } // ----- PAGE LINKS ----- if($pageno==1) { $pages .= 'FIRST | PREVIOUS '; } else { $pages .= "<a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a> | "; $prevpage=$pageno-1; $pages .= " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREVIOUS</a> "; } $pages .= ' ( Page '.$pageno.' of '.$lastpage.' ) '; if($pageno==$lastpage) { $pages .= ' NEXT | LAST '; } else { $nextpage = $pageno+1; $pages .= " <a href='".$_SERVER['PHP_SELF']."?pageno=$nextpage'>NEXT</a> | "; $pages .= " <a href='".$_SERVER['PHP_SELF']."?pageno=$lastpage'>LAST</a>"; } $limit=' LIMIT '.($pageno-1)*$perPage.', '.$perPage; $query = $query.$limit; $result = mysql_query($query); if(!$result) { return 'Query failed: '.mysql_error(); } while($row = mysql_fetch_array($result)) { $output .= $row['name']."<br>".$row['country']."<br>".$row['typeoffood']."<br>".$row['yourrecipe']."<br>"."<br>".'<br />'; } $output .= '<div style="width:100%; text-align:center; font-size:smaller; color:#999;">'.$pages.'</div>'; $output .= 'Total number of products: '.$numrows; return $output; exit(); } ///////////////////////////////////////// ////////// Set paramenters ////////////// ///////////////////////////////////////// $typeoffood = $_POST['typeoffood']; $country = $_POST['country']; $tablename = 'recipeform'; $perPage = 4; $query = "SELECT * FROM $tablename WHERE country='$country' AND typeoffood='$typeoffood'"; echo pages($tablename, $pageno, $perPage, $query); ?> my search form: searchrecipe.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the recipe ' . 'database at this time.</p>'); } ?> <form id="form1" name="form1" method="post" action="reciperesults.php"> <label><strong>SEARCH RECIPE</strong><br /> <br /> </label> <p>Country<br /> <label> <select name="country" id="country"> <option>USA</option> <option>CANADA</option> <option>ENGLAND</option> </select> </label> </p> <p>Type of Food <br /> <label> <select name="typeoffood" id="typeoffood"> <option>DESERT</option> <option>ENTREE</option> <option>SPICY</option> </select> </label> </p> <p> <label> <input type="submit" name="Search" id="Search" value="Search" /> </label> </p> </form> <a href="submitrecipe.php">Submit Recipe</a> </body> </html> and sql -- phpMyAdmin SQL Dump -- version 2.11.6 -- http://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Oct 29, 2008 at 09:44 AM -- Server version: 5.0.51 -- PHP Version: 5.2.6 SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `recipetime` -- -- -------------------------------------------------------- -- -- Table structure for table `recipeform` -- CREATE TABLE `recipeform` ( `name` varchar(255) default NULL, `country` varchar(255) default NULL, `typeoffood` varchar(255) default NULL, `yourrecipe` varchar(1000) default NULL ) ENGINE=InnoDB DEFAULT CHARSET=latin1; -- -- Dumping data for table `recipeform` -- INSERT INTO `recipeform` (`name`, `country`, `typeoffood`, `yourrecipe`) VALUES ('Hakmir', 'USA', 'DESERT', 'Now I will tell you how to make apple pie'), ('Nick', 'CANADA', 'SPICY', 'Now time to make mexican food....'), ('MIra', 'ENGLAND', 'ENTREE', 'I will show you an entree from England'), ('tavik', 'USA', 'DESERT', 'tuvik lu desert usa'), ('tarik', 'USA', 'DESERT', 'tarikdan tatli usa'), ('now', 'USA', 'DESERT', 'iste simdi gidecek'), ('takita', 'USA', 'DESERT', 'check this out usa desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('hokota', 'USA', 'DESERT', 'hokotadan desert'), ('dallama', 'USA', 'DESERT', 'desert from dallama'), ('bude', 'USA', 'DESERT', 'bude'), ('rara', 'USA', 'DESERT', 'rarababa'), ('sat', 'USA', 'DESERT', 'sat'), ('sdfsdf', 'USA', 'DESERT', 'sdfsd'), ('asdssss', 'USA', 'DESERT', 'sssssss'), ('saki', 'USA', 'DESERT', 'saki'), ('sdfdf', 'USA', 'DESERT', 'sdfdf'), ('hey', 'USA', 'DESERT', 'hey'), ('hu', 'USA', 'DESERT', 'hu'), ('hakan2', 'USA', 'DESERT', 'hakan2 lets see if this will work'), ('', 'USA', 'DESERT', ''), ('', 'USA', 'DESERT', ''), ('taka', 'USA', 'DESERT', 'taka\r\n'), ('taka', 'USA', 'DESERT', 'taka\r\n'), ('haki', 'USA', 'DESERT', 'haki'), ('taka', 'USA', 'DESERT', 'taka\r\n'), ('haki', 'USA', 'DESERT', 'haki'), ('soko', 'USA', 'DESERT', 'soko'), ('', 'USA', 'DESERT', ''), ('soko', 'USA', 'DESERT', 'soko'), ('soko', 'USA', 'DESERT', 'soko'), ('soko', 'USA', 'DESERT', 'soko'), ('soko', 'USA', 'DESERT', 'soko'), ('takashi', 'USA', 'DESERT', 'tahashi'), ('saggg', 'USA', 'DESERT', 'saggg'), ('pasha', 'USA', 'DESERT', 'pasha'), ('pasha', 'USA', 'DESERT', 'pasha'), ('pasha', 'USA', 'DESERT', 'pasha'), ('pasha', 'USA', 'DESERT', 'pasha'), ('para', 'USA', 'DESERT', 'para'), ('money', 'USA', 'DESERT', 'money'), ('moneyttt', 'USA', 'DESERT', 'moneyttt'), ('yani', 'USA', 'DESERT', 'yani'), ('', 'USA', 'DESERT', ''), ('', 'USA', 'DESERT', ''), ('', 'USA', 'DESERT', ''), ('', 'USA', 'DESERT', ''), ('', 'USA', 'DESERT', ''), ('This is serious', 'USA', 'DESERT', 'this is serios'), ('hadiya', 'USA', 'DESERT', 'hadiya'), ('This is serious', 'USA', 'DESERT', 'this is serios'), ('hadiya', 'USA', 'DESERT', 'hadiya'), ('fff', 'USA', 'DESERT', 'fff'), ('fffeee', 'USA', 'DESERT', 'fffeee'), ('', 'USA', 'DESERT', ''), ('tttt', 'USA', 'DESERT', 'ttttt'), ('yyy', 'USA', 'DESERT', 'yyy'), ('test', 'USA', 'DESERT', 'test'), ('test', 'USA', 'DESERT', 'test'), ('test1', 'USA', 'DESERT', 'test1'), ('test2', 'USA', 'DESERT', 'test2'), ('test3', 'USA', 'DESERT', 'test3'), ('dfdfdf', 'USA', 'DESERT', 'dfdfdf'), ('gdfd', 'USA', 'DESERT', 'fdfdfd'), ('trtr', 'USA', 'DESERT', 'trtr'), ('yyyy', 'USA', 'DESERT', 'yyyy'), ('rrrr', 'USA', 'DESERT', 'rrrrr'), ('yyyy', 'USA', 'DESERT', 'yyyy'), ('ooooooo', 'USA', 'DESERT', 'oooooooo'), ('pppppppp', 'USA', 'DESERT', 'ppppppppp'), ('qqqqqqqqqq', 'USA', 'DESERT', 'qqqqqqqq'), ('p', 'USA', 'DESERT', 'p'), ('p', 'USA', 'DESERT', 'p'), ('qwqw', 'USA', 'DESERT', 'qwqw'), ('fuku', 'USA', 'DESERT', 'fuku'), ('fuku', 'USA', 'DESERT', 'fuku'), ('saki', 'USA', 'DESERT', 'saki'), ('saki', 'USA', 'DESERT', 'saki'), ('saki', 'USA', 'DESERT', 'saki'), ('saki', 'USA', 'DESERT', 'saki'), ('saki', 'USA', 'DESERT', 'saki'), ('re', 'USA', 'DESERT', 're'), ('yu', 'USA', 'DESERT', 'yu'), ('fdfd', 'USA', 'DESERT', 'dfdfdf'), ('fdfd', 'USA', 'DESERT', 'dfdfdf'), ('yumu', 'USA', 'DESERT', 'yumu'), ('yumu', 'USA', 'DESERT', 'yumu'), ('yumu', 'USA', 'DESERT', 'yumu'), ('fdfd', 'USA', 'DESERT', 'dfdfdf'), ('yumu', 'USA', 'DESERT', 'yumu'), ('89', 'USA', 'DESERT', '89'), ('8999', 'USA', 'DESERT', '89999'), ('8999', 'USA', 'DESERT', '89999'), ('56', 'USA', 'DESERT', '56'), ('erer', 'USA', 'DESERT', 'erer'), ('ty', 'USA', 'DESERT', 'ty'), ('fsdf', 'USA', 'DESERT', 'sdfsdf'), ('fsdf', 'USA', 'DESERT', 'sdfsdf'), ('te', 'USA', 'DESERT', 'te'), ('UI', 'USA', 'DESERT', 'UI'), ('OIOO', 'USA', 'DESERT', 'OIOO'), ('OIOO', 'USA', 'DESERT', 'OIOO'), ('WWW', 'USA', 'DESERT', 'WWW'), ('RERERE', 'USA', 'DESERT', 'RERERE'), ('25', 'USA', 'DESERT', '25'), ('EE', 'USA', 'DESERT', 'EE'), ('98', 'USA', 'DESERT', '565'), ('TEKRAR', 'USA', 'DESERT', 'TEKRAR'), ('fdfdfdfdfdf', 'USA', 'DESERT', 'fdsfsfddfsdfdf'), ('HAKAN', 'USA', 'DESERT', 'HAKAN'), ('den', 'USA', 'DESERT', 'den'), ('SAKINHA', 'USA', 'DESERT', 'SAKINBI KELEKLIK YAPMA BANA'), ('SAKINHA', 'USA', 'DESERT', 'SAKINBI KELEKLIK YAPMA BANA'), ('SAKINHA', 'USA', 'DESERT', 'SAKINBI KELEKLIK YAPMA BANA'), ('SAKINHA', 'USA', 'DESERT', 'SAKINBI KELEKLIK YAPMA BANA'), ('2222', 'USA', 'DESERT', '22222'), ('', 'USA', 'DESERT', '5656'), ('ddR', 'USA', 'DESERT', 'ddR'), ('ddRF', 'USA', 'DESERT', 'ddRF'), ('ddRF', 'ENGLAND', 'SPICY', 'ddRF');
  16. THanks for the advice guys. I appreciate it. But I am new to programming. I guess I will have to try what I know already.
  17. Hi everybody, I have submitform.php with captcha. It works fine but when the person who is filling the form enters wrong code in captcha are the webpage tells him that code was incorrect so go back to form page. But when he goes back all the things he filled are gone. How can I fix this problem. At least for "yourrecipe" area. Here is the code <?php /** * Project: Securimage: A PHP class for creating and managing form CAPTCHA images<br /> * File: form.php<br /><br /> * * This is a very simple form sending a username and password.<br /> * It demonstrates how you can integrate the image script into your code.<br /> * By creating a new instance of the class and passing the user entered code as the only parameter, you can then immediately call $obj->checkCode() which will return true if the code is correct, or false otherwise.<br /> * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version.<br /><br /> * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details.<br /><br /> * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA<br /><br /> * * Any modifications to the library should be indicated clearly in the source code * to inform users that the changes are not a part of the original software.<br /><br /> * * If you found this script useful, please take a quick moment to rate it.<br /> * http://www.hotscripts.com/rate/49400.html Thanks. * * @link http://www.phpcaptcha.org Securimage PHP CAPTCHA * @link http://www.phpcaptcha.org/latest.zip Download Latest Version * @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation * @copyright 2007 Drew Phillips * @author drew010 <drew@drew-phillips.com> * @version 1.0.3.1 (March 23, 2008) * @package Securimage * */ session_start(); ?> <html> <head> <title>Submit recipe form</title> </head> <body> <?php $dbcnx = @mysql_connect('localhost', 'root', ''); if (!$dbcnx) { exit('<p>Unable to connect to the ' . 'database server at this time.</p>'); } if (!@mysql_select_db('recipetime')) { exit('<p>Unable to locate the experience ' . 'database at this time.</p>'); } ?> <?php if (empty($_POST)) { ?> <form id="form1" name="form1" method="post" action="submitrecipe.php"> <label><strong>SUBMIT YOUR RECIPE</strong><br /> <br /> Name<br /> <input type="text" name="yourname" id="yourname" /> </label> <p>Country<br /> <label> <select name="yourcountry" id="yourcountry"> <option>USA</option> <option>CANADA</option> <option>ENGLAND</option> </select> </label> </p> <p>Type of Food <br /> <label> <select name="typeoffood" id="typeoffood"> <option>DESERT</option> <option>ENTREE</option> <option>SPICY</option> </select> </label> </p> <p>Your recipe<br /> <label> <textarea name="yourrecipe" id="yourrecipe" cols="45" rows="5"></textarea> </label> </p> <p> <label> <!-- pass a session id to the query string of the script to prevent ie caching --> <img src="securimage_show.php?sid=<?php echo md5(uniqid(time())); ?>"><br /> <input type="text" name="code" /><br /> <input type="submit" value="Submit Form" /> </form> <?php } else { //form is posted include("securimage.php"); $img = new Securimage(); $valid = $img->check($_POST['code']); if($valid == true) { echo "<center>Thanks, you entered the correct code.</center>"; } else { echo "<center>Sorry, the code you entered was invalid. <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>"; } } ?> <?php if (isset($_POST['yourrecipe'])&&($valid==true)): // A new recipe has been entered // using the form. $yourname = $_POST['yourname']; $yourcountry = $_POST['yourcountry']; $typeoffood = $_POST['typeoffood']; $yourrecipe = $_POST['yourrecipe']; $sql = "INSERT INTO recipeform SET name='$yourname', country='$yourcountry', typeoffood = '$typeoffood', yourrecipe='$yourrecipe'"; if (@mysql_query($sql)) { echo '<p>New recipe added</p>'; echo "<a href=\"searchrecipe.php\">Search Recipe</a></center>"; } else { exit('<p>Error adding new recipe: ' . mysql_error() . '</p>'); } ?> <?php endif; ?> </body> </html>
  18. sorry I wanted to say: I am new to php guys. I WISH I could understand or know how to do what you are saying. I am a copy and paste guy.
  19. I am new to php guys. I could understand or know how to do what you are saying. I am a copy and paste guy.
  20. I think When it updates the page (2. or later pages) it doesn't get the POST values (id=typeoffood and id=country) from searchrecipe.php file. But I don't know how to fix.
  21. I saw somebody (biciodark )has the same problem too at http://www.phpfreaks.com/tutorial/basic-pagination#comment-172 can you help?
  22. I checked the tutorial. It is working well (almost) When I use this code there is no problem. It shows everything in my database page by page. $sql = "SELECT * FROM recipeform LIMIT $offset, $rowsperpage "; But when I use this code (which I want to use) It shows first page with no problem. But when I click on page 2, 3, or other pages there is no data showing then when I click page 1 again it doesn't show anything either.. $sql = "SELECT * FROM recipeform WHERE typeoffood='$typeoffood' and country='$country' LIMIT $offset, $rowsperpage "; ? This is what I came up with <?php // database connection info $conn = mysql_connect('localhost','root','') or trigger_error("SQL", E_USER_ERROR); $db = mysql_select_db('recipetime',$conn) or trigger_error("SQL", E_USER_ERROR); // find out how many rows are in the table $sql = "SELECT COUNT(*) FROM recipeform"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $r = mysql_fetch_row($result); $numrows = $r[0]; // number of rows to show per page $rowsperpage = 3; // find out total pages $totalpages = ceil($numrows / $rowsperpage); // get the current page or set a default if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) { // cast var as int $currentpage = (int) $_GET['currentpage']; } else { // default page num $currentpage = 1; } // end if // if current page is greater than total pages... if ($currentpage > $totalpages) { // set current page to last page $currentpage = $totalpages; } // end if // if current page is less than first page... if ($currentpage < 1) { // set current page to first page $currentpage = 1; } // end if // the offset of the list, based on current page $offset = ($currentpage - 1) * $rowsperpage; // get the info from the db $typeoffood = $_POST['typeoffood']; $country = $_POST['country']; $sql = "SELECT * FROM recipeform WHERE typeoffood='$typeoffood' and country='$country' LIMIT $offset, $rowsperpage "; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); // while there are rows to be fetched... while ($list = mysql_fetch_assoc($result)) { $recname = htmlspecialchars($list['name']); $reccountry = htmlspecialchars($list['country']); $rectypeoffood = htmlspecialchars($list['typeoffood']); $recyourrecipe = htmlspecialchars($list['yourrecipe']); // echo data echo "Name: <td>$recname</td>" . "<br>"; echo "Country: <td>$reccountry</td>" . "<br>"; echo "Typeoffood: <td>$rectypeoffood</td>" . "<br>"; echo "Your Recipe: <td>$recyourrecipe</td>" . "<br>" . "<br>"; } // end while /****** build the pagination links ******/ // range of num links to show $range = 3; // if not on page 1, don't show back links if ($currentpage > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> "; // get previous page num $prevpage = $currentpage - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> "; } // end if // loop to show links to range of pages around current page for ($x = (($currentpage - $range) - 1); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [<b>$x</b>] "; // if not current page... } else { // make it a link echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> "; } // end else } // end if } // end for // if not on last page, show forward and last page links if ($currentpage != $totalpages) { // get next page $nextpage = $currentpage + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> "; } // end if /****** end build pagination links ******/ ?>
×
×
  • 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.