PHP - Php Url For More Results Per Page?
Hi I dont know anything about html nevermind php.. but spent the past several hours searching on the internet and couldnt find anything so last ditch thought i'd post here. Looked for php help in google and this phpfreaks seemed the most popular site.
ok here's what i'm trying to do. Browsing around the facebook trying to view fans. I dont like the little pop-up window it does because cant see mutual friends.. so i'll right click fans to a new window. Then you can see if anyone's got mutual friends. Only has 10 results per page though.. and when you click the arrow for next page, it stops at 2000. If you click next after 2000 it only has a link to the same page. Figured though to get past that if you manually type in the next number in the url where it says &start=2000. So then at the end of the url i'll change the 2000 to 2010 hit enter.. 2020 hit enter, etc. Its getting kind of tiresome because this fan page i'm checking out for the city has 12,000.. and doing it 10 at a time is ridiculous. Thought there might be a &= thing i could type in the http url to show more profiles per page instead of 10. You know, like some pages have options to show more results per page.. well i looked around checking what the url says for sites that have that option, but it seems like its different for each page they make. You'd think there'd be a standard ?= thing for however many profiles per page. I thought of maybe opening a saved facebook fan results page and opening it with an html editor and looking for 10 to see what text it writes in there showing what code it is that determines the 10 per page.. but theres nothing. Probably cant get it to show more than 10 profiles per page. Anyways, just last-ditch posting maybe you guys would know more about that. Probably cant do anything about it and i'll have to manually type in each ten increment ten thousand times and hit enter. Similar Tutorialsi have done this code but i want to limit to 10 records per page, i cant get the start from and limint number on page correct, it only echos out the links, 1 and 2 i have 18 data inputs in my data base so that bit is corrent by its not echoing the data out please help i think the problem is im my query but cant put my finger on it <?php include 'connect.inc'; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 10; $result = mysql_query ("SELECT * FROM images ODER BY date ASC $start_from,10"); $num_rows = mysql_num_rows($result); echo $num_rows; ?> <table> <?php while ($row = mysql_fetch_assoc($result)) { ?> <tr> <td><? echo $row['title']; ?></td> <td><? echo $row['description']; ?></td> </tr> <?php }; ?> </table> <?php $rs = mysql_query("SELECT COUNT(id) FROM images"); $row = mysql_fetch_row($rs); $totalrecords = $row[0]; $totalpages = ceil($totalrecords / 10); for ($i=1; $i<=$totalpages; $i++) { echo "<a href='hello.php?page=".$i."'>".$i."</a> "; }; ?> thanks matt I have a simple form which sends results (using php) to my email. It works fine. I want to make a similar form, and send the results not to email but to another web page, showing a summary of the form results, so user can check if all is entered correctly before continuing. Can anyone advise if this is possible and how. I am a real php beginner ... Hi, I was just wondering if it were possible (and if so how) to open a page in a new window when submitting a form via php? E.g. I have a poll on my website that is directed to the reults page by $insertGoTo = "results.php";. This all works but what I want to happen is for when the user clicks submit that the results page displays in a new window (or at the very least a new tab), similar to what would happen when you put a target=_blank on a html link. Any help would be very appreciated. Thanks. I know the php is basic and not completed yet, but I am working on that. My next step I want the result to show on index.php when a form is submitted to calculator2.php. I just cant seem to get it. Please help! index.php Code: [Select] <div class="post"> <h2 class="title">Calculator</h2> <hr /> <form method="post" action="calculator2.php"> Fireplace Front Width: <input type="text" name="fw"> <br /> Fireplace Back Width: <input type="text" name="bw"> <br /> Fireplace Depth: <input type="text" name="fd"> <br /> <input type="submit" name="Submit" value="Submit"> </form> Pounds Of Glass Needed: <?php echo $res1; ?> </div> calculator2.php Code: [Select] <?php $frontwidth = $_POST['fw']; $backwidth = $_POST['bw']; $firedepth = $_POST['fd']; $x = $frontwidth + $backwidth+ $firedepth; $y = ($x / 3) * .6667; $res1 = $y *2; echo $res1; ?> Hello all. I'm using this code to go through the database and output certain user-defined numbers Code: [Select] <?php mysql_connect ("pdb1.awardspace.com", "anastasov_db","moscow1945") or die (mysql_error()); mysql_select_db ("anastasov_db"); $term = $_POST['term']; $sql = mysql_query("select * FROM countries WHERE cocode = '$term'"); while ($row = mysql_fetch_array($sql)){ echo '<br/> Code: '.$row['cocode']; echo '<br/> Country: '.$row['coname']; echo '<br/><br/>'; } ?> Now how would I go about making a page that appears if the script can't find any results in the database? Thank you in advance Hello. I am having a hard time building my own search results page for my mysql database. Basically I am trying to search for game categories from the fldCategory field in the table, and display 15 results at a time in an HTML table with the Image of the games (fldIconMedium), and the titles of the games (fldTitle) placed in to the table. Also, at the bottom of the table would have a number bar that you can click on numbers to go to the next set of search results in the same page. The number bar would have Previous and Next button. For the code I am using, I had help from another expert. I thank him, but here is the code I have so far. =========================== =========================== <?php $cat=1; $nor=15; $a=1; if(isset($_GET['cat'])) { } else { $_GET['cat']=1; } echo $_GET['cat']; $con=mysql_connect("host","nusername","password") or die ("error"); $db=mysql_select_db("database",$con) or die("Database not found!"); $result=mysql_query("SELECT * FROM games") or die ("query error"); echo "<table border='1'><tr><th>ImageIcon</th><th>Title</th></tr>"; $r=mysql_num_rows($result); echo $r."<br/>"; $p=ceil($r/$nor); //echo $p; while($rows=mysql_fetch_array($result)) { if($a>($_GET['cat']-1)*$nor) { echo "<tr><td>".$rows['fldIconMedium']."</td><td>".$rows['fldTitle']."</td></tr>"; } $a=$a+1; } echo "</table>"; for($i=1;$i<=$p;$i++) { if($i==$_GET['cat']) { echo $i; } else { echo "<a href='gameslist.php?cat=".$i."'>".$i."</a>"; } } ?> =========================== =========================== To see this code in action, heres the link http://netroxy.com/gameslist.php?cat=skills. > Not working well. I am expecting the games search results page to look like this: http://netroxy.com/51274581336/search.htm So basically its: - viewing how many games found for game category, ex: Skills. Or Action, Mind, etc.. - the URL containing 'gameslist.php?cat=' with the given ID category at the end should search for that given category and display at least 15 games per results, along the number bar bellow, which counts how many are found from that category, which automatically increases or decreases the number bar bellow depending how many games from that specific category was found. I also forgot to mention that I did not add the Previous and Next button, which i dont know how - As for the 15 results per page, its basically 15 images (fldIconMedium) of different games of the same category, with their Titles (fldTitle) underneath them and both image and title should have the LINK to that specific game by retrieving the links from the 'fldLink' column where all the links of the games are found. Thanks all! Hi again PhpFreaks, yet again I got a problem regarding coding. Hi I'm new to the site... and new to PHP, so excuse me if my verbiage isn't quite right. I've been struggling to find a solution to paging through my search results. MY code works for the first five entries that are found via the mysql query but when I click next five results, the code breaks down and sends me back to my index. I believe the problem is he print " <a href=\"$PHP_SELF?s=$news&poster=$var\">Next 5 >></a>  "; I don't know how to rewrite, to display results based on the number of pages found. Ideally the user should be able to query the db and then page through the results. my entire code: Code: [Select] <?php // Get the search variable from URL $var = @$_GET['poster']; $trimmed = trim($var);//trim whitespace from stored variable // rows to return $limit=5; // check for empty string and display a message. if ($trimmed == "") { echo "<p>Please enter a search...</p>"; } else { // check for a search parameter if (!isset($var)) { echo "<p>We dont seem to have a search parameter!</p>"; exit; } //connect to your database $con = mysql_connect("localhost", "test", "test") or die('Sorry, could not connect to server'); mysql_select_db("recipe", $con) or die('Sorry, could not connect to database'); //Build SQL Query $query = "Select date, poster, title, article FROM bulletin WHERE poster LIKE \"%$trimmed%\" order by articleid desc"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); if ($numrows == 0) { echo "<h4>Results</h4>"; echo "<p>Sorry, your search: "" . $trimmed . "" returned zero results</p>"; } else // next determine if s has been passed to script, if not use 0 if (empty($s)) { $s=0; } // get results $query .= " limit $s,$limit"; $result = mysql_query($query) or die("Couldn't execute query"); // display what the person searched for echo "<p>You searched for: "" . $var . ""</p>"; // begin to show results set echo "Results"; echo "<hr>"; $count = 1 + $s ; // now you can display the results returned while ($row= mysql_fetch_array($result)) { $date = $row['date']; $poster = $row['poster']; $title = $row['title']; $article = $row['article']; echo "$date"; echo "<br>\n"; echo "<img src='images/marker.png'><font color=\"white\">$poster</font><br><br>\n"; echo "$title"; echo "<br />"; echo "<br />"; echo "<font color=\"white\">$article</font>\n"; echo "<br>\n"; echo "<hr>"; echo "<br>\n"; } $currPage = (($s/$limit) + 1); //break before paging echo "<br />"; // next we need to do the links to other results if ($s>=1) { // bypass PREV link if s is 0 $prevs=($s-$limit); print " <a href=\"$PHP_SELF?s=$prevs&q=$var\"><< Prev 5</a>  "; } // calculate number of pages needing links $pages=intval($numrows/$limit); // $pages now contains int of pages needed unless there is a remainder from division if ($numrows%$limit) { // has remainder so add one page $pages++; } // check to see if last page if (!((($s+$limit)/$limit)==$pages) && $pages!=1) { // not last page so give NEXT link $news=$s+$limit; print " <a href=\"$PHP_SELF?s=$news&poster=$var\">Next 5 >></a>  "; } $a = $s + ($limit) ; if ($a > $numrows) { $a = $numrows ; } $b = $s + 1 ; echo "<br />"; echo "<br />"; echo "<p>Showing results $b to $a of $numrows</p>"; } ?> If someone could help I would be so great full! Thanks in advance... Mod edit: [code] . . . [/code] BBCode tags added. Code: [Select] The form below is meant to retrieve the named attribute of a form input called "limitedtextfield" , along side the current date and store those values in a database. The form contains some javascript which can be disregarded for this particular problem. [code] <form name="mymind" style= "position:relative;left:40px;" action="insert_status.php" method="post"> <input name="limitedtextfield" type="text" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,55);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,55);" maxlength="55"><br> <font size="1">(Maximum characters: 55)<br> You have <input readonly type="text" name="countdown" size="3" value="55"> characters left.</font> <input type="hidden" name="submitted" value="TRUE"/> <input style="position:relative;left:0px;bottom:0px;" type="submit" name="submit" value="Submit!" /> </form> Here is the php script that processes the form. What it is meant to do is search the database and if no record is found for the authenticated member, input the relevant values into the database. If a record is found, it should update the record. Well every time I hit the submit button, all I get is a blank page. Any clue as to what is going wrong? PS: I checked the database and no values got inserted. Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //Connect to database require ('config.php'); if (isset($_POST['submitted'])) { $query = "SELECT* FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if ($num> 0) { $update = mysql_query("UPDATE publications SET publication = '{$_POST['limitedtextfield']}' WHERE member_id = '".$_SESSION['id']."' AND cartegory = 'status'"); header("Location: member.php"); } else { $query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )"; header("Location: member.php"); } } ?> I would like to modify my php script where my PDF search results would not only display the company name, the country, but also display a limit number link by pages so that not all of the results are shown. I also want the first word searched to go to the first occurrence of the word on the PDF document. What would be the best way to do this? Here is my code: <html> <head></head> <body> <?php if (!isset($_POST['q'])) { ?> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search</h2> <form method="post" action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>"> <input type="text" name="q" size="30" /> </form> <?php } else { ?> <img src="/wvb-logo-slogen.png" border="0" /> <h2>Search Results</h2> <?php try { // create object // $swish = new Swish('/usr/local/apache/htdocs/swish/index.swish-e'); $swish = new Swish('/var/www/html/pdf2/index.swish-e'); // get and run query from command-line $queryStr = htmlentities($_POST['q']); $result = $swish->query($queryStr); ?> Found <?php echo $result->hits; ?> match(es) for '<?php echo $queryStr; ?>'. <?php // iterate over result set // print details for each match while($r = $result->nextResult()) { ?> <p> <?php echo $r->swishreccount; ?> <strong> <a href="<?php echo '/pdf2', ltrim($r->swishdocpath, '.') ; ?>"> <?php echo $r->swishdocpath; ?> </a> </strong> (sco <?php echo $r->swishrank; ?>) <br/> <?php echo $r->swishdocpath; ?> </p> <?php } } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } } ?> </body> </html> Any assistance would be greatly appreciated. Edited by mac_gyver, 15 May 2014 - 08:17 AM. code tags please Hi all, I need your help as I have got a problem with display the 50 rows in the search results. I want to limit 50 rows in per page and if I have less than 50 rows like 21 rows in the page 2 then display the 21 rows. I have got a problem with the limit, because when I tried to use `LIMIT 0, 50`, it will display total 71 rows which I only want to display no more than 50 in per page. Here is what I have tried: $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT 0, 50"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]);
$search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT $offset, $limit"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]);
Here is the full code:
<?php // Initialize the session session_start(); //Connect to the database require_once('config.php'); $searchemail = '%' . 'gmail.com' . '%'; $searchsubject = '%' . 'gmail.com' . '%'; $searchmessage = '%' . 'gmail.com' . '%'; $mailbox = $link->prepare("SHOW TABLES"); $mailbox->execute(); $folders = array(); $total = 0; $total_rows = 0; $i = 0; while ($folder = $mailbox->fetch(PDO::FETCH_NUM)) { $folder = $folder[0]; if (strpos($folder, 'users') !== false) { $folder = str_replace('users', '', $folder); } else { $folders[$i] = $folder; } $i++; } foreach($folders as $folder) { $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT 0, 50"); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); if ($search_mailbox->rowCount() > 0) { $total += $search_mailbox->rowCount(); } } $page = 1; $limit = 50; //$per_page = 50; //$pages = ceil($total / $per_page); $offset = ($page - 1) * $limit; foreach($folders as $folder) { $search_mailbox = $link->prepare("SELECT * FROM $folder WHERE from_email LIKE ? OR subject LIKE ? OR message LIKE ? ORDER BY received_date DESC LIMIT $offset, $limit); $search_mailbox->execute([$searchemail, $searchsubject, $searchmessage]); if ($search_mailbox->rowCount() > 0) { foreach($search_mailbox->fetchAll() as $k => $row) { $email_number = $row['id']; $search_from = $row['from_email']; $search_subject = $row['subject']; $total_rows++; echo $search_subject . '.........................' . $total_rows; echo "<br>"; } } } ?> I am unable to fetch the first 50 rows in the page 1 and I am also unable to fetch the 21 rows in the page 2. What I am trying to achieve is when I am in page 1, I want to display the first 50 rows, then in the page 2 if I have another 50 rows then display the 50 rows, but if I have less than 50 rows like 21 rows then display the 21 rows. Can you please show me an example how I can start with first 50 rows when I am in the page 1 then in page 2 display 21 rows to make in total 71 rows? Any advice would be much appreicated. Thanks in advance. i have built pages that paginate with 10 rows per page (some pages show more but for the moment i want to focus on this particular page)
//Define Some Options for Pagination $num_rec_per_page=10; if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * $num_rec_per_page; $results = mysql_query("SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name) LIMIT $start_from, $num_rec_per_page") or die(mysql_error()); $results_array = array(); while ($row = mysql_fetch_array($results)) { $results_array[$row['characterID']] = $row; }The above sets the variables for the pagination and below the results are echo with 10 rows per page then i show the pagination links: <?php $sql = "SELECT * FROM `ecmt_memberlist` WHERE toonCategory='Capital' AND oldMember = 0 ORDER BY CONCAT(MainToon, Name)"; $rs_result = mysql_query($sql); //run the query $total_records = mysql_num_rows($rs_result); //count number of records $total_pages = ceil($total_records / $num_rec_per_page); ?> <table width="100%" border="0" cellspacing="0" cellpadding="0"> <tr> <td align="center"><div style="width:100%; text-align:center;"> <ul class="pagination"> <li class="selected"> <?php echo "<a href='capitalmember.php?page=1'>".'«'."</a> ";?> </li> <? for ($i=1; $i<=$total_pages; $i++) { echo "<li><a href='capitalmember.php?page=".$i."'>".$i."</a></li> "; }; ?> <li class="selected"> <? echo "<a href='capitalmember.php?page=$total_pages'>".'»'."</a> "; // Goto last page ?></li> </ul></div> <?php $pageNr = $page; // Get Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 echo $pageNr; /* Result: From page 30 to 40 */ ?></td> </tr> </table>this works great and shows me 10 results per page, what i need to work out and work on next is: echo the number of results above the records (for example: "showing records 1 to 10" and then on page 2 "showing records 11 to 21" and page 3 "showing records 22 to 32" how can i work out the maths for this echo? i was thinking along the lines of; <?php $pageNr = $page; // Gets Current Page Number $from = $pageNr * $rowsPerPage; // 3 * 10 = 30 $to = $from + $rowsPerPage; // 30 + 10 = 40 // Now Show Results echo $from; // Echo from echo $to // Echo to ?>but i'm still working on this.. then i need to look at shortening the amount of page links on the page if for example i have 500 records it shows me links 1 to 50 and eats up the page.... Appreciate any help and light onto my problems. Many thanks Edited by jacko_162, 11 January 2015 - 05:43 PM. I have a search page and everything works fine but I would like to add the latest 10 rows to the page so there is something to look at or click on before the user searches. The page is at: www.giantstridedives.com/locations. You can see that it's pretty boring. Hit submit and you'll see the entries so far (only 3 right now). I'd like to have the latest 10 display there by default but then when a user searches they are replaced by the search results. Make sense? Here's the code I'm using for the search: Code: [Select] <?php if (isset($_POST['submit'])) { require_once('dbconnection.php'); mysqli_select_db($conn, $dbname); $searchterm = $_POST['search']; $searchterm = strip_tags($searchterm); $searchterm = trim ($searchterm); $q ="SELECT * FROM locations WHERE loc_name LIKE '%" . $searchterm . "%' AND loc_approved != '0'"; $r = mysqli_query($conn, $q) or die(mysql_error($q)); $row = mysqli_fetch_assoc($r); $rowcount = mysqli_num_rows($r); } ?> <h1>Search for Scuba Dive Locations</h1> <form id="searchform" name="searchform" method="post" action="index.php"> <input type="text" name="search" id="search_bar" /> <input type="submit" name="submit" id="submit" value="Submit" /> </form> <span style="color: #333;">Search for the name of the location, ie: Devils Den or USS Oriskany.</span><br /> <?php if (isset($_POST['submit'])) { if ($rowcount == 0) { echo "Sorry, but we can not find an entry to match your query: <strong>$searchterm</strong>"; } else { //this tells the table below to display since $totalRows_Products_res is not 0 ?> <table style="font-size: 14px;" border="0" width="650"> <tr> <td colspan="6"><p>You searched for <strong><?php echo $searchterm; ?></strong>. Results are displayed below.</p></td> </tr> <tr> <td><strong>Location Name</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Depth (ft)</strong></td> <td><strong>Fees</strong></td> <td><strong>Gear Rentals</strong></td> <td><strong>Map</strong></td> </tr> <?php do { ?> <tr> <td><a href="loc_details.php?loc_id=<?php echo $row ['loc_id']; ?>"> <?php echo $row ['loc_name']; ?> </a></td> <td><?php echo $row ['loc_city']; ?></td> <td><?php echo $row ['loc_state']; ?></td> <td><?php echo $row ['loc_depth']; ?></td> <td>$<?php echo $row ['loc_fee']; ?></td> <td><?php if($row['loc_gear'] == 1) { echo 'Yes'; } else { echo 'No'; } ?></td> <td><a href="http://maps.google.com/maps?q=<?php echo $row ['loc_lat'];?>,<?php echo $row ['loc_lon'];?>" target="_blank">View Map</a></td> </tr> <?php } while ($row = mysqli_fetch_assoc($r)); ?> </table> <?php mysqli_free_result($r); } // this closes out results else } ?> I figure I can use the below query to get the results. Code: [Select] select * from table WHERE id > ((SELECT MAX(id) from table) - 10);I'm just not sure how I can display them by default and then have them be replaced by the search results. Anyone have any ideas for me? As always I appreciate the help as I continue to learn this beast. I'll walk you first through what is working: <?php echo($user['biz_site'] != '' ? "<h4>Web Site</h4>" . $user['biz_site'] : ""); ?> In a results page, the code renders something that looks like: Quote Web Site http://www.somecoolsite.com What I'd like instead is something like this: Quote Web Site Visit Site ...where the "visit site" links to the site. I'm trying to address a problem of some sites, especially government sites, having 75+ character-long addresses, which messes up the finite space I have allotted for site addresses. Everything I've tried thus far has rendered blank white pages. (the original code posted up top does not produce a hyperlink) Hi, I am stuck. I have used dreamweaver to create a master details page with links to the details page successfully, but I would like to display the master details page results in 3 columns rather than the 1 column that dreamweaver defaults. As the site becomes richer the content will increase yielding many results, therfore the content displayed in a single column will require the users to scroll way down the page. So, as it is now the results display as follows: Plant1 Plant2 Plant3 Plant4 Plant5 Plant6 Plant7 Plant8 Plant9 etc... I would like them to display as follows: Plant1 Plant4 Plant7 Plant2 Plant5 Plant8 Plant3 Plant6 Plant9 Here is my code thus far: <?php require_once('Connections/connGND.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; } $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } mysql_select_db($database_connGND, $connGND); $query_rsBotanicalA = "SELECT * FROM plants WHERE CatIDB = 'A'"; $rsBotanicalA = mysql_query($query_rsBotanicalA, $connGND) or die(mysql_error()); $row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA); $totalRows_rsBotanicalA = mysql_num_rows($rsBotanicalA); ?> <table border="0" align="left"> <?php do { ?> <tr> <td align="left"><a href="plantdetails.php?recordID=<?php echo $row_rsBotanicalA['PlantID']; ?>"> <?php echo $row_rsBotanicalA['BotanicalName']; ?> </a></td> </tr> <?php } while ($row_rsBotanicalA = mysql_fetch_assoc($rsBotanicalA)); ?> </table> Could someone help me to write this code, as I have been unsuccessful maintaining the links. I have been able get the results to display in the columsn as I would like, but I haven't been able to figure it out while maintaining the links! Thanks. I'm not looking for code, mostly just some direction, but I'm sure I'll be back as I try to shape the code. Also, I know very little about coding jQuery, Ajax, etc. Here is what I'm looking for: Basketball coach enters a Page that only he (or admin) can see. (I have that part figured out.) Once there, he has a form to fill out with a player's name and other information. I'd rather there not be 12 rows of empty cells. (Coaches will view that as work) I'd rather not have the Page reload on each "Add", but that would be the lesser of two evils. Is there a way to keep a persistent connection so when a coach hits Add, the player gets added to the database, a new empty form shows up, and the player's information shows up below on a roster? I am trying to implement lazy loading into a project with pagination already set up.
If I was to go to my website and after the .com, type in "api_courselist.php?page=1" I would receive the first 20 results of my query. If I was to change that to page=2, it would retrieve the next 20 and so on.
My issue is I have no idea how to implement that into my java script/ajax file. I have it set up so that when the user scrolls to the bottom of the page, a div will make its self visible with the new page populated inside of it and IT will keep on pulling pages in till There is no more content.
jQuery(function ($) { jQuery(document).ready(function() { var is_loaded = true; jQuery(window).scroll(function() { if(jQuery(window).scrollTop() == jQuery(document).height() - jQuery(window).height()) { jQuery('div#loadMore').show(); if(is_loaded){ is_loaded = false; jQuery.ajax({ url: "api_courselist.php?page=1", success: function(html) { is_loaded = true; if(html){ jQuery("#infiscroll").append(html); jQuery('div#loadMore').hide(); }else{ jQuery('div#loadMore').replaceWith("<center><h1 style='color:red'>End of Content !!!!!!!</h1></center>"); } } }); } } }); }); }); Quesion: Show each movie in the database on its own page, and give the user links in a "page 1, Page 2, Page 3" - type navigation system. Hint: Use LIMIT to control which movie is on which page. I have provided 3 files: 1st: configure DB, 2nd: insert data, 3rd: my code for the question. I would appreciate the help. I am a noob by the way. First set up everything for DB: <?php //connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //create the main database if it doesn't already exist $query = 'CREATE DATABASE IF NOT EXISTS moviesite'; mysql_query($query, $db) or die(mysql_error($db)); //make sure our recently created database is the active one mysql_select_db('moviesite', $db) or die(mysql_error($db)); //create the movie table $query = 'CREATE TABLE movie ( movie_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, movie_name VARCHAR(255) NOT NULL, movie_type TINYINT NOT NULL DEFAULT 0, movie_year SMALLINT UNSIGNED NOT NULL DEFAULT 0, movie_leadactor INTEGER UNSIGNED NOT NULL DEFAULT 0, movie_director INTEGER UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (movie_id), KEY movie_type (movie_type, movie_year) ) ENGINE=MyISAM'; mysql_query($query, $db) or die (mysql_error($db)); //create the movietype table $query = 'CREATE TABLE movietype ( movietype_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT, movietype_label VARCHAR(100) NOT NULL, PRIMARY KEY (movietype_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); //create the people table $query = 'CREATE TABLE people ( people_id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT, people_fullname VARCHAR(255) NOT NULL, people_isactor TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, people_isdirector TINYINT(1) UNSIGNED NOT NULL DEFAULT 0, PRIMARY KEY (people_id) ) ENGINE=MyISAM'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Movie database successfully created!'; ?> ******************************************************************** *********************************************************************** second file to load info into DB: <?php // connect to MySQL $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); //make sure you're using the correct database mysql_select_db('moviesite', $db) or die(mysql_error($db)); // insert data into the movie table $query = 'INSERT INTO movie (movie_id, movie_name, movie_type, movie_year, movie_leadactor, movie_director) VALUES (1, "Bruce Almighty", 5, 2003, 1, 2), (2, "Office Space", 5, 1999, 5, 6), (3, "Grand Canyon", 2, 1991, 4, 3)'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the movietype table $query = 'INSERT INTO movietype (movietype_id, movietype_label) VALUES (1,"Sci Fi"), (2, "Drama"), (3, "Adventure"), (4, "War"), (5, "Comedy"), (6, "Horror"), (7, "Action"), (8, "Kids")'; mysql_query($query, $db) or die(mysql_error($db)); // insert data into the people table $query = 'INSERT INTO people (people_id, people_fullname, people_isactor, people_isdirector) VALUES (1, "Jim Carrey", 1, 0), (2, "Tom Shadyac", 0, 1), (3, "Lawrence Kasdan", 0, 1), (4, "Kevin Kline", 1, 0), (5, "Ron Livingston", 1, 0), (6, "Mike Judge", 0, 1)'; mysql_query($query, $db) or die(mysql_error($db)); echo 'Data inserted successfully!'; ?> ************************************************************** **************************************************************** MY CODE FOR THE QUESTION: <?php $db = mysql_connect('localhost', 'root', '000') or die ('Unable to connect. Check your connection parameters.'); mysql_select_db('moviesite', $db) or die(mysql_error($db)); //get our starting point for the query from the URL if (isset($_GET['offset'])) { $offset = $_GET['offset']; } else { $offset = 0; } //get the movie $query = 'SELECT movie_name, movie_year FROM movie ORDER BY movie_name LIMIT ' . $offset . ' , 1'; $result = mysql_query($query, $db) or die(mysql_error($db)); $row = mysql_fetch_assoc($result); ?> <html> <head> <title><?php echo $row['movie_name']; ?></title> </head> <body> <table border = "1"> <tr> <th>Movie Name</th> <th>Year</th> </tr><tr> <td><?php echo $row['movie_name']; ?></td> <td><?php echo $row['movie_year']; ?></td> </tr> </table> <p> <a href="page.php?offset=0">Page 1</a>, <a href="page.php?offset=1">Page 2</a>, <a href="page.php?offset=2">Page 3</a> </p> </body> </html> Some code from my pages ,
Page1 ( Redirecting page )
<html> <title>login_redirect.</title> body> <form name="redirect" action="http://mysite/page2.php" method="post"> <input type="hidden" name="mac" value="$(mac)"> </form> <script language="JavaScript"> <!-- document.redirect.submit(); //--> </script> </body> </html>Page 2 ( select product ) <?php session_start(); ini_set('display_errors',1); error_reporting(E_ALL); include '../lib/config.php'; include '../lib/opendb.php'; // get user mac adres from redirect post page1 $_SESSION['macid'] = $_POST['mac']; // set $macid for other use ( maybe not needed, am learning ) $macid = $_SESSION['macid']; // echo $macid does show mac adress, so variable is not empty here if (!empty($_POST["submit"])) { $product_choice = $_POST['accounttype']; $query= "SELECT AccountIndex, AccountCost, AccountName FROM AccountTypes WHERE AccountIndex='$product_choice'"; $result = mysql_query($query) or die('Query failed. ' . mysql_error()); while($row = mysql_fetch_array($result)) { $_SESSION['AccountIndex'] = $row['AccountIndex']; $_SESSION['AccountCost'] = $row['AccountCost']; $_SESSION['AccountName'] = $row['AccountName']; } header('Location: page3.php'); } // did leave out the other/html/form stuff herePage 3 ( show Session variables ) <?php ini_set('display_errors',1); error_reporting(E_ALL); session_start(); print_r($_SESSION); ?>Now, on page 3 i do see the right session varables, only the "macid" is empty. why ? |