How to paginate a form in php? - php

I have a problem. Last time, I made a grading system for teachers. I have a form for grading teachers but I am confused on how to paginate that form. If the entries are more than 10 then it causes problems.
<form action="n.php" method="post" enctype="multipart/form-data">
<table width="642" height="215" border="10" align="left" cellspacing="0" >
<tr>
<th class="style5">Teacher ID</th>
<th width="90" class="style5">Teacher Name</th>
<th width="127" class="style5">Teacher Registration</th>
<th width="135" class="style5">Teacher Qualification</th>
<th width="92" class="style5">Teacher Subject</th>
<th width="92" class="style5">Action</th>
</tr>
<?php
include 'conn.php';
$sql = "SELECT * FROM teacher ";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_array()){
$id=$row['tid'];
?>
<tr>
<td height="50" align="center" class="style5"><?php echo $row['tid'];?></td>
<td align="center" class="style5"><?php echo $row['tname'];?></td>
<td align="center" class="style5"><?php echo $row['treg'];?></td>
<td align="center" class="style5"><?php echo $row['qualification'];?></td>
<td align="center" class="style5"><?php echo $row['subject'];?></td>
<td align="center"> <input type="text" name="rating[<?php echo $id; ?>]">
</td>
</tr>
<?php
}
}else{
echo "<center><p><font size=10/> No Records</p></center>";
}
$conn->close();
?><tr><td colspan="6">
<input type="submit" name="submit" value="Enter"></td></tr>
</table>
</form>

In your PHP you could define a page size:
$page_size = 10; // number of teachers per page
And start at page 1:
$page = 1;
You change your SQL to use these values:
$sql = "SELECT * FROM teacher LIMIT " . $page_size * ($page - 1) . ", " . $page_size;
Now you'll only be shown 10 teachers from page 1.
You can change your script so that the page is read from the URL /yourscript.php?page=2:
$page = isset($_GET['page']) ? $_GET['page'] : 1; // take from query string or default to 1
Next step is to insert next and prev link in your html:
<?php
$next = $page + 1;
$prev = $page - 1 > 0 ? $page - 1 : 1;
echo "<a href='?page=$prev'>prev page</a>";
echo "<a href='?page=$next'>next page</a>";
You can improve your scripts by checking how many pages there is using a count of teacher records
$pages = ceil(count($teachers) / $page_size);
I think you can take it from here.
UPDATE: I've merged my suggestions with your code:
<form action="n.php" method="post" enctype="multipart/form-data">
<table width="642" height="215" border="10" align="left" cellspacing="0">
... your table stuff ...
<?php
include 'conn.php';
$page_size = 10;
// Get total pages
$sql = "SELECT COUNT(*) as cnt FROM teacher";
$result = $conn->query($sql);
$teacher_count = $result[0]["cnt"]; // I'm unsure how you DB class works;
$pages = ceil($teachers / $page_size);
$page = isset($_GET['page']) ? $_GET['page'] : 1; // take from query string or default to 1
$next = $page + 1 > $pages ? $pages : $page + 1;
$prev = $page - 1 > 0 ? $page - 1 : 1;
$sql = "SELECT * FROM teacher LIMIT " . $page_size * ($page - 1) . ", " . $page_size;
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_array()){
$id=$row['tid'];
?>
<tr>
<td height="50" align="center" class="style5"><?php echo $row['tid'];?></td>
<td align="center" class="style5"><?php echo $row['tname'];?></td>
<td align="center" class="style5"><?php echo $row['treg'];?></td>
<td align="center" class="style5"><?php echo $row['qualification'];?></td>
<td align="center" class="style5"><?php echo $row['subject'];?></td>
<td align="center"> <input type="text" name="rating[<?php echo $id; ?>]">
</td>
</tr>
<?php
}
}else{
echo "<center><p><font size=10/> No Records</p></center>";
}
$conn->close();
?><tr><td colspan="6">
<input type="submit" name="submit" value="Enter"></td></tr>
</table>
<?php
if ($next > 1) {
echo "<a href='?page=$prev'>prev page</a>";
}
if ($prev > 0 && $page !== 1) {
echo "<a href='?page=$next'>next page</a>";
}
?>
</form>

Related

Pagination is only changing the page number, not the content

I have a table with a list of users and I want to create pagination for this table.
However, when I click page number 2 the page changes but not the contents of the list of users.
<?php
session_start();
require_once "connect.php";
//Database connect
$database = #new mysqli($host, $db_user, $db_password, $db_name);
//Limit users
$start = 0;
$limit = 3;
//Question to -> Database
$sql = ("SELECT * FROM users LIMIT $start, $limit");
$adds = $database->query($sql);
//Return records
$rows = mysqli_num_rows($adds);
echo "Rows found in database.. ".$rows."<br /><br />";
if(isset($_GET['id']))
{
$id=$_GET['id'];
$start=($id-1)*$limit;
}
else{
$id=1;
}
if ($rows >= 1)
{
//the beginning of the table
echo<<<END
<table width="1000" align="center" border="1" bordercolor="#d5d5d5" cellpadding="0" cellspacing="0">
<tr>
<td width="50" align="center" bgcolor="e5e5e5"></td>
<td width="50" align="center" bgcolor="e5e5e5">IDUsera</td>
<td width="20" align="center" bgcolor="e5e5e5">NazwaUsera</td>
<td width="20" align="center" bgcolor="e5e5e5">EmailUsera</td>
<td width="20" align="center" bgcolor="e5e5e5">DataRejestracji</td>
<td width="20" align="center" bgcolor="e5e5e5">Indetyfikator grupy</td>
</tr>
<tr>
END;
}
while($score = mysqli_fetch_assoc($adds)) {
$row_score_id = $score['id'];
$row_score_user = $score['user']." ";
$row_score_register = $score['dataRes']. " ";
//continued table
echo<<<END
<td width="50" align="center"><a class="button_red" href="delete_user.php?id=''">Delete</a></td>
<td width="50" align="center">$row_score_id</td>
<td width="100" align="center">$row_score_user</td>
<td width="100" align="center"></td>
<td width="100" align="center">$row_score_register</td>
<td width="100" align="center"></td>
</tr>
END;
}
$pagnSql = ("SELECT * FROM users");
$pagnBase = $database->query($pagnSql);
$pagnRows = mysqli_num_rows($pagnBase);
$total=ceil($pagnRows/$limit);
if($id>1)
{
//Go to previous page to show previous 10 items. If its in page 1 then it is inactive
echo "<a href='?id=".($id-1)."' class='button'>PREVIOUS</a>";
}
if($id!=$total)
{
////Go to previous page to show next 10 items.
echo "<a href='?id=".($id+1)."' class='button'>NEXT</a>";
}
for($i=1;$i<=$total;$i++)
{
if($i==$id) { echo "<li class='current'>".$i."</li>"; }
else { echo "<li><a href='?id=".$i."'>".$i."</a></li>"; }
}
?>
You have to put the $start from GET
Change this
$start = 0;
To:
$start = $_GET[id];

Getting radio button value in while loop

I'm doing a simple examination program using PHP.
Here is my code for taking the quiz, it's still in testing so don't mind the design.
This is the session for the person who is taking the quiz (no problem here):
<?php
session_start ();
$_SESSION['username'];
?>
<div id="wrap">
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="myproject"; // Database name
$tbl_name="q_quiz"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['q_id'];
$sql="SELECT * FROM $tbl_name WHERE q_id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" frame="box" cellpadding="3" cellspacing="1" bgcolor="#CCFFCC">
<tr>
<td bgcolor="#CCFFCC"><h3>Quiz Info : </h3></td>
</tr>
<tr>
<td bgcolor="#CCFFCC"><strong>Quiz Name : </strong><?php echo $rows['q_name']; ?></td>
</tr>
</table>
</td>
</tr>
</table>
<font size="6">
<div style="font-weight: bold" id="quiz-time-left"></div>
<script type="text/javascript">
var max_time = <?php echo $rows['q_time'] ?>;
var c_seconds = 0;
var total_seconds =60*max_time;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
function init(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds';
setTimeout("CheckTime()",999);
}
function CheckTime(){
document.getElementById("quiz-time-left").innerHTML='Time Left: ' + max_time + ' minutes ' + c_seconds + ' seconds' ;
if(total_seconds <=0){
setTimeout('document.quiz.submit()',1);
} else {
total_seconds = total_seconds -1;
max_time = parseInt(total_seconds/60);
c_seconds = parseInt(total_seconds%60);
setTimeout("CheckTime()",999);
}
}
init();
</script>
</font>
<form action="result.php" method="post">
<?php
$score = 0;
$tbl_name2="a_quiz"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question']; ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $q_question; ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
$connection=mysql_connect('localhost', 'root','');
mysql_select_db('thesis');
$username= $_SESSION['username'];
$query6 = mysql_query("SELECT * FROM student WHERE username='$username'");
$row6 = mysql_fetch_assoc($query6);
$s_id = $row6['id'];
$name = $row6['name'];
$email = $row6['email'];
$position = $row6['position'];
?>
<input type="text" name="s_id" value="<?php echo $s_id ?>">
<input type="submit" name="submit" value="Submit Answer" class="btn">
</form>
</div>
I provided an image (I inputted two questions, this is the output of the code above):
http://i60.tinypic.com/2lu8doh.jpg
(2 is the quiz id, no problem on this, 12 near the submit button is the examiner id)
There's no problem in the code above.
My problem starts here. I am only getting the answer of the (examiner/person taking the quiz) of the question number 1 only and I already found my error.
This code below initiates when I click the submit button:
if(isset($_POST['submit']))
{
$con = mysql_connect ("localhost","root","");
if (!$con)
{
die("Error:".mysql_error());
}
mysql_select_db("myproject",$con);
}
I'm only getting the answer in the question number 1 of the examiner, because of this. It is not a loop so I'm only getting one answer even if theres 2-3 more answers.
$stud_id = $_POST['s_id'];
$quiz_id = $_POST['q_id'];
$score = 0;
$tbl_name2="a_quiz";
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$quiz_id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question=$rows['q_question'];
$question1 = $rows['answer'];
echo $q_question;
echo '<br>';
echo $question1;
echo '<br>';
if(isset($_POST[$q_question])){
$s_answer = $_POST[$q_question];
echo $s_answer;
if ($question1 == $s_answer){
$score = $score + 1;
}
}
}
echo $score;
So, for example, I got question 1 and question 2 and I selected the correct answer in number 1 I'm getting and $score++ but when my answer in question 2 is also correct is doesn't do $score++.
My problem here is: How can I get the value of radio button which I outputted them in while loop? Do I need to do a while loop for the answer too? How?
First, you are using each question as name attribute for your radio buttons, which is far from perfect. You might consider add a column to the table 'a_quiz' with a unique namespace for each question with no space in it (for instance question-one, question-two...) and call this column 'namespace'.
After this is done, you questions loop should look like this:
<?php
$score = 0;
$tbl_name2="a_quiz"; // Switch to table "forum_answer"
$sql2="SELECT * FROM $tbl_name2 WHERE q_id='$id'";
$result2=mysql_query($sql2);
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
$namespace = $rows['namespace'];
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr style='overflow:hidden; word-wrap:break-word;'>
<input type="text" name="q_id" value="<?php echo $rows['q_id'];?>">
<td bgcolor="lightgreen"><strong>Question:</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen" style="max-width: 1000px;"><?php echo $rows['q_question']; ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>A</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="a"><?php echo $rows['a'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>B</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="b"><?php echo $rows['b'] ?></td>
</tr>
<tr>
<td width="18%" bgcolor="lightgreen"><strong>C</strong></td>
<td width="5%" bgcolor="lightgreen">:</td>
<td width="77%" bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="c"><?php echo $rows['c'] ?></td>
</tr>
<tr>
<td bgcolor="lightgreen"><strong>D</strong></td>
<td bgcolor="lightgreen">:</td>
<td bgcolor="lightgreen"><input type="radio" name="<?php echo $namespace; ?>" value="d"><?php echo $rows['d'] ?></td>
</tr>
</table></td>
</tr>
<hr>
</table><br>
<?php
}
?>
Then, for the results part, use this code:
$stud_id = (int)$_POST['s_id'];
$quiz_id = (int)$_POST['q_id'];
$score = 0;
$tbl_name2 = "a_quiz";
$sql2 = "SELECT * FROM $tbl_name2 WHERE q_id='$quiz_id'";
$result2 = mysql_query($sql2);
$result = '';
while($rows=mysql_fetch_array($result2)){
$q_question = $rows['q_question'];
$question1 = $rows['answer'];
$namespace = $rows['namespace'];
$result .= $q_question;
$result .= <br>;
$result .= $question1;
$result .= <br>;
if(isset($_POST[$namespace])){
$s_answer = $_POST[$namespace];
$result .= $s_answer;
if ($question1 == $s_answer)
$score++;
}
}
$result .= $score;
echo $result;
}
?>

Displaying Records in Multiple Columns Using PHP

I'm trying to display two (2) columns instead of my current one (1) column.
My example here:
http://freeskateboardsticker.com/news/authors.php
I have rewritten the script many times, but I cannot seem to get the rows and columns to display correctly and still keep the pagination intact.
Below is my script:
<?php include_once(realpath("templates/top.php")); ?>
<?php include_once(realpath("templates/$templates/mid1.php")); ?>
<?php
$page = #$_GET["page"];
$start = #$_GET["start"];
if (!is_numeric($page) || $page < 1)
$page = 1;
if ($page == 1)
$start = 0;
else
$start = ($page * $authorsPerPage) - $authorsPerPage;
$aResult = mysql_query("select pk_alId, alEmail, alFName, alLName, alBio, alDateJoined from tbl_AdminLogins order by alFName, alLName limit $start, $authorsPerPage");
$numRows = mysql_num_rows(mysql_query("select pk_alId from tbl_AdminLogins order by alFName, alLName"));
if ($numRows > 0) {
?>
<!-- Start Authors -->
<div align="center">
<center>
<TABLE WIDTH="86%" BORDER="0" CELLSPACING="0" CELLPADDING="0">
<TR>
<TD WIDTH="100%" HEIGHT="20" COLSPAN="2" ALIGN="right" class="BodyText" VALIGN="top"><FONT COLOR="#0B75AF"> <?PHP
if ($page > 1)
$nav .= "<a href='authors.php?page=" . ($page - 1) . "'><span class='Link1'><u>« Prev</u></span></a> | ";
for ($i = 1; $i <= ceil($numRows / $authorsPerPage); $i++)
if ($i == $page)
$nav .= "<a href='authors.php?page=$i'><span class='Link4'><b>$i</b></span></a> | ";
else
$nav .= "<a href='authors.php?page=$i'><span class='Link1'>$i</span></a> | ";
if (($start + $authorsPerPage) < $numRows && $numRows > 0)
$nav .= "<a href='authors.php?page=" . ($page + 1) . "'><span class='Link1'><u>Next »</u></span></a>";
if (substr(strrev($nav), 0, 2) == " |")
$nav = substr($nav, 0, strlen($nav) - 2);
echo $nav . "<br> ";
?></FONT>
</TD>
</TR>
</TABLE>
<?php while ($aRow = mysql_fetch_array($aResult)) { ?>
<div align="center"><center>
<TABLE WIDTH="720" CELLSPACING="0" CELLPADDING="0" BORDER="0">
<TR>
<TD WIDTH="185"> <?php if ($showAuthorImages) { ?><img src="imageview.php?what=getAuthorPic&authorId=<?php echo $aRow["pk_alId"]; ?>"> <?php } ?></TD>
<TD WIDTH="5" VALIGN="top"> </TD>
<TD WIDTH="530" VALIGN="MIDDLE"><SPAN CLASS="BodyHeading1"><?PHP echo $aRow["alFName"]; ?></SPAN>
<BR><span class="Text1"><?php echo $aRow["alBio"]; ?></span><br></TD>
</TR>
<TR>
<TD COLSPAN="3"> </TD>
</TR>
</TABLE>
</center></div>
<?php } ?>
<div align="center">
<center>
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" height="20" colspan="2" align="right" valign="top">
<SPAN CLASS="Text4"><?php echo $nav . "<br> "; ?></SPAN>
<br>
</td>
</tr>
</table>
</center>
</div>
<!-- End Authors -->
<?php
} else {
// No authors found in the database
?>
<!-- StartAuthors -->
<div align="center">
<center>
<table width="96%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%" colspan="2" bgcolor="#FFFFFF" height="21">
<span class="BodyHeading">
<br>No Authors Found
</span>
<span class="Text1">
<br><br>
No authors were found in the database. Please use
the link below to return to our home page.
<br><br>
</span>
Return Home
</td>
</tr>
</table>
</center>
</div>
<!-- End Authors -->
<?php
}
?>
Do not use font tag, it is deprecated
br /> not br>
If you are writing then write all other tags also in lower case
Use some MySQLi library (PDO etc)
Do not put center and div with align center tag into while cycle
Build table rows in while cycle, not one table per one author (table beginning before while, table ending after while cycle, inside while leave onl tr/td generation)
Move your loop inside the table, to create a new row per iteration, not a new table:
<div align="center">
<center>
<TABLE WIDTH="720" CELLSPACING="0" CELLPADDING="0" BORDER="0">
<?php while ($aRow = mysql_fetch_array($aResult)) { ?>
<TR>
<TD WIDTH="185"> <?php if ($showAuthorImages) { ?><img src="imageview.php?what=getAuthorPic&authorId=<?php echo $aRow["pk_alId"]; ?>"> <?php } ?></TD>
<TD WIDTH="5" VALIGN="top"> </TD>
<TD WIDTH="530" VALIGN="MIDDLE"><SPAN CLASS="BodyHeading1"><?PHP echo $aRow["alFName"]; ?></SPAN>
<BR><span class="Text1"><?php echo $aRow["alBio"]; ?></span><br></TD>
</TR>
<TR>
<TD COLSPAN="3"> </TD>
</TR>
<?php } ?>
</TABLE>
</center>
</div>

mysql results error on php

hello below is my code for a query with submit from.. the no of rows are correctly count and show in the page and the result rows are not show in my page and show "No results found, please search again", i cant find the error on my code, can anyone help to find it..
<?
### DEBUG
$debugP = 0 ;
### END DEBUG
include 'db_connector.php';
require_once('myfunctions.php');
include('header.php');
#defauts
$maxRows_p = 10;
$pageNum_p = 0;
if (isset($_GET['pageNum_p'])) {
$pageNum_p = $_GET['pageNum_p'];
}
$startRow_p = $pageNum_p * $maxRows_p;
$limit = ' LIMIT '.$startRow_p.', '.$maxRows_p;
## Start building sql for GET varables for advanced search
###Add city
if(isset($_REQUEST['city']) && ($_REQUEST['city'] != ''))
$search[] = ' city = "'.$_REQUEST['city'].'"';
###Add State
if(isset($_REQUEST['district']) && ($_REQUEST['district'] != ''))
$search[] = ' district = "'.$_REQUEST['district'].'"';
###Add lot size
if(isset($_REQUEST['lot_size']) && ($_REQUEST['lot_size'] != ''))
$search[] = ' perches >= '.$_REQUEST['lot_size'];
$search[] = ' availibility = "0" ';
###implode to search string on ' and ';
$searchStr = #implode(' and ',$search);
$sql = 'select * FROM properties WHERE status="1" and'; ###status=1 and
$sql .= $searchStr;
###Add column sorting
if($_REQUEST['sort'] != '')
$sort = ' order by added asc ';
else
$sort = $_REQUEST['sort'];
### DEBUG
if($debugP) echo 'Advanced Search Sql<hr>'.$sql;
$error['Results'] = 'No results found, please search again';
###}
### Finished Building search sql and execting #####
$sql_with_limit = $sql . $sort . $limit;
if($debugP)
echo "<hr>Property Search with Limit SQL: $sql_with_limit";
###Perform search
$searchResults = mysql_query($sql.$sql_with_limit);
### BUILD OUTPUT ####
if (isset($_GET['totalRows_p'])) {
$totalRows_p = $_GET['totalRows_p'];
} else {
if($debugP)
echo "<hr>Property with out limit SQL: $sql $sort";
$all_p = mysql_query($sql.$sort);
$totalRows_p = mysql_num_rows($all_p);
if($debugP)
echo "<br>Result Rows $totalRows_p";
}
$totalPages_p = ceil($totalRows_p/$maxRows_p)-1;
if($debugP)
echo "<hr>Builting Query String for Limit: ";
###Build query string
foreach($_GET as $name => $value){
if($name != "pageNum_p")
$queryString_p .= "&$name=$value";
}
if($debugP)
echo $queryString_p;
?>
<div align="left" class="locText">Home<span class="locArrow"> > </span> Search Results</div>
<hr size="1" color="#666666">
<table border="0" align="center">
<tr>
<td align="center">
<?php if ($pageNum_p > 0) { ### Show if not first page ?>
< href="<?php printf("%s?pageNum_p=%d%s", $currentPage, 0, $queryString_p); ?>" class="pageLink">First</a> |
<?php } ### Show if not first page ?>
<?php if ($pageNum_p > 0) { ### Show if not first page ?>
< href="<?php printf("%s?pageNum_p=%d%s", $currentPage, max(0, $pageNum_p - 1), $queryString_p); ?>" class="pageLink">Previous</a> |
<?php } ### Show if not first page ?>
<?php if ($pageNum_p < $totalPages_p) { ### Show if not last page ?>
< href="<?php printf("%s?pageNum_p=%d%s", $currentPage, min($totalPages_p, $pageNum_p + 1), $queryString_p); ?>" class="pageLink">Next</a> |
<?php } ### Show if not last page ?>
<?php if ($pageNum_p < $totalPages_p) { ### Show if not last page ?>
< href="<?php printf("%s?pageNum_p=%d%s", $currentPage, $totalPages_p, $queryString_p); ?>" class="pageLink">Last</a>
<?php } ### Show if not last page ?>
</td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pageText" >Showing: <strong><?php echo ($startRow_p + 1) ?> to <?php echo min($startRow_p + $maxRows_p, $totalRows_p) ?> of <?php echo $totalRows_p ?></strong> Listings</td>
<td align="right" class="pageText"></td>
</tr>
</table></td>
</tr>
<tr>
<td height="5">xx</td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="1" cellpadding="4" class="resBorder">
<tr>
<td class="colText">Address</td>
<td class="colText">City</td>
<td class="colText">ST</td>
<td class="colText">Price</td>
<td class="colText">Beds</td>
<td class="colText">Baths</td>
<td class="colText">Sqft</td>
</tr>
<?php while($row_p = #mysql_fetch_assoc($searchResults)) { ?>
<tr valign="top">
<td class="bodytext"><?php echo $row_p['address']; ?></td>
<td class="bodytext"><?php echo $row_p['city']; ?></td>
<td class="bodytext"><?php echo $row_p['district']; ?></td>
<td class="bodytext"><?php echo Money($row_p['price'],1); ?></td>
<td class="bodytext"><?php echo $row_p['rooms']; ?></td>
<td class="bodytext"> </td>
<td class="bodytext"><?php echo $row_p['floor']; ?></td>
</tr>
</table></td>
</tr>
<? } ?>
</table></td>
</tr>
<tr>
<td height="5">xx</td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="pageText"> </td>
<td align="right"></td>
</tr>
</table></td>
</tr>
</table>
<p> </p>
<?
## if no results where found
if(#mysql_num_rows($searchResults)<=0){
foreach($error as $name => $value)
print '<div align=center class="error">'.$name . ': ' . $value.'</div>';
}
##Fetch Footer
?>
<script>
document.getElementById('loading').style.display = 'none';
</script>
Try changing:
###Perform search
$searchResults = mysql_query($sql.$sql_with_limit);
To:
###Perform search
$searchResults = mysql_query($sql_with_limit);

Multiple pages PHP how?

Here I have a problem in this code ..
I want to specify the 4 values in each page ..
But I can not ... So far there is a problem, I think, in limit
<?php
if ( !isset( $_GET["page"] ) )
{
$page = 1;
include( "connect.php" );
} else {
$page = intval( $_GET['page'] );
}
$max = 4;
$from = ($max * $page) - $max;
$sql = mysql_query( "
select *
from uploads
, members
, rooms
where uploads.MemberID = members.MemberID
and uploads.RoomID = rooms.RoomID
and UploadCategory = 'L'
order by UploadID desc
limit $from, $max
");
$num_sql = mysql_num_rows( $sql );
$pages = ceil( $num_sql / $max );
$num = mysql_num_rows( $sql );
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<form name="form1" method="post" action="">
<div align="center">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF">
<p align="center"><font size="4"> file</font>
</td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF">#</td>
<td align="center" bgcolor="#FFFFFF"><strong>member</strong></td>
<td align="center" bgcolor="#FFFFFF"><strong> Name</strong></td>
</tr>
</table>
</div>
</form>
</td>
</tr>
<?php while( $row = mysql_fetch_array( $sql ) ) : ?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $row['UploadID']; ?>"></td>
<td bgcolor="#FFFFFF"> <?php echo $row[MemberName]. "<br />"; ?></td>
<td bgcolor="#FFFFFF"> <?php echo $row[UpoadName]."<br />"; ?></td>
</tr>
<?php endwhile; ?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="delete"></td>
</tr>
</table>
<?php
if ( $page > 1 )
{
$prev = $page - 1;
echo "prev";
}
for ( $i = 1; $i <= $pages; $i++ )
{
echo ( $page == $i )
? " [$i] "
: " $i ";
}
if ( $page < $pages )
{
$next = $page+1;
echo "next";
}
?>
</html>
thanks a lot
EDIT
Further details
alt text http://up.arab-x.com/Mar10/Xjq83483.jpg
I want to the code as in the picture ..
So that if you click on the number 1 to turn to a new page containing the values 4 and No. 2 if you also turn to a new page containing the 4 other values and so on.
What is wrong with this code even shows me output as in the picture
(((Can anyone help me how can I make code works like the picture ..... Please ... Please
Code works, but not like what I want))))))
Also :
if(!isset($_GET["page"]))
{
$page=1;
include ("connect.php");
}
else
{
$page= intval($_GET['page']);
}
You include the 'connect.php' script only when the page isn't specified in the query string. Is this correct?
Try using the dictionary with quotes and correct spelling:
echo $row['MemberName']
echo $row['UploadName']
For any better answer, you'd need to include some more information, like Felix already commented...
One major problem I'm seeing in this code is that include ("connect.php"); is inside the if(!isset($_GET["page"])) - but you're running mysql_query regardless.

Categories