PHP - Pagination For A Single Record
I am having a problem applying pagination to my page when I only have one record displayed. I would like to have it set up to where one record is followed by the next one in the list. I have tried several ways but they are for whole tables moving to the next page. I think I am missing something small but not sure. Any help will be greatly appreciated, thanks.
Similar TutorialsHi, I've been scratching my head for a while now about how to do this, I'm relatively new to php and mysql and perhaps foolishly taking on creating a user area for a website. I have everything else working, all of my register account functions and confirmations and all of the login scripts etc. I have created a profile page which returns various information to the user (this bit works fine) and I've got some nice show/hide toggles running with some javascript/css but my intention is to allow the user to change thier information (e-mail address, contact phone number and also whether they are subscribed to the e-mail list), it also displays any support tickets or messages. So after the long intro, here's what I'm struggling with... I have a form in a visibility toggled <div> which submits a 'change_email' script, so a user wants to change their e-mail, clicks on change, the <div> appears, they bang in the new e-mail and hit submit. My php script appears to work (because it doesn't throw up any errors), until you realise that actually it's not updated the record in the db... I'm using mysql_query("UPDATE users SET email='$new_email' WHERE username='$user'"); Do I need to setup variables for all of the information in the db (name, username, password, email, contno etc etc) and include them in the command to get it to work or should that just pick the correct record and then update it? If that is the case is there a way I can include 'blank' variables so I don't have to set them all up... e.g. mysql_query("UPDATE users SET user='',password='',email='$new_email', etc WHERE username='$user'"); Many thanks in anticipation How to pull just I record of a column out of the 20 columns? This is not showing the results. $SomeVar = 'pets'; $query = "SELECT field1 FROM db1 WHERE id1 = '".$SomeVar."'"; $results=mysql_query($link); echo $link; Hi.
I have a product database w/ tables each for product series, model, sub-model and optionals. One item in each of these makes up one product. So Series K, Model 7, sub-model 2, optional 3 will be a product called K 7/2-3 .The permutations and combinations of these are all possible products.
In the same db, I have a quotations table. Each quotation has a unique id / record. A quotation can include any number of products : it can have K 7/2-3, KA 561/1-2 , FPN 311/2-1 or it can only have KA 561/1-2 etc.
Now I am stuck. Don't know how to
a. structure the quotations table
b. create a MySQL select so that one statement can make multiple selections . I thought of using a checkbox but that doesn't work either since the series/model/sub model/optionals must chosen sequentially.
Any ideas I can follow thru ?
Many thanks
Swati
Hi I have a results page from a MySQL query and I have implemented pagination to present data in chunks of 25 per page in a table view (each row => 1 entry). My problem is that next to each data row, I have a selection checkbox, and if the user clicks on it, he can download the selected entries. This thing worked OK before I employed paginated view, when I presented all data in one page. Now, if I select e.g. 2 entries in page 1, then I jump to page 12 and select another 2 entries, if I click on the "Retrieve" button, I get only the last 2 entries (from the last page visited). How can I solve this problem? With JS? Can I use PHP only? PHP script return 20Â UL LISTÂ values like, < ul >
A < /ul > How to display UL LIST into row wise 5 columns like
A B C D I'm trying to update records in a Db. I have a record called "classOffering" and I have associated records for that offering called "classSessions". You have 1 classOffering for 1 to 6 classSessions. The process I use has the user create the classOffering and say how many classSession there will be then I create how ever many sessions they say. I then display the classSessions so they can be edited and updated in the Db. I can't seem to update and set more than one record even though there are more. I know I need to use a while or foreach statement, but I can't seem to do it. Here's my code so far: $sessSet = "UPDATE classSessions SET startDate= '$startDate', startTime= '$startTime', time= '$time' WHERE classSessions.sessionId = $sessionId "; Thanks for any help. Is it no problem to give the SUM of integers in a column, but is it also possible to give the SUM of integers in a record (automatically)?
My form has 40 fields, and I want to re-generate it to be reviewed as it was when submitted. Next, I want to be able to UPDATE the forms values, where necessary. Is there an easy way to UPDATE the entire form from the reviewable version. Is it smarter to update ONLY the specific items that need modification? Any examples would be helpful. Hi Guys, I appreciate your help! What I am doing is making a Choose Your Own Adventure Game and what I would like to do is the following. Record the moves of the person Put those moves on a page telling them their - say - 5 latest games Record the time it took them to complete the adventure Record that in a High Score database I know that I will need to employ the use of MYSQL databases and PHP, but I'm a total noob! Any help would be greatly appreciated! ~ Jack Code: [Select] $sql = "SELECT poster_id from phpbb_posts WHERE topic_id = ".$topic_id." "; $result = $db->sql_query($sql); //same as mysql_query $row = $db->sql_fetchrow($result); // same as mysql_fetch array. var_dump($row); With this code (i commented the query function for you) im getting Code: [Select] array 'poster_id' => string '59' (length=2) When I run this into SQL in phpmyadmin I'm getting Code: [Select] 59 56 //this is what I want I need to get all of the records, not just the first one. I have even tried using replacing the function with mysql_query and mysql_fetch_array any ideas? It's a bit late, so I may just be making a simple mistake. Thanks! Hey, I'm trying to check if a username is unique, but for some reason none of the methods that I've looked up seem to work. I'm aiming for the code to check if a username is unique, and if get the user to input the name again. $get = "SELECT `i` FROM `m` WHERE `i`=\"$r\""; $checkResults = mysql_query($getRandomness); while(mysql_num_row($checkResults) > 0) { //some code... //check again $get = "SELECT `i` FROM `m` WHERE `i`=$r"; $checkResults = mysql_query($get); } The error comes from the while line, but it comes up during the first check because the record is empty. This is the error: "Fatal error: Call to undefined function mysql_num_row()" I'm having an issue updating a records. The insert and delete functions are working fine. The $submit variable is being passed 'Update' ~ that is working. This is some extremely old code that has migrated to a new server and is no longer working. Code: [Select] <?php $id = $_GET["id"]; $delete = $_GET["submit"]; $sortorder = $_POST["sortorder"]; $name = $_POST["name"]; $content = $_POST["content"]; $submit = $_POST["submit"]; require'../include/maindb.php'; if($submit=="Submit") { $sql="INSERT INTO biography (id, sortorder, name, content) VALUES (NULL, '".$sortorder."', '".nl2br(addslashes(trim($name)))."', '".htmlentities(addslashes(trim($content)))."')"; } if ($submit == "Update") { $sql="UPDATE biography SET sortorder='".$sortorder."', name='".nl2br(addslashes(trim($name)))."', content='".htmlentities(addslashes(trim($content)))."' WHERE id='".$id."'"; } if ($delete=="Delete") { $sql="DELETE FROM biography WHERE id='".$id."'"; } mysql_query($sql); echo(mysql_error()); header('Location: index.php'); ?> Hi guys, Doing a small project and i'm pretty new to php/mysql so hoping someone can help. Also i wasn't sure if this should be in php section or mysql, so apologises if it's in the wrong section. Basically... I have a form with a table in it with the fields (id, model, current stock level, new stock level) The table is populated using a mysql query to get the data from 1 table in a database. In the new stock column there's a simple text box to put a number in. Sooo like (ID) (Model) (current stock level) (new stock level) 1 AAA 3 [ ] 2 BBB 1 [ ] 3 CCC 4 [ ] A user will then put a new number in the 'new stock level' text box and when it gets submitted the new number replaces the number in 'current stock level' Basically i know how to do it if it was just the one record, but how do i get it to update all the ones with numbers in the new stock level column at the same time, and ignore it if it doesn't have anything entered in the text box? appreciate any help! thanks! sir i m new in php i need some help i want to go next record by clicking subbmit button here is my code: <?php mysql_connect('localhost','root',''); mysql_select_db('exam'); $sql="select * from examination"; $result=mysql_query($sql); echo $result; echo"<table><tr>"; $i = 1; while ($row = mysql_fetch_assoc($result)) { if(isset($_POST['bttn'])) { // here i want to go next record echo "<td>"; echo $row['qid']; echo "</td>"; print "</tr>"; $i++; } } Please help me I currently have a list of host addresses. I need to get the mx records for them. I was looking at the documentation, and found the getmxrr(). Would that send back the mx record, or just true if it has one? New to php so I'm having trouble with deleting a record from my php table. This is my code for my page where the records are being displayed. I have a delete statement that is not working properly. Also, I was thinking maybe I need a array to delete records? Please help! Code: [Select] <?php require_once('database.php'); session_start(); if (isset($_POST['add_grade'])) { $query = "INSERT INTO grades (student_id, grade_type, grade_name, grade_points) "; $query .= "VALUES (:student_id, :grade_type, :grade_name, :grade_points) "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $_SESSION['student_id']); $statement->bindValue (':grade_type', $_POST['grade_type']); $statement->bindValue (':grade_name', $_POST['grade_name']); $statement->bindValue (':grade_points', $_POST['grade_point']); $statement->execute(); $statement->closeCursor(); if (isset($_POST['remove'])) { foreach($_POST['delete'] as $delete_id) { $query = "DELETE FROM grades WHERE grade_id = $delete_id"; mysqli_query($dbc, $query) or die ('can\'t delete user'); } } } ?> <!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>View Course Grades</title> <link rel="stylesheet" type="text/css" href="main.css" /> </head> <body> <?php $student_name = $_SESSION['student_name']; $student_id = $_SESSION['student_id']; $query = "SELECT * FROM grades WHERE student_id = :student_id "; $statement = $db->prepare($query); $statement->bindValue (':student_id', $student_id); $statement->execute(); $grades = $statement->fetchAll(); $statement->closeCursor(); echo "<h1>Show Grades for $student_name </h1>"; foreach ($grades as $grade) { echo $grade['grade_type'] . " " . $grade['grade_name']. " " . $grade['grade_points'] . "<br />"; } $query = "select*from se266"; $result = mysql_query($dsn, $query); while($row = mysql_fetch_array($result)) { echo '<input type="checkbox" value="' .$row['grade_id'] . '"name="delete[]" />'; echo ' ' .$row['grade_type']; echo ' ' .$row['grade_name']; echo '<br />'; } ?> <div id="content"> <!-- display a table of products --> <table> <tr> <th>Grade Type</th> <th>Grade Name</th> <th>Grade Points</th> <th>Remove</th> </tr> <?php foreach ($grades as $grade) : ?> <tr> <td><?php echo $grade['grade_type']; ?></td> <td><?php echo $grade['grade_name']; ?></td> <td><?php echo $grade['grade_points']; ?></td> <td><form action="grades.php" method="post"> <input type="submit" name="remove" value="Delete" /> </form></td> </tr> <?php endforeach; ?> </table> </div> </div> <div id="footer"> </div> <form name="grades" method="post" action="grades.php"> <p>Grade Type<SELECT NAME="grade_type"> <OPTION VALUE="Mid-Term">Mid-Term <OPTION VALUE="Final">Final <OPTION VALUE="Lab">Lab </SELECT> <br> Grade Name:<input type="text" name="grade_name" value=""><br /> Grade Points:<input type="text" name="grade_point" value=""> <input type="submit" name="add_grade" value="Add Grade"> </form> </table> </body> </html> Hi guys
I am using the code below to show distinct months using one query then for each month I am trying to show a list of fixtures for the month, the problem I have is only one month is showing.
where am i going wrong?
<?php //find distinct months $sql="SELECT DISTINCT MONTH( match_date ) AS MONTH FROM tbl_fixtures WHERE season_id =$current_season UNION SELECT DISTINCT MONTH( match_date ) AS MONTH FROM tbl_gp WHERE season_id =$current_season"; $result=mysqli_query($dbConn, $sql); if(mysqli_num_rows($result)>0){ while($row=mysqli_fetch_assoc($result)){ $month=$row['MONTH']; echo '<div class="fixtureMonth"> <h2>'.$months[$month].'</h2> </div> <div class="fixtures">'; //find fixtures for month $sql="SELECT Opposition, match_date, competition, tbl_clubs.club_name AS club, image, HomeAway, team, opposition_points, points FROM tbl_fixtures INNER JOIN tbl_clubs ON tbl_fixtures.club = tbl_clubs.club_id WHERE season_id =$current_season and MONTH(match_date)=$month UNION SELECT Opposition, match_date, \"SGP\" AS competition, \"SGP\" AS club, \"sgp.png\" AS image, \"\" as HomeAway, \"\" as team, \"\" as opposition_points, points FROM tbl_gp WHERE season_id =$current_season and MONTH(match_date)=$month ORDER BY match_date"; $result=mysqli_query($dbConn,$sql)or die(mysqli_error($dbConn)); if(mysqli_num_rows($result)==0){ echo no_fixtures_found; } else{ echo '<table class="fixturesTable">'; while($row=mysqli_fetch_assoc($result)){ echo'<tr> <td>'.date("d-M-Y",strtotime($row['match_date'])).'</td> <td><img src="'.$shopConfig['url'].'images/'.$row['image'].'"/></td> <td>'.$row['Opposition'].'</td> <td>'.$row['HomeAway'].'</td> <td><b>'.$row['team'].'</b>-'.$row['opposition_points'].'</td> <td>'.$row['team'].'</td> </tr>'; } echo '</table>'; } echo '</div>'; } } ?> Hi, I have a simple mySQL database and I would like to update using a simple html form. One of the field is "accepted" and is type "boolean". I have a texbox where I will write the record id and another button which will change the "accepted" value from 0 to 1 for that record id. The problem is that I don't know how to start.... Thanks in advance Sergio Hey Guys, Im slowly updating our website to php/mysql, im getting there slowly but stuck at the minute. Im try to create a form where we can edit one of the pages text and then update the text in the database if that makes sense Basically at the moment i have a form where you can see the pages text like so: <table width="400" border="0" align="center" cellpadding="3" cellspacing="1"> <tr> <td><strong>Edit About Us English </strong></td> </tr> </table> <table width="400" border="0" align="center" cellpadding="0" cellspacing="1"> <tr> <td><form name="form1" method="post" action="send_update_english.php"> <table width="100%" border="0" cellspacing="1" cellpadding="3"> <tr> <td>Detail</td> <td>:</td> <td><textarea name="detail" cols="50" rows="4" id="detail"> [b]<?php mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); $result = mysql_query("SELECT body FROM aboutenglish WHERE ID = '1'"); $row = mysql_fetch_array( $result ); echo nl2br($row['body']); ?>[/b] </textarea></td> </tr> <tr> <td> </td> <td> </td> <td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td> </tr> </table> </form> </td> </tr> </table> Ive got that php bit in the middle to pull out the text thats on that page but not sure if thats correct or not. But anyways on the 'send form' page i have: <?php // Details [b]$message="$detail";[/b] mysql_connect("localhost", "web148", "123") or die(mysql_error()); mysql_select_db("web148") or die(mysql_error()); mysql_query("SET names 'utf8'"); $result = mysql_query("UPDATE aboutenglish SET body = '$message' where ID = '1'"); ?> the update query works if i put text in there, but when i use '$message' the database is left blank. This is only my second week doing all this stuff, so bare with me I appreciate your answers. <?php if (session_status() == PHP_SESSION_NONE) { session_start(); } require_once 'functions.php'; $dbh = mysql_connection(); $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $_FILES["file"]["name"]); $extension = end($temp); if ( ( ($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png") ) && //($_FILES["file"]["size"] < 20000) && in_array($extension, $allowedExts)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br>"; echo "Type: " . $_FILES["file"]["type"] . "<br>"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; $objDateTime = new DateTime('NOW'); $created = $objDateTime->format("Y-m-d H:i:s"); $modified = $objDateTime->format("Y-m-d H:i:s"); $title = $_FILES["file"]["name"]; $photo_url = "upload/" . $_FILES["file"]["name"]; $user_id = $_SESSION['id']; $username = $_SESSION['username']; $sql = 'insert into p_photos(title,photo_url,user_id,username,created,modified) values(:title,:photo_url,:user_id,:username,:created,:modified)'; $sth = $dbh->prepare($sql); $rt = $sth->execute(array(':title' => $title, ':photo_url' => $photo_url, ':user_id' => $user_id, ':username' => $username, ':created' => $created, ':modified' => $modified)); } } } else { echo "Invalid file"; } ?>File is uploaded in upload folder correctly. What's wrong with prepare and execute statement? What can be the reason not inserting record? What's the way to debug php pdo query? Edited by php-coder, 31 May 2014 - 10:20 PM. |