PHP - Pagination Of My Results Isnt Working.
Hey Guys,
In this portion of my code I have tried to implement pagination, as the results try to display a page with over 100 mp3's with flash players on teh page, and of course the page just dies. However my attempt at pagination isnt actually working. can anyone help this noob? <? // how many rows to show per page $rowsPerPage = 20; // by default we show first page $pageNum = 1; // if $_GET['page'] defined, use it as page number if(isset($_GET['page'])) { $pageNum = $_GET['page']; } // counting the offset $offset = ($pageNum - 1) * $rowsPerPage; $query = " SELECT val FROM ax_music " . " LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die('Error, query failed'); // print the random numbers while($row = mysql_fetch_array($result)) { echo $row['val'] . '<br>'; } $row2 = mysql_query("SELECT * FROM ax_music ORDER BY 'sort' ASC"); while($row = mysql_fetch_array($row2)){ ?> <tr> <td><?=$row[title];?></td> <td> <embed src= "musicplayer2.swf" quality="high" width="300" height="52" allowScriptAccess="always" wmode="transparent" type="application/x-shockwave-flash" flashvars= "valid_sample_rate=true&external_url=./music/<?=$row[mp3];?>" pluginspage="http://www.macromedia.com/go/getflashplayer"> </embed> </td> <td> <? if($row[visible] == 0){ echo "<strong>Not Playlisted</strong><br /> <a href=\"index.php?page=musicplayer&showid=$row[id]\">Add To Playlist</a>"; }else{ echo "<strong>Playlisted</strong><br /> <a href=\"index.php?page=musicplayer&hideid=$row[id]\">Remove From Playlist</a>"; } ?> </td> <td><a href="index.php?page=musicplayer&deleteid=<?=$row[id];?>"><strong>Delete</strong></a></td> <td><a href="./music/<?=$row[mp3];?>"><strong>Download</strong></a></td> </tr> <? } ?> </table> Similar Tutorialsit worked before, although now $value consists of a space and i think it may be messing things up. i pass a form field Code: [Select] <input type="text" name="attributes[]" id="attributes[]"> and then i do this... In the case above the 3 attributes[] passed are "Value 1", "Value 2", "Value 3" $attribute = ""; foreach($_POST['attributes'] as $key => $value) { $attribute .= $value . "/"; } $atr = explode("/",$attribute); #print_r($atr); foreach($atr as $key => $value) { #THIS IS WHERE THE ISSUE ARISES... $_POST[$value] wont work echo $_POST[$value] . "<BR>"; // DOES NOT WORK #echo $value . "<BR>"; // WORKS - shows "Value 1", etc.... #echo $_POST["VALUE 1"] . "--<BR>"; // DOESNT WORK EITHER } any ideas? im 90% certain if the $value variable was just "Value" and not "Value 1" it would work as it has before. I am using an if statement. If the user has a credit value of 1 or more it echos a variable thats a form. When the user submits the form, it takes a credit away, so the credit value is -1. I need the form to dissapear, because the form has a button that will execute a query that I dont want to execute. So, usually unset() fixes this, but its not in my case. Heres the code Code: [Select] $a='<strong></strong>'; if ($hintcredit<1) $a.='<font style="color: #cc0000;">You have already requested a hint! Once you guess the correct number, you will be able to get another hint. </font>'; else $form= "<form action='blablabla' method='post'>blablablabla</form>"; $a.=$form; $a.='<strong></strong>'; echo $a; if ($_POST['request'] == "Retrieve Hint") { unset($form); $form= '<b>One of the digits in your number is '.substr($num, -1).'</b>'; $newquery= "UPDATE userinfo SET hint_credits = '-1' WHERE username = '".$_SESSION['login_name']."'"; echo $form; mysql_query($newquery,$link); } In this case, the form is still being shown. I need the form completely removed after the form has been submitted. This is simple and idk why its not working for me!? im trying to return the highest value in my table from the season_id column this is the code i have: Code: [Select] $test = mysql_query("SELECT * FROM `$show` WHERE [season_id]=(SELECT Max([season_id]) FROM `$show`)"); please advise? Hi, I'm making a php game, and the image map isn't working. I don't know if it is a php or javascript issue, I don't think it is an html issue but I could be wrong so feel free to move this post. lol. But basically, The image map is supposed to link to an array of images. That is how the game works. There is the overworld image map, you click on a link, and go to the zone images, all in the same window. Any help GREATLY appreciated because having the image map feature work would be awesome finally. thanks. Derek. here is the code that uses the image map. I cut out a lot of the unnecessary code , but the image map functionality related code is in there. Code: [Select] <?php session_start(); ////////////////////////////////////////////////////////////////////////////////// /////////////////////////////GAME NAVIGATION AND MONSTER SEARCH CODE NOT FINISHED////////////////////////////////// $locations[0] = array(); $locations[1] = array( 'background_images' => array( "<img src='sundragon_environments/ocean/ocean1_FRAME.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME2.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME3.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME4.jpg'/>", "<img src='sundragon_environments/ocean/ocean1_FRAME5.jpg'/>" ), 'monster_images' => array( "<img src='sundragon_monsters_source/water/goldfish/goldfish.png'/>", "<img src='sundragon_monsters_source/water/eel/eel_transp_FRAME.png '/>", "<img src='sundragon_monsters_source/water/shark/shark_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/octalisk/octalisk_transp_FRAME.png'/>", "<img src='sundragon_monsters_source/water/teardrop_ocean_protector/teardrop_ocean_protector.png'/>" ) ); $locations[2] = array( 'backgroundImages' => array( //Array images go here. ) ); if(isset($_GET['newLocation'])) { $_SESSION['current_location']=$_GET['newLocation']; } if(!isset($_SESSION['current_location']) && !isset($_SESSION['current_background']) && !isset($_SESSION['currentMonster'])) { $_SESSION['current_location'] = 0; $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if($_SESSION['current_location'] != 0) { if(!isset($_SESSION['current_background']) && !isset($_SESSION['current_monster'])) { $_SESSION['current_monster'] = 0; $_SESSION['current_background'] = 0; } if(isset($_GET['further'])) { //below is- inside the locations array, teardrop ocean (1) the background image is 4(example)+1 is set, then //do this if(isset($locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']+1])) { $_SESSION['current_background']+=1; } if(isset($locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']+1])) { $_SESSION['current_monster']+=1; } } elseif(isset($_GET['back'])) { if(isset($locations[$_SESSION['current_location']]['background_images'][$_SESSION['current_background']-1])) { $_SESSION['current_background']-=1; } if(isset($locations[$_SESSION['current_location']]['monster_images'][$_SESSION['current_monster']-1])) { $_SESSION['current_monster']-=1; } } $currentBackground=$_SESSION['background'][$_SESSION['current_background']]; $currentMonster=$_SESSION['monster'][$_SESSION['current_monster']]; } else { //?newLocation=1 means set it to Teardrop ocean. $currentBackground = ' <img src="aradia.jpg" width="256" height="328" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="5,176,81,249" href="?newLocation=1"/> </map>'; $currentMonster = ''; } /////////////////////////////////////////////////////////////////////////////////////////////////// ?> <!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>Realm of the Sun Dragon</title> <link rel="stylesheet" type="text/css" href="css/gamestyles.css"> <style type="text/css"> body { margin-top:-32px; padding:0; color: gold; } table { color: black; } .style8 {color: #000000} </style> </head> <body oncontextmenu="return false;"> <div id="container"> <div id="monster_message"> <?php echo "this is the monster battle and NPC talk window";?> </div> <div id="currentWeapon"> <img src="sundragon_interface_template/items/swords/sword_shrunk.png" width="190" height="65" /> </div> <div id="iframe_player_top_lft" > <div id="left_player_stats"><table align="center" width="30" border="0"> <tr> <td><strong>HP</strong></td> <td><strong><font color="red"><?php echo $playerHp;?></font></strong></td> </tr> <tr> <td><strong>MANA</strong></td> <td><strong><font color="green"><?php echo $echoPlayerMana;?></font></td> </tr> <tr> <td><strong>EXP</strong></td> <td><strong><font color="blue">999</font></strong></td> </tr> <tr> <td><strong>PLAT</strong></td> <td><strong><font color="white">999</font></strong></td> </tr> </table></div> <p> </p> <p> </p> <p> </p> <p align="center"><strong><br /> <span class="style8">Octalisk (Level <?php echo $currentMonsterLevel;?>) </span></strong> <br/> <strong><span class="style8">HP</span><font color="red"> <?php echo $monsterHp;?></font></strong> </p> <div id="spelleffectsleft" > <div class="divcenter"> <div align="center"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <!--end divcenter--> </div><!--end spell effects--> <div id="bottomspellsleft" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> <!--end div center--> </div><!--end bottomspells--> </div><!-- end player div--> <div id="iframe_spell_foreground"><?php echo $echoSpell;?></div> <div id="iframe_monster_background"><?php echo $currentBackground;?></div> <div id="iframe_transparent_monster"><?php echo $currentMonster;?></div> <!--not here--> <div id="iframe_player_top_right" > <table width="160" height="64" border="0" align= "center"> <tr> <td width="160"><div align="center"> <p><strong><br /> Silverglade (Level: <?php echo $currentPLayerLevel;?>)<br /> </strong></p> </div></td> </tr> </table> <div class="spelleffects" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> <div class="bottomspells" > <div class="divcenter"> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> <div class="inline"> <div align="center">spell</div> </div> </div> </div> </div> <div id="iframe_chat_right"> the data from the chat message box will be output to this div</div> <!--not here--> <div id="iframe_player_center_bottom" align="center" ><div style="display: inline;"> <form style="display: inline; margin: 0;" ...> <form style="display: inline; margin: 0;" action='gamestart_NEWEST.php' method='post'><input type='submit' name='attack' value='Attack'/><input type="submit" name="search" value="search" /><input type="submit" value="cast spell" name="spell" /><input type="submit" name="inventory" value="Inventory"/></form> <form style="display: inline; margin: 0;" method="get" action=""><input type="submit" value="go further" name="further" /> <input type="submit"value="Go back" name="back"/></form> </form> </div> <div id="chat"> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <strong>Message:</strong> <textarea name="message"></textarea> <input type="submit" name="submit" value="Chat"> <input type="hidden" name="ip" value="<?php echo $_SERVER['REMOTE_ADDR']; ?>"> </form> </div></div></div> <!--not here--> <div id="log_off"> <a href="logout.php"><strong>LOG OFF</strong></a> </div> <!--not here--> </div> </body> </html> Code: [Select] <?php session_start(); require_once("connect.php"); ?> <html> <body> Thanks for buying!<br> Receipt:<br> Amount:<?php echo ($_POST["amount"]);?> <br>Type:<?php echo $_POST["type"];?> <br>Cost:<?php if($_POST["type"]=="pikemen"){ $cost = 20 * $_POST["amount"]; $price = $_SESSION["resources"] - $cost; $name = $_SESSION["username"]; $gained = $_POST["amount"] + $_SESSION["pikemen"]; mysql_query("UPDATE SET pikemen = '$gained' WHERE username = '$name'"); } mysql_query("UPDATE SET resources = '$price' WHERE username = '$name'"); ?> </body> </html> The script is supposed to use some information taken from an input box on the previous page to buy items from the shop, but its not working (it doesnt give errors, just doesnt change the amount of soldiers or resources... Hi guys Probably a simple but trying to figure out why I cant get this while loop to work (at least I think its the loop) Query works as it returns 1 row, but not all of them. Any help would be great! $sql = "SELECT * FROM requests ORDER BY leave_after DESC"; if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { while ($row = mysql_fetch_assoc($result)) { echo '<div id="resultholder">'; echo "<p>Request ID:" . $row['id'] . ", User ID: " . $row['user_id'] . ", Departing From: " . $row['departing'] . ", Going To: " . $row['destination'] . " , Leaving After: " . $row['leave_after'] . " , but Arriving Befo " . $row['arrive_before'] ."</p></div>"; echo '</div>'; } } } Thanks! Hiya peeps! I have built this. <?php class extract { private $link; private $rec; public function __construct() { } public function __init($link, $rec = 0) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$link); curl_setopt($ch, CURLOPT_TIMEOUT, 50); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $this->_data = curl_exec($ch); curl_close($ch); $this->_emails = array(); if($rec == 1) { if(preg_match_all('/((?:http|https):\/\/(?:www\.)*(?:[a-zA-Z0-9_\-]{1,15}\.+[a-zA-Z0-9_]{1,}){1,}(?:[a-zA-Z0-9_\/\.\-\?\&\:\%\,\!\;]*))/', $this->_data, $urls)) { foreach($urls[0] as $k => $v) { $this->__init($v, 1); } } } return $this->emails(); } public function emails() { if(preg_match_all('/(\w+\.)*\w+@(\w+\.)*\w+(\w+\-\w+)*\.\w+/', $this->_data, $emails, PREG_SET_ORDER)) { foreach($emails as $dk => $dv) { foreach($dv as $fk => $fv) { if(preg_match('/^[^@]+@[a-zA-Z0-9._-]+\.[a-zA-Z]+$/', $fv)) { $this->_emails[] = $fv; } } } } return $this->_emails; } public function multi_unique($array) { foreach ($array as $k => $na) { $new[$k] = serialize($na); $uniq = array_unique($new); } foreach($uniq as $k => $ser) { $new1[$k] = unserialize($ser); } return $new1; } } $go = new extract(); $done = $go->__init($_POST['site'], $_POST['deep']); print_r($done); ?> <center><form action="#" method="post"> Site:<br /><input type="text" name="site"><br /><br /> Go-Deep:<br /><select name="deep"><option value="0" selected>No</option><option value="1">Yes</option></select><br /><br /> <input type="submit" name="submit"> </form></center> It works, but only on one URL, I have setup a html page containing an email address and a link to another page containing an email address, so technically it should return two email addresses. But it doesn't, it only displayed the email address on the url that is inputted. Does anyone have any idea why? Many thanks, James. I dont understand why my header(Location) isnt working. Does any one see why?
<?php include 'core/init.php'; logged_in_redirect(); include 'includes/overall/header.php'; if (empty($_POST) === false) { $required_fields = array('first_name', 'last_name', 'username', 'password', 'password_again', 'email'); foreach($_POST as $key=>$value) { if (empty($value) && in_array($key, $required_fields) === true) { $errors[] = 'All field are required'; break 1; } } if (empty($errors) === true) { if (user_exists($_POST['username']) === true) { $errors[] = 'Sorry, the user \'' . $_POST['username'] . '\' is already taken'; } if (preg_match("/\\s/", $_POST['username']) == true) { $errors[] = 'Your username can not have spaces'; } if (strlen($_POST['password']) < 6) { $errors[] = 'Your password must be at least 6 characters long'; } if ($_POST['password'] !== $_POST['password_again']) { $errors[] = 'Your passwords do not match'; } if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) === false) { $errors[] = 'A valid email address is required'; } if (email_exists($_POST['email']) === true) { $errors[] = 'Sorry, the email \'' . $_POST['email'] . '\' is already is use. Please contact your site adimn is this is incorrect.'; } } } if (isset($_GET['success']) && empty($_GET['success'])) { echo '<div class="container"><div class="background-success text-center"><div class="alert alert-success center-background">You\'ve be registered successfully! Please check your email to activate your account</div><div class="center-background"><div class="center-text-background">if any issues occur please send us an email!! support@bettergamerzunited.com</div></div></div>'; } else { if(empty($_POST) === false && empty($errors) === true) { $register_data = array( 'first_name' => $_POST['first_name'], 'last_name' => $_POST['last_name'], 'username' => $_POST['username'], 'password' => $_POST['password'], 'email' => $_POST['email'], 'email_code' => md5($_POST['username'] + microtime()) ); register_user($register_data); header('Location: register.php?success'); exit(); } ?> <div class="container background"> <form action="" method="POST" class="form-horizontal" role="form"> <div class="form-group"> <label for="inputfirstname3" class="col-sm-2 control-label">First Name</label> <div class="col-sm-10"> <input type="text" name="first_name" class="form-control" id="inputfirstname3" value="" autocomplete="off" placeholder="First Name"> </div> </div> <div class="form-group"> <label for="inputlastname3" class="col-sm-2 control-label">Last Name</label> <div class="col-sm-10"> <input type="text" name="last_name" class="form-control" id="inputlastname3" value="" autocomplete="off" placeholder="Last Name"> </div> </div> <div class="form-group"> <label for="inputusername3" class="col-sm-2 control-label">Username</label> <div class="col-sm-10"> <input type="text" name="username" class="form-control" id="inputusername3" value="" autocomplete="off" placeholder="Username"> </div> </div> <div class="form-group"> <label for="inputemail3" class="col-sm-2 control-label">Email</label> <div class="col-sm-10"> <input type="email" name="email" class="form-control" id="inputemail3" value="" autocomplete="off" placeholder="Email Address"> </div> </div> <div class="form-group"> <label for="inputpassword3" class="col-sm-2 control-label">Password</label> <div class="col-sm-10"> <input type="password" name="password" class="form-control" id="inputpassword3" autocomplete="off" placeholder="Password"> </div> </div> <div class="form-group"> <label for="inputpassword_again3" class="col-sm-2 control-label">Validate Password</label> <div class="col-sm-10"> <input type="password" name="password_again" class="form-control" id="inputpassword_again3" autocomplete="off" placeholder="Validate Password"> </div> </div> <div class="form-group"> <div class="col-sm-10"> <p class="info">Please be aware that this does not mean that you are a member of Better Gamerz United. If you would like to be come a member please contuine with the registration and then fill out our application. Other wise you will have limited use of this site. Thank you Team BGU!! </p> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-primary pull-right register">Register</button> </div> </div> </form> </div> <?php } include 'includes/overall/footer.php'; ?> the strange thing is...I have the exact same script on another part of my page and it works! the only thing that changed are the variable names and the path (which ive checked 27000 times) What this should do is check if you have a signature in the external file and if you do and you fill out the form correctly then it replaces your old signature with your new one. and if you dont have a signature already and filled out the form correctly then it should write your signature to the file...for some reason this isnt working after checking and rechecking...i need a second pair of eyes. Help please! if (isset($_POST['change_submit2'])) { if (($_SESSION['logged_in'] == '1') && ($signature_test != '1') && ($_POST['change_box2'] == 'CHANGE') && ($invalid_character_test != '1') && ($invalid_character_test1 != '1')) { $fh1 = fopen($users_signatures_path, 'r+'); fwrite($fh1, $sig_front); frwrite($fh1, $_POST['signature']); fwrite($fh1, $sig_back); fwrite($fh1, ' '); flose($fh1); echo 'You have succesfully created a signature!'; } elseif (($_SESSION['logged_in'] == '1') && ($signature_test == '1') && ($_POST['change_box2'] == 'CHANGE') && ($invalid_character_test != '1') && ($invalid_character_test1 != '1')) { $users_signatures_path1 = "../../users/users_signatures.txt"; $fh1 = fopen($users_signatures_path1, 'r+'); $read_fh1 = fread($_fh1, filesize($users_signatures_path1)); $the_new_sig = str_replace($mcurrent_sig, $mnew_sig, $read_fh1); fclose($fh1); $fh1 = fopen($users_signatures_path1, 'r+'); fwrite($fh1, $the_new_sig); fclose($fh1); echo $mnew_sig; echo 'Your signature has been succesfully changed!'; } elseif ($_SESSION['logged_in'] != '1') { echo 'You need to be logged in!'; } elseif ($_POST['change_box2'] != 'CHANGE') { echo 'You must fill in the "CHANGE" box!'; } elseif ($invalid_character_test == '1') { echo 'Contains illegal characters!'; } elseif ($invalid_character_test1 == '1') { echo 'Contains illegal characters!'; } } Hello! This may sound like a stupid question but i have been trying to get this working all day and its driving me crazy.
Ive been asked to take over development of this project, he sent me his code and its a little out of date so im trying to update it. Here is what i cant work out.
I have this little snippet of code:
if ($page == "showthread"){ showThread(); }There are several more like that, but you dont need a whole list. That code seems to be throwing up this error when i go to that specific page: Notice: Undefined index: error in ..... All well and good, i would usually do this: if (isset($page) == "showthread"){ showThread(); }Thats fine and dandy, the error goes away. But now, when i go to that page, it redirects me and gives me my error message for a non-existing page. Its really frustrating me. Can you help me fix this little error? HI, Please forgive my inexperience I am new to php and any help is most apreciated. I have a database called liveproj and a table named olde_history. Within the table, Project history is stored. Each project has a unique number ie 10383 etc. I am trying to display the results for an individual project once the project has been selected. The structure of the table is as such: $sql = 'CREATE TABLE IF NOT EXISTS `liveproj`.`olde_history` ( `History_Id` int(6) NOT NULL AUTO_INCREMENT, `History_Project_Id` varchar(10) NOT NULL, `History_Department_Id` varchar(25) NOT NULL, `History_By` varchar(25) DEFAULT NULL, `History_Contact` varchar(25) DEFAULT NULL, `History_Date` varchar(10) NOT NULL, `History_Description` varchar(500) DEFAULT NULL, `History_Action_Owner` varchar(25) DEFAULT NULL, `History_Status_Id` varchar(10) DEFAULT NULL, `History_Action_Date` varchar(10) DEFAULT NULL, `History_Action_Description` varchar(500) DEFAULT NULL, `History_Date_Resolved` varchar(10) DEFAULT NULL, `History_Email` varchar(150) DEFAULT NULL, `History_Minutes` varchar(150) DEFAULT NULL, `History_Visit` varchar(150) DEFAULT NULL, PRIMARY KEY (`History_Id`) )'; A snippet of the table structure I can View all information based on all projects and this works fine althoughh I only wish to display the relevent info for a selected project. The error code I get is as follows: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10,10' at line 1 My code is: Code: [Select] <!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>Live Project List</title> <link href="../css/Style.css" rel="stylesheet" type="text/css" /> <style type="text/css"></style> </head> <body id="body"> <div align="center" id="Section">Project History List <div id="apDiv1"> <form id="form1" name="form1" method="post" action=""> <input type="text" name="Search" id="Search" size="20" /> <img src="../Images/search.png" width="24" height="24" align="middle" /> </form> </div> </div> <table class="hovertable"> <tr> <th width="10%">Date:</th> <th width="10%">By:</th> <th width="30%">History Description:</th> <th width="5%">Action Status:</th> <th width="5%">Action Owner:</th> <th width="10%">Action Rqd Date</th> <th width="10%">Action Description:</th> <th width="10%">Date Resolved:</th> <th width="5%">View:</th> <th width="5%">Edit:</th> </tr> <?php ############################################################################### # Start of pagination script ############################################################################### IF (ISSET($_GET['pageno'])) { $pageno = $_GET['pageno']; } ELSE { $pageno = 1; } // if ############################################################################### # 2. Identify how many database rows are available ############################################################################### # This code will count how many rows will satisfy the current query. session_start(); include "../scripts/connect.php"; include "../scripts/Inc/db_lp.php"; //$disc = $_SESSION['Disc']; $quote='"'; $projno2 = $_SESSION['Project']; $projno = "$quote$projno2$quote"; $query = "SELECT count(*) FROM `liveproj` . `olde_history` WHERE `History_Id` = '$projno'"; //$query = "SELECT count(*) FROM `liveproj` . `olde_history` WHERE `History_Id` <> ''"; //WORKING LINE $result = mysql_query($query) or die(mysql_error()); $query_data = MYSQL_FETCH_ROW($result); $numrows = $query_data[0]; PRINT "NUMROWS: $numrows<br>"; ############################################################################### # 3. Calculate number of $lastpage ############################################################################### # This code uses the values in $rows_per_page and $numrows in order to identify the number of the last page. $rows_per_page = 10; ######## Set the ammount of rows you wish to display per page ######### $lastpage = CEIL($numrows/$rows_per_page); ############################################################################### # 4. Ensure that $pageno is within range ############################################################################### # This code checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; IF ($pageno < 1) { $pageno = 1; } ELSEIF ($pageno > $lastpage) { $pageno = $lastpage; } // if ############################################################################### # 5. Construct LIMIT clause ############################################################################### # This code will construct the LIMIT clause for the sql SELECT statement. $limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page; ############################################################################### # 6. Issue the database query ############################################################################### # Now we can issue the database query and process the result. $query = "SELECT * FROM `liveproj` . `olde_history` $limit"; $result = mysql_query($query) or die(mysql_error()); #... process contents of $result ... WHILE ($row = MYSQL_FETCH_ARRAY($result)) { echo '<tr onmouseover="this.style.backgroundColor=\'#CCCCCC\';" onmouseout="this.style.backgroundColor=\'#ffffff\';"><td width="10%">'; echo $row["History_Date"]; echo "</td>"; echo '<td width="10%" >'; echo $row["History_By"]; echo "</td>"; echo '<td width="30%">'; echo "" . substr($row['History_Description'],0,20) . ".....[Select View To Read More]" ; //echo $row["History_Description"]; echo "</td>"; echo '<td width="5%">'; echo $row["History_Status_Id"]; echo "</td>"; echo '<td width="5%">'; echo $row["History_Action_Owner"]; echo "</td>"; echo '<td width="10%">'; echo $row["History_Action_Date"]; echo "</td>"; echo '<td width="10%">'; //echo $row["History_Action_Description"]; echo "" . substr($row['History_Action_Description'],0,20) . ".....[Select View To Read More]" ; echo "</td>"; echo '<td width="10%">'; echo $row["History_Date_Resolved"]; echo "</td>"; echo '<td width="5%">'; echo "<div class=form>"; echo '<form id="form" name="form" method="post" action="Doc_History_Desc.php" onSubmit="return confirm('; echo '">'; echo '<input type="hidden" name="histid" value="'; echo $row["History_Id"]; echo '"><input type="image"SRC="../Images/Icons/List-View.png" Height="22" Width="22" value="View" alt="submit" class="hidebutton" name="B1">'; //echo '"><input type="submit" value="View" name="B1">'; echo "</form>"; echo "</td>"; echo '<td width="5%">'; echo "<div class=form>"; echo '<form id="form" name="form" method="post" action=".php" onSubmit="return confirm('; echo '">'; echo '<input type="hidden" name="histid" value="'; echo $row["History_Id"]; echo '"><input type="image"SRC="../Images/Icons/List-Edit.png" Height="22" Width="22" value="View" alt="submit" class="hidebutton" name="B1">'; //echo '"><input type="submit" value="View" name="B1">'; echo "</form>"; echo "</td>"; echo "</tr>"; } ?> </table> <p><br /> <br /> </p> <?php ############################################################################### # 7. Construct pagination hyperlinks ############################################################################### # Finally we must construct the hyperlinks which will allow the user to select # other pages. We will start with the links for any previous pages. echo '<div align="center" id="SectionEnd">'; IF ($pageno == 1) { echo "<font size='1' color='#FFFFFF'>FIRST | PREV</font>"; } ELSE { echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'>FIRST</a>"; $prevpage = $pageno-1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'>PREV</a>"; } // if # Next we inform the user of his current position in the sequence of available pages. echo " <font size='1' color='#FFFFFF'>( Page $pageno of $lastpage )</font> "; # This code will provide the links for any following pages. IF ($pageno == $lastpage) { echo "<font size='1' color='#FFFFFF'>NEXT | LAST</font>"; } ELSE { $nextpage = $pageno+1; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>NEXT</a>"; echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>LAST</a>"; } // if echo'<br/>'; echo'<br/>'; echo'</div>'; ############################################################################### # End of pagination script ############################################################################### ?> </body> </html> Thankyou in advance. Good Evening, I've been in a trial and error state for the past week trying to figure out how I can put on the pre-made pagination scripts I found on the web, but of no luck. I have just started programming like two weeks ago, and is still trying to understand logics and stuffs so I can get my desired output. So far, everything is doing well except for one - I am really having a hard time to incorporate pagination scripts with my code. To rank myself as a php programmer, I can say I am lower than one, and seemingly, what I want to achieve is an advanced code. Can anyone help me on what pagination code I should try to play with and incorporate with my code? Here's my code so far: <?PHP include("dbconnection.php"); //Include database connection to file $query = "SELECT * FROM records"; if(isset($_POST["btnSearch"])) { $query .= " WHERE last_name LIKE '%".$_POST["search"]."%' OR first_name LIKE '%".$_POST["search"]."%'OR territory LIKE '%".$_POST["search"]."%'OR job_title LIKE '%".$_POST["search"]."%'OR title LIKE '%".$_POST["search"]."%'OR employer LIKE '%".$_POST["search"]."%' ORDER BY territory ASC LIMIT 0,15" ; $result = mysql_query($query, $connection) or die(mysql_error()); } ?> <!-- Start of table --> <table width="760" border="0" align="center" cellpadding="0" cellspacing="0"> <td> <table width="760" border="0" cellpadding="0" cellspacing="0"> <!-- Table data containing the Asia Logo --> <td width="199" align="center" valign="top"> <a href="login.html"> <img src="asia.gif" alt="" width="152" height="58" border="0" /> </a> </td> <!-- Table data containing Home button --> <td width="176" align="right" valign="bottom"> <a href="main.php"> <img src="Home.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Table data containing View Client button --> <td width="130" align="right" valign="bottom"> <img src="View.jpg" width="104" height="20" border="0"/> </td> <!-- Table data containing the Add Client button --> <td width="146" align="right" valign="bottom"> <a href="add_client.php"> <img src="Add.jpg" width="104" height="20" border="0"/> </a> </td> <!-- Blank table data --> <td width="109" align="right" valign="bottom"> </td> </table> <!-- Table design division and body--> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="3" bgcolor="#1B1C78"> <img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td> <td width="560" bgcolor="#0076CC"> <img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td> <tr> <td height="500" colspan="2" align="center" valign="top" bgcolor="#F3FAFE"> <!-- Page contents --> <!-- Search Query --> <br> <form name="form" action="view_client.php" method="post"> <table width="351" border="0"> <tr> <td width="137" align="left" valign="middle"> SEARCH RECORD: </td> <td width="144" align="center" valign="middle"> <input type="text" name="search" /> </td> <td width="56" align="left" valign="middle"> <input type="submit" name="btnSearch" value="Search" /> </td> </tr> </table> <br> <!-- End of search query--> <!-- Start of Search Results--> <table border="0" cellpadding="3" cellspacing="1" bordercolor="38619E" > <tr> <th width="80" align="center" bgcolor="#E0E8F3">Territory</th> <th width="330" align="center" bgcolor="#E0E8F3">Employer</th> <th width="160" align="center" bgcolor="#E0E8F3">Name</th> <th width="80" align="center" valign="middle" bgcolor="#E0E8F3"> </th> </tr> <?php if($result) { for($i=0; $i<mysql_num_rows($result); $i++) { $id = trim(mysql_result($result, $i, "id")); $territory = trim(mysql_result($result, $i, "territory")); $employer = trim(mysql_result($result, $i, "employer")); $first_name = trim(mysql_result($result, $i, "first_name")); $last_name = trim(mysql_result($result, $i, "last_name")); echo "<tr>"; echo "<td>".$territory."</td>"; echo "<td>".$employer."</td>"; echo "<td>".$last_name.", ".$first_name."</td>"; echo "<td><a href='edit_client.php?id=".$id."'>edit</a> | <a href='delete_client.php?id=".$id."'>delete</a></td>"; echo "</tr>"; } } ?> </table> </form> <!-- End of page --> </td> </tr> </table> </td> <tr> <td height="38"> <table width="760" border="0" cellpadding="0" cellspacing="0"> <td width="200" height="35" align="center" bgcolor="#1B1C78" class=white> <a href="disclaimer.html"> <font color="#FFFFFF">Legal Disclaimer</font> </a> </td> <td width="560" align="center" bgcolor="#0076CC"> Copyright © 2006 - 2010 Asia. All rights reserved. </td> </table></td> </tr> </table> Thank you very much, and I am looking forward for your responses. Thanks! I would like to know what is the best method (the most intelligent and comfortable for users) to paginate a result table with PHP/MySQL? Provided I have a result set of 100 pages. Method 1: <select> <option>1</option> .... </select> Method 2: Link on Page 1, 2, 3 ... 100 If there is any algorithm with PHP for automated these displays, please demonstrate it. I want visitors to be able to sort the results on my Browse Documentaries page by popularity, date, and type. The only way I know how to do this is to create a separate page for each sorting arrangement and provide a link to each page. Is there any way of doing it on a single page?
I am guessing that I can do things like that with Javascript or jQuery. Is that correct?
Hi All, I have a pagination script that works correctly when a user clicks on a category heading, however when I am using it to try an display search results it does not take into account the set of records to display per page, it just shows all results. <?php echo '<h3>Search Results</h3><br />'; $query = "SELECT count(*) from merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%'"; $row=mysql_fetch_assoc(mysql_query($query)); $total_records = $row['count(*)']; $records_per_page = 5; $total_pages = ceil($total_records / $records_per_page); $page = intval($p); if ($page < 1 || $page > $total_pages) $page = 1; $offset = ($page - 1) * $records_per_page; $limit = " LIMIT $offset, $records_per_page"; $query = mysql_query("SELECT * FROM merchants WHERE name LIKE '%$_GET[q]%' OR short like '%$_GET[q]%' OR full like '%$_GET[q]%' OR keywords like '%$_GET[q]%' ORDER BY m_id DESC") ; echo mysql_error() ; while($row = mysql_fetch_assoc($query)){ $name = $row['name']; $short = $row['short']; $per = $row['percent']; $m_id = $row['m_id']; ?> <div id="cbbox"> <a href="viewm.php?m_id=<?php echo $m_id;?>"> <div class="cbname"> <?php echo $name;?> - Up to <?php echo $per ;?>% Cashback Available </div> <div class="cbimage"> <img src="pimage/<?php echo $name;?>.gif" height="50px" width="100px" /> </div> <div class="cbshort"> <?php echo $short;?> </div> </a> <div class="cbtweet"> <a href="http://twitter.com/home/?status=Get up to <?php echo $per;?> percent Cashback on purchase from <?php echo $name;?> http://goo.gl/PLkp"><img src="images/cbtweet.png" width="90" height="50" alt="Tweet This" /></a> </div></div> <br /><br /> <?php } if($total_records > 5) { for ($i = 1; $i <= $total_pages; $i++) { echo "<a title='page $i p=$i'>Page $i - </a>"; } } ?> </div> if I echo out $total_records it displays the correct amount (7 in the case I am looking at) Any ideas? Hi Everyone,
I have a question about pagination. I have this code that I would like to incorporate into my php file.
This is said code that will be incorporated:
try { // Find out how many items are in the table $totalItems = $databaseHandle->query(' select count(*) from tableName ')->fetchColumn(); // Set how many items per page to display $limit = 10; // find how many pages are needed $totalPages = ceil($totalItems / $limit); // Find out which page we are on $currentPage = min($totalPages, filter_input(INPUT_GET, 'page', FILTER_VALIDATE_INT, array( 'options' => array( 'default' => 1, 'min_range' => 1, ), ))); // Calculate the offset for the query $offset = ($page - 1) * $limit; // Some information to display to the user $start = $offset + 1; $end = min(($offset + $limit), $total); // "back" link $prevlink = ($page > 1) ? '<a href="?page=1" title="First page">«</a> <a href="?page=' . ($currentPage - 1) . '" title="Previous page">‹</a>' : '<span class="disabled">«</span> <span class="disabled">‹</span>'; // "forward" link $nextlink = ($page < $pages) ? '<a href="?page=' . ($page + 1) . '" title="Next page">›</a> <a href="?page=' . $totalPages . '" title="Last page">»</a>' : '<span class="disabled">›</span> <span class="disabled">»</span>'; // Display the paging information echo '<div id="paging"><p>', $prevlink, ' Page ', $currentPage, ' of ', $totalPages, ' pages, displaying ', $start, '-', $end, ' of ', $totalItems, ' results ', $nextlink, ' </p></div>'; // Get the results. Paged query $stmt = $databaseHandle->prepare(' select * from tableName order by name limit :limit offset :offset '); // Bind the query params $stmt->bindParam(':limit', $limit, PDO:: PARAM_INT); $stmt->bindParam(':offset', $offset, PDO:: PARAM_INT); $stmt->execute(); // Results? if ($stmt->rowCount() > 0) { $stmt->setFetchMode(PDO::FETCH_ASSOC); $iterator = new IteratorIterator($stmt); // Display the results foreach ($iterator as $row) { echo '<p>', $row['name'], '</p>'; } } else { echo '<p>No results could be displayed.</p>'; } } catch (Exception $e) { echo '<p>', $e->getMessage(), '</p>'; }and this is what is in my php file: <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; ?><br /> <?php $file = '/var/www/html/active_colist.csv'; $fh = fopen($file, 'r'); $companies = array(); $row = fgetcsv($fh, 1024); // ignore header while ($row = fgetcsv($fh, 1024)) { $companies[$row[0]] = array('company' => $row[1], 'country' => $row[3]); //changed line } fclose($fh); //Split a filename by . $filenames = explode(".", $r->swishdocpath); //get 3 chars from $filenames to $country $wvb_number = substr($filenames[1],1,12); $country = substr($filenames[1],1,3); echo 'Country: '.$companies[$wvb_number]['country']."<br />"; //echo 'Country Name: '.$country."<br />"; //$filenames[2] = explode(".", $r->swishdocpath); $year = substr($filenames[2],0,4); echo 'Year: '.$year."<br />"; //$filenames = explode(".", $r->swishdocpath); //$wvb_number = substr($filenames[1],1,12); echo 'WVB Number: '.$wvb_number."<br />"; echo 'Company Name: '.$companies[$wvb_number]['company']; //echo 'Country: '.$companies[$wvb_number]['country']; ?> </p> <?php } } catch (Exception $e) { die('ERROR: ' . $e->getMessage()); } } ?> </body> </html>My question is what would be the best way incorporate this into my php file so that I am able to display a limit number link by page so that not all of the results are listed on the same page? If that is even possible. 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've got a page with pagination set up, but I can't figure out where I went wrong with the links at the bottom. When I do a search, it generates the proper number of links, but clicking on the links goes to a page with a whole row of 20 links at the bottom and no results on the page. (my search should show 3 pages with 2 records on each page) I've looked through the tutorial here and one in a book on pagination. Not seeing what's wrong. I'd narrow this down if I knew where it was causing the problem. pagination links are at the very bottom of the code. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html><head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>search.html</title></head> <body> <center> <p>The results of your search:</p> <br> </center> require ('databaseconnect.php'); $select = mysql_select_db($db, $con); if(!$select){ die(mysql_error()); } $display = 2; if (isset($_GET['np'])) { $num_pages = $_GET['np']; } else { $data = "SELECT COUNT(*) FROM descriptors LEFT JOIN plantae ON (descriptors.plant_id = plantae.plant_name) WHERE `leaf_shape` LIKE '%$select1%' AND `leaf_venation` LIKE '%$select3%' AND `leaf_margin` LIKE '%$select4%'"; $result = mysql_query ($data); if (!$result) { die("Oops, my query failed. The query is: <br>$data<br>The error is:<br>".mysql_error()); } $row = mysql_fetch_array($result, MYSQL_NUM); // row 41 $num_records = $row[0]; if ($num_records > $display) { $num_pages = ceil ($num_records/$display); } else { $num_pages = 1; } } if (isset($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } if(isset($_POST[submitted])) { // Now collect all info into $item variable $shape = $_POST['select1']; $color = $_POST['select2']; $vein = $_POST['select3']; $margin = $_POST['select4']; // This will take all info from database where row tutorial is $item and collects it into $data variable row 55 $data = mysql_query("SELECT `descriptors`.* ,`plantae`.* FROM `descriptors` LEFT JOIN `plantae` ON (`descriptors`.`plant_id` = `plantae`.`plant_name`) WHERE `leaf_shape` LIKE '%$select1%' AND `leaf_venation` LIKE '%$select3%' AND `leaf_margin` LIKE '%$select4%' ORDER BY `plantae`.`scientific_name` ASC LIMIT $start, $display"); //chs added this in... row 72 echo '<table align="center" cellspacing="0" cellpading-"5"> <tr> <td align="left"><b></b></td> <td align="left"><b></b></td> <td align="left"><b>Leaf margin</b></td> <td align="left"><b>Leaf venation</b></td> </tr> '; // This creates a loop which will repeat itself until there are no more rows to select from the database. We getting the field names and storing them in the $row variable. This makes it easier to echo each field. while($row = mysql_fetch_array($data)){ echo '<tr> <td align="left"> <a href="link.php">View plant</a> </td> <td align="left"> <a href="link.php">unknown link</a> </td> <td align="left">' . $row['scientific_name'] . '</td> <td align="left">' . $row['common_name'] . '</td> <td align="left">' . $row['leaf_shape'] . '</td> </tr>'; } echo '</table>'; } if ($num_pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; // row 100 if ($current_page != 1) { echo '<a href="leafsearch2a.php?s=' . ($start - $display) . '&np=;' . $num_pages . '">Previous</a> '; } for ($i = 1; $i <= $num_pages; $i++) { if($i != $current_page) { echo '<a href="leafsearch2a.php?s=' . (($display * ($i - 1))) . '$np=' . $num_pages . '">' . $i . '</a>'; } else { echo $i . ' '; } } if ($current_page != $num_pages) { echo '<a href="leafsearch2a.php?s=' . ($start + $display) . '$np=' . " " . $num_pages . '"> Next</a>'; } } ?> </body></html> Hi, my page is currently up at brewhas.org/transactions.php. When I retrieve a set of results > the defined # per page (such as entering 'WI' for last name), I see the first page correctly, and see the links to next pages, but when I go to the next page there are no results displayed. Same for p.3, etc. So I've looked around enough to know that I need to pass a variable to the subsequent pages, either via a session variable or the URL. I have 2 fields input on the form, as well as a limit and offset. My questions are 1) do I need to pass all 4 and if so then should I use a session variable so the URL does not get too long, and 2) can anyone provide any help with setting session variables and including them to be passed? I'm a newbie and have grabbed some code where I can but this is where i'm stuck. thanks in advance. Code: [Select] <?php include 'config.php'; include 'opendb.php'; $rows_per_page = 20; //Get the values from the text boxes $fnamesearch = $_POST["fnamesearch"]; $lnamesearch = $_POST["lnamesearch"]; //These trim and convert the name fields to upper case. $fnamesearch=strtoupper($fnamesearch); $lnamesearch=strtoupper($lnamesearch); $fnamesearch=trim($fnamesearch); $lnamesearch=trim($lnamesearch); // Count how many rows are coming back for the query //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT COUNT(*) FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%'))"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the get count query $query_data = mysql_fetch_row($result); $numrows = $query_data[0]; echo "count: ".$numrows; $lastpage = ceil($numrows/$rows_per_page); //determines how many pages based on rows divided by rows per page echo "pages: ".$lastpage; // Get required page number. If not present, default to 1. if (isset($_GET['pageno']) && is_numeric($_GET['pageno'])) {$pageno = $_GET['pageno']; } else {$pageno = 1; } //Checks that the value of $pageno is an integer between 1 and $lastpage. $pageno = (int)$pageno; if ($pageno > $lastpage) {$pageno = $lastpage; } if ($pageno < 1) {$pageno = 1; } //constructs OFFSET for the sql SELECT statement $offset = ($pageno - 1) * $rows_per_page; //This checks to see if there are at least 2 chars in the last name. if (strlen($lnamesearch)<2) { echo "<p class='style7'>Please enter at least 2 letters of the last name.</p>"; exit; } else //sets the query to get the number of rows { $query = "SELECT * FROM BKL_TRANSACTIONS WHERE((PLAYER_LNAME LIKE '$lnamesearch%')& (PLAYER_FNAME LIKE '$fnamesearch%')) LIMIT $offset, $rows_per_page"; } $result = mysql_query($query) or die ("Could not execute the query"); //executes the query //Count the number of results $numrows=mysql_num_rows($result); echo "<p class='style7'>Your search: "".$fnamesearch." ".$lnamesearch."" returned <b>".$numrows."</b> results.</p>"; if ($numrows == 0) //if no matches, don't display the table exit; else //build the table and insert rows { echo "<table border=1 cellspacing=0 cellpadding=1 width='77%' align=left bordercolor=#666666>"; echo "<tr bgcolor=#cccc99 class='style5'><th width='10%' class='style5'>Date</th>"; echo "<th width='10%' class='style5'>Action</th>"; echo "<th width='12%' class='style5'>From</th>"; echo "<th width='12%' class='style5'>To</th>"; echo "<th width='5%' class='style5'>Pos</th>"; echo "<th width='18%' class='style5'>Name</th>"; echo "<th width='5%' class='style5'>Round</th></tr>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td width='10%' class='style6'>".$row['TRANS_DT']."</td>"; echo "<td width='10%' class='style6'>".$row['TRANS_ACTION']."</td>"; echo "<td width='12%' class='style6'>".$row['FROM_OWNER']."</td>"; echo "<td width='12%' class='style6'>".$row['TO_OWNER']."</td>"; echo "<td width='5%' class='style6'>".$row['POSITION']."</td>"; echo "<td width='18%' class='style6'>".$row['PLAYER_FNAME']." ".$row['PLAYER_LNAME']."</td>"; echo "<td width='5%' class='style6'>".$row['DRAFT_RND']."</td></tr>"; } /****** build the pagination links ******/ // if not on page 1, don't show back links if ($pageno > 1) { // show << link to go back to page 1 echo " <a href='{$_SERVER['PHP_SELF']}?pageno=1'><<</a> "; // get previous page num $prevpage = $pageno - 1; // show < link to go back to 1 page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$prevpage'><</a> "; } // range of num links to show $range = 3; // loop to show links to range of pages around current page for ($x = ($pageno - $range); $x < (($pageno + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $lastpage)) { // if we're on current page... if ($x == $pageno) { // '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']}?pageno=$x'>$x</a> "; } // end else } // end if } // if not on last page, show forward and last page links if ($pageno != $lastpage) { // get next page $nextpage = $pageno + 1; // echo forward link for next page echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$nextpage'>></a> "; // echo forward link for lastpage echo " <a href='{$_SERVER['PHP_SELF']}?pageno=$lastpage'>>></a> "; } // end if /****** end build pagination links ******/ echo "</table>"; } mysql_free_result($result); //release the result set from the table mysql_close($conn); //close the connection to the db ?> MOD EDIT: [code] . . . [/code] tags added. |