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.
Related
I am learning PHP. I tried building a script that shows records from MySQL by pagination.
I set the code to show 1 record per page. There are 4 records or matches on the MySQL table for the recipient 'admin123'. I have logged-into this account.
And so, this pagination script should pull 4 records to show me. 1 record per page. Total 4 pages. It gives echo 2 results found (it should show 4). And then only shows 1 record on the page as expected. But, I do not see the pagination section. No links to the other pages are getting shown like this:
Page 1234.
I am confused now. Please take a look and let me know where I am going wrong.
<?php
declare(strict_types=1);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
include 'configurations.php';
if (!$conn)
{
$error = mysqli_connect_error();
$errno = mysqli_connect_errno();
print "$errno: $error\n";
exit();
}
else
{
//Get Page Number. Default is 1 (First Page).
$page_number = $_GET["page_number"];
if ($page_number == "")
{
$page_number = 1;
}
$sender_username = $mod; //$mod defined in configurations.php
$recipient_username = $user;
$links_per_page = 1;
$max_result = 30;
$offset = ($page_number*$links_per_page)-$links_per_page;
$query_1 = "SELECT COUNT(*) FROM messages WHERE recipient_username = ?
AND sender_username = ? ORDER BY id LIMIT ? OFFSET ?";
$stmt_1 = mysqli_prepare($conn,$query_1);
mysqli_stmt_bind_param($stmt_1,'ssii',$recipient_username,$sender_username,$ links_per_page,$offset);
mysqli_stmt_execute($stmt_1);
$result_1 = mysqli_stmt_bind_result($stmt_1,$matching_rows_count);
mysqli_stmt_fetch($stmt_1);
mysqli_stmt_free_result($stmt_1);
$total_pages = ceil($matching_rows_count/$links_per_page);
$query_2 = "SELECT id,date_and_time,recipient_username,sender_username,warning_messages FROM
messages WHERE recipient_username = ? AND sender_username = ? ORDER BY id
LIMIT ? OFFSET ?";
$stmt_2 = mysqli_prepare($conn,$query_2);
mysqli_stmt_bind_param($stmt_2,'ssii',$recipient_username,$sender_username,$links_per_page,$offset);
mysqli_stmt_execute($stmt_2);
$result_2 = mysqli_stmt_bind_result($stmt_2,$id,$date_and_time,$recipient_username,$sender_username,$warning);
mysqli_stmt_fetch($stmt_2);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional/EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1" http-equiv=" content-type">
<title><?php echo "$site_name User $user Warnings in $server_time time."; ?>
</title>
</head>
<body>
<br>
<p align="center"><span style="font-weight:bold;"><?php echo "$site_name
User $user Warnings in $server_time time."; ?></span></align>
<br>
<br>
<table width="1500" border="0" cellpadding="5" cellspacing="2"
bgcolor="#666666">
<?php if(!$stmt_2)
{
?>
<tr>
<td bgcolor="#FFFFFF">No record found! Try another time.</td>
</tr>
<?php
}
else
{
if(($offset+1)<=$max_result)
{
printf("<b> %d Result Found ...</b>\n",$matching_rows_count); ?><br>
<br>
<tr name="headings">
<td bgcolor="#FFFFFF" name="heading_submission-
number">Submission Number</td>
<td bgcolor="#FFFFFF" name="heading_date-and-
time">Date & Time in <?php echo "$server_time" ?></td>
<td bgcolor="#FFFFFF" name="heading_recipient-
username">To</td>
<td bgcolor="#FFFFFF" name="heading_sender-
username">From</td>
<td bgcolor="#FFFFFF" name="heading_warning">Warning</td>
</tr>
<tr name="user-details">
<td bgcolor="#FFFFFF" name="submission-number"><?php
printf("%s",$id); ?></td>
<td bgcolor="#FFFFFF" name="date-and-time"><?php
printf("%s",$date_and_time); ?></td>
<td bgcolor="FFFFFF" name="recipient-username"><?php
printf("%s",$recipient_username); ?></td>
<td bgcolor="#FFFFFF" name="sender-username"><?php
printf("%s",$sender_username); ?></td>
<td bgcolor="#FFFFFF" name="warning"><?php printf("%s",$warning); ?>
</td>
</tr>
<?php
while(mysqli_stmt_fetch($stmt_2))
{
?>
<tr name="user-details">
<td bgcolor="#FFFFFF" name="submission-number"><?php
printf("%s",$id); ?></td>
<td bgcolor="#FFFFFF" name="date-and-time"><?php
printf("%s",$date_and_time); ?></td>
<td bgcolor="#FFFFFF" name="recipient-username"><?php
printf("%s",$recipient_username); ?></td>
<td bgcolor="#FFFFFF" name="sender-username"><?php
printf("%s",$sender_username); ?></td>
<td bgcolor="#FFFFFF" name="warning"><?php
printf("%s",$warning);
?></td>
</tr>
<?php
?>
<tr name="pagination">
<td colspan="10" bgcolor="#FFFFFF"> Result Pages:
<?php
if($page_number < $total_pages)
{
for($i=1;$i<=$total_pages;$i++) //Show Page Numbers in
Serial.
echo "<a href=\"{$_SERVER['PHP_SELF']}?
user=$user&page_number={$i}\">{$i}</a> ";
}
else
{
for($i=$total_pages;$i>=1;$i--) //Show Page Numbers in
Reverse.
echo "<a href=\"{$_SERVER['PHP_SELF']}?
user=$user&page_number={$i}\">{$i}</a> ";
}
?>
</td>
</tr>
<?php
}
}
}
?>
</table>
<br>
<br>
<p align="center"><span style="font-weight:bold;"><?php echo "$site_name
User $user Warnings in $server_time time."; ?></span></align>
<br>
</div>
<br>
</body>
</html>
<?php
mysqli_stmt_free_result($stmt_2);
mysqli_stmt_close($stmt_2);
mysqli_close($conn);
}
?>
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>
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>
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);
I've noticed that the first condition does not work
if (empty($ss)) {
echo "please write your search words";
}
but the second does
else if ($num < 1) {
echo "not found any like ";
Full code:
<?php
require_once "conf.php";
$ss= $_POST["ss"];
$sql2=("SELECT * FROM student WHERE snum = $ss");
$rs2 = mysql_query($sql2) or die(mysql_error());
$num = mysql_num_rows($rs2);
if (empty($ss)) {
echo "please write your search words";
}
else if ($num < 1 ) {
echo "not found any like ";
}else {
$sql=("SELECT * FROM student WHERE snum = $ss ");
$rs = mysql_query($sql) or die(mysql_error());
while($data=mysql_fetch_array($rs)) {
?>
<div id="name">
<table align="center" border="3" bgcolor="#FF6666">
<tr>
<td><? echo $data ["sname"]." "."نتيجة الطالب"; ?></td>
</tr>
</table>
</div>
<div id="ahmed">
<table width="50%" height="50" align="center" border="2px" bgcolor="#BCD5F8">
<tr>
<td width="18%"><strong>جيولوجي</strong></td>
<td width="13%"><strong>تاريخ</strong></td>
<td width="13%"><strong>رياضة</strong></td>
<td width="14%"><strong>عربي</strong></td>
<td width="12%"><strong>علوم</strong></td>
<td width="30%"><strong>المادة</strong></td>
</tr>
<tr>
<td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td>100</td>
<td><strong>الدرجة النهائية</strong></td>
</tr>
<td><? echo $data['geo']; ?></td>
<td><? echo $data['snum']; ?></td>
<td><? echo $data['math']; ?></td>
<td><? echo $data['arab']; ?></td>
<td><? echo $data['history']; ?></td>
<td><strong>درجات الطالب</strong></td>
</tr>
<tr>
<td colspan="5" align="center" valign="middle">
<? $sum= $data['geo'] + $data['snum'] +
$data['math'] + $data['arab'] +
$data['history'];
echo $sum ;
?>
</td>
<td><strong>مجموع الدرجات</strong></td>
</tr>
<tr>
<td colspan="5" align="center">
<?
$all=500 ;
$sum= $data['geo'] + $data['snum'] +
$data['math'] + $data['arab'] +
$data['history'];
$av=$sum/$all*100 ;
echo $av."%" ;
?>
</td>
<td><strong>
النسبة المئوية
</strong></td>
</tr>
</table>
</tr>
</div>
<?
}
};
The full code link is:
http://www.mediafire.com/?2d4yzdjiym0
Are you sure that $ss isset? i.e. there is a POST variable with the name ss. you could test it with.
if (empty($ss) || !isset($ss)) {
echo "please write your search words";
}
or test for it when you read in the post var
if ((!isset($_POST["ss"]) || (!is_numeric($_POST["ss"])))
{
$ss = 0;//empty considers 0 as been empty
}
else
{
$ss = $_POST["ss"];
}
ss looks to be a number too, so checking if it is numeric using is_numeric will help stop SQL errors, if for some reason it is not.
Use
if (!isset($ss)) {
echo "please write your search words";
}
instead of
if (empty($ss)) {
echo "please write your search words";
}
Try changing the condition to
if(empty($_POST['ss'])){ ... }
and continue using $_POST['ss'] instead of $ss.
BTW Always use error_reporting(E_ALL) when developing.
$sql=("SELECT * FROM student WHERE snum = $ss ");
Remove the brackets in the variables ($sql1 and $sql2) that have your query
It should be
$sql="SELECT * FROM student WHERE snum = $ss ";
I think that's why its telling you that you have an error near ...