Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I have created a form whose method is "POST" and action is "#", indicating to send the data to the same page.
Now after submitting the form,
A second form appears below which fetches data(according to the selection on first form) from database and gives the user a control to edit the record.
EVERYTHING IS WORKING GOOD AND WELL
The only problem is "*Second form submit button doesn't show up"
My Code of that particular page:(editcategory.php)
<?php
require_once("admin_panel.php");
?>
<!DOCTYPE html>
<head>
<title>Users</title>
<link rel="stylesheet" href="css/footer.css">
<style>
.bodystart{
margin-top:2%;
margin-left:25%;
}
h1{
font-size:xx-large;
}
table {
border-collapse: separate;
border-spacing:5px 5px;
width: auto;
color: #588c7e;
font-family:"Lucida Console", "Courier New", monospace;
font-size: 20px;
text-align: left;
}
th {
background-color: #588c7e;
color: white;
}
option:nth-child(even) {
background-color: #f2f2f2
}
.submitnewcat{
margin-top:3%;
color:#ffffff;
padding:5px;
border-radius:10 px;
background-color:#4CAF50;
cursor:pointer;
}
form{
margin-top:5%;
}
input,select{
border-style:inset;
border-left:6px solid green;
background-color:#ced6e0;
padding: 12px 15px;
border-radius:5px;
}
.catidcont{
background-color:#c7ecee;
cursor:default;
}
label{
padding:12px 15px;
font-size:larger;
background-color:#130f40;
color:#ffffff;
border-radius:5px;
border:2px solid red;
}
</style>
</head>
<body>
<div class="bodystart">
<h1><i>Edit Category</i></h1>
<form method="POST" action="#">
<label>Select Category</label>
<?php
$sql = "SELECT * FROM category";
$result = mysqli_query($db_conn,$sql);
echo "<select name='catset' required>";
echo "<option value=''>Select</option>";
while ($row = $result->fetch_assoc()) {
echo "<option value='" . $row['id'] . "'>" . $row['name'] . "</option>";
}
echo "</select>";
?>
<button class="submitnewcat" name="submit3" type="submit" value="Submit">Fetch Details</button>
</form>
<?php
if(isset($_POST["submit3"])==true){
function validate($data){
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$x=(int)$_POST['catset'];
$sql = "SELECT * FROM category a WHERE a.id=$x";
$result = $db_conn->query($sql);
if ($result->num_rows > 0) {
$row = $result->fetch_assoc();
echo "<form method='POST' action='updatecategory.php'";
echo "<input type='hidden' readonly>";
echo "<label>Category ID</label>";
echo "<input type='number' name='catid' value=$x readonly style='cursor:no-drop;'><br><br><br>";
echo "<label>New Category Name</label>";
echo "<input type='text' name='newcatname' required placeholder='".$row['name']."'>";
echo "<label>Status</label>";
echo "<select name='newstat' required>";
if($row["status"]==1){
$catstat="Active";
echo "<option value='".$row['status']."' selected>$catstat</option>";
echo "<option value='2'>Disabled</option>";
}
else{
$catstat="Disabled";
echo "<option value='1'>Active</option>";
echo "<option value='".$row['status']."' selected>$catstat</option>";
}
echo "<button class='submigtnewcat' name='submit4' type='submit' value='Submit'>Fetch Details</button>";
echo "</form>";
}
} ?>
</div>
</body>
<?php
require_once("include/footer.php");?>
</html>
Snippet of my page
there is bug you have not close the tag of select so button is not displaying .
i hope you have got your answer .
echo "<select name='newstat' required>";
if($row["status"]==1){
$catstat="Active";
echo "<option value='".$row['status']."' selected>$catstat</option>";
echo "<option value='2'>Disabled</option>";
}
else{
$catstat="Disabled";
echo "<option value='1'>Active</option>";
echo "<option value='".$row['status']."' selected>$catstat</option>";
}
echo "</select>";
Related
I am developing an online examination system. Everything works fine but the questions are selected and displayed from question number one to the last question. I wanted to do the following:
Select the questions and display them one after the other at random.
Add a skip button so that students can skip any question they can't answer and it will be rolled back to them later.
Give a time to the answering session so that when the time is up it will stop the student.
This is my code for the question selection.
<!DOCTYPE html">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body{background-color:#f4fff8;}
#aq{
position:relative;
top:50px;
}
#st{
position:relative;
top:30px;
}
.btn{
background-color:#dedbb8;
color:#016e37;
text-shadow:3px 3px 3px gray;
box-shadow:3px 3px 3px gray;
height:40px;
text-align:center;
font-size:25px;
font-family:'Times New Roman';
font-weight:bold;
font-style:italic;
margin-top:2px;
border-radius: 2px;
}
.style8{
padding-top:5px;
font-size:20px;
}
#pt{
padding-top:20px;
}
h1{
position:relative;
color:green;
top:30px;
}
h2{
position:relative;
color:orange;
top:30px;
}
</style>
</head>
<body>
<?php
require_once("dbconnect.php");
include("header.php");
include("footer.php");
include("stdlogsession.php");
extract($_GET);
extract($_POST);
extract($_SESSION);
$student_id=$_SESSION['login_user'];
$student_id = stripslashes($student_id);
$student_id = mysqli_real_escape_string($db_conn,$student_id);
if(!empty($_GET['examid']))
{
$examid =$_GET['examid'];
}
// Selecting Database
$db = mysqli_select_db($db_conn,$mysql_database);
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
if(!isset($_SESSION['qn']))
{
$_SESSION['qn']=0;
}
if(!empty($_POST['submit'])=='Answer' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
if($ans==$row[8])
{
$remarks= "Correct";
$mark=$row[9];
} else {
$remarks= "Wrong";
$mark=0;
}
mysqli_query($db_conn,"insert into results(exam_id,student_id,quesNum,choice,remarks,mark) values ('$row[1]','$student_id','$row[2]', '$ans','$remarks','$mark')") or die(mysqli_error($db_conn));
$_SESSION['qn']=$_SESSION['qn']+1;
}
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
$examN=mysqli_query($db_conn,"select examName from exampaper where exam_id='$examid'") or die('Error: ' .mysqli_error($db_conn));
$row = mysqli_num_rows($examN);
if ($row > 0) {
$rows=mysqli_fetch_assoc($examN);
$Enam=$rows['examName'];
}
echo "<center><h1>congrats! you have successfully finished your " .$Enam."</h1></center>";
echo "<center><h2> Click <a href=instresult.php>here</a> for your results </h2></center>";
unset($_SESSION['qn']);
exit();
}
if(!empty($_POST['submit'])=='Skip' && !isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
$_SESSION['qn']=$_SESSION['qn']+1;
}
$rs=mysqli_query($db_conn,"select * from exampaper where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
$rows = mysqli_num_rows($rs);
while($rows=mysqli_fetch_row($rs))
{
echo "<center>";
echo "<table id=aq >";
echo "<tr><td>
<span class=style8>SUBJECT:</span></td>
<td class=style8>$rows[2]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION NAME:</span></td>
<td class=style8>$rows[1]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION DATE:</</span></td>
<td class=style8>$rows[3]</td>
</tr>";
echo "<tr><td>
<span class=style8>TOTAL TIME:</span></td>
<td class=style8>$rows[4]</td>
</tr>";
echo "<tr><td>
<span class=style8>INSTRUCTIONS:</span></td>
<td class=style8>$rows[5]</td>
</tr>";
echo "</table>";
echo "</center>";
}
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die(mysqli_error($db_conn));
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
unset($_SESSION['qn']);}
echo "<center>";
echo "<table id=st>";
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
echo "<form name=myfm method=post action=exam.php>";
$n=$_SESSION['qn']+1;
echo "<tR ><td id=pt><span class=style8>Quetion ". $n .": $row[3]</style></td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=A>$row[4]</td></tr>";
echo "<tr><td class=style8> <input type=radio name=ans value=B>$row[5]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=C>$row[6]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=D>$row[7]</td></tr>";
echo "<tr><td><input class=btn type=submit name=submit value='Answer'> <input align=right class=btn type=submit name=submit value='Skip'></td></tr></form>";
echo "</table>";
echo "</center>";
?>
</body>
</html>
I'm trying to embed some CSS into my PHP file. How can I properly add my CSS so that each called form will be rendered inside a black border? This is what I tried so far.
while ($ratings = mysql_fetch_array($q))
{
//This outputs the doctors's name
echo "Doctor's name:" . $ratings['doctor_name'] ."<br />";
// Retrieve the id of the doctor which was posted on
$id = $_POST['id'];
echo "<style> form { border-style: solid; border-color: #ffffff}";
//This outputs a textarea for the user to submit comments
echo "<b>Your Experience: </b>";
echo "<form method='post' action='review_doctors.php'>
<textarea name='body'></textarea>
<input type='submit' name='submit' value='Send'/>
<input type='hidden' name='id' value='$ratings[id]' />
</style>
</form>
";
echo "<br />";
}
As mentioned in the comments: "The style tag should only include styles".
?>
<style>
form {
border: 3px solid black;
}
</style>
<?php
while ($ratings = mysql_fetch_array($q)) {
echo "<form>...</form>"
}
If you would like to reuse styles you can put them in their own file and then include them on each page:
?>
<link rel="stylesheet" type="text/css" href="/path/to/mystyle.css">
<?php
// ...
I have a php array that includes inputs for posting. It uses a counter for each array record, and this counter is applied to the name of the input to be used in performing some actions with the post - this is working great.
The issue is that I would like to keep the users' existing inputs and re-populate the input fields in the array if their post doesn't pass validation.
I have done this before with static fields, simply storing the post variable and echoing it in the "value" --- but I can't figure out how to do this when working with an array. Anyone have any ideas?
$counter = 0;
echo "<form method='post'>";
echo "<table class='mainlist' width='680'>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr height='60'>";
echo "<td class='mainlist'><input type=text name=options[$counter] autocomplete=off onclick='this.select()' class='txt'></td>";
echo "</tr>";
$counter = $counter + 1;
}
echo "</table>";
Full code per request:
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$userid = $_SESSION['login_user'];
$companyid = $_POST['companyid'];
$options = $_POST['options'];
$counter = $_POST['hiddencounter'];
$runningtotal=0;
$totaloptions = array_sum($options);
$result = mysqli_query($connection, "SELECT options_balance FROM user_options_balance WHERE user_id = '".$userid."'");
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i]))
{ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else
{
$checknewcompanies = mysqli_query($connection, "SELECT company_id FROM user_company_total_invested WHERE user_id = '".$userid."' and company_id = '" .$companyid[$i]."'");
if($checknewcompanies->num_rows == 1)
{ // do nothing
}
else
{
$runningtotal = $runningtotal + 1;
}
} /* END OF ELSE IF NOT EMPTY OPTIONS */
} /* END OF FOR LOOP */
$checkcurrentcompanies = mysqli_query($connection, "SELECT company_id FROM user_company_total_invested WHERE user_id = '".$userid."'");
$countcompanies = $checkcurrentcompanies->num_rows;
$countcheck = $runningtotal + $countcompanies;
if($countcheck <= 4)
{
while($row = mysqli_fetch_array($result))
{
$balance = $row['options_balance'];
}
if ($totaloptions>$balance)
{
$notenoughoptions= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! You don't have enough options! Try investing less!</div>";
}
else
{
// loop through array
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i])){ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else {
if(!ctype_digit($options[$i]) or !is_numeric($options[$i])){
$charactercheck= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! Please enter only positive numbers to invest!</div>";
}
else {
$checkcompanies = mysqli_query($connection, "SELECT company_id FROM company_main WHERE company_id = '".$companyid[$i]."'");
if($checkcompanies->num_rows != 1)
{
$companynotexist= "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! That company doesn't exist!</div>";
}
else
{
// loop through array
for ($i=0; $i<$counter; $i++)
{
if(empty($options[$i]))
{ /* IF NO INPUT ON OPTIONS */
/* DO NOTHING */
}
else
{
$query = "INSERT INTO user_company_invested(user_id, company_id, user_company_options_invested)
VALUES($userid,$companyid[$i],$options[$i])";
mysqli_query($connection, $query);
} /* END OF ELSE IF NOT EMPTY OPTIONS */
} /* END OF FOR LOOP */
$balancecheck = mysqli_query($connection, "SELECT options_balance FROM user_options_balance WHERE user_id = '".$userid."'");
while($row = mysqli_fetch_array($balancecheck))
{
$balance2 = $row['options_balance'];
}
if($balance2 > 0)
{
header('Location: user_invest.php');
}
else
{
header('Location: user_market.php');
}
} // end company check
} //end character check
} //end empty option check
} //end loop
} /* END OF NOT ENOUGH OPTIONS CHECK */
}
else
{
$toomanycompanies = "<div style='background-color:#FF0000; border-radius: 15px; padding: 10px; color: #FFFFFF; font-size: 12px;'>Oops! You can invest in a maximum of 4 companies per week. Please choose fewer companies, or invest more in some of your existing companies!</div>";
/* echo "Maximum number of companies you can invest in is 4";
echo "<br />";
echo "Companies you already are invested in: ".$countcompanies;
echo "<br />";
echo "New companies you are trying to invest in: ".$runningtotal;
echo "<br />";
echo "Total: ".$countcheck;*/
}
} /* END OF ISSET CHECK */
else
{
}
?>
<?php
$result = mysqli_query($connection,"SELECT * from company_main");
$counter=0;
echo "<form method='post'>";
echo "<table class='mainlist' width='680'>";
while($row = mysqli_fetch_array($result))
{
echo "<tr height='60'>";
echo "<td class='mainlist' width=140 align='center'>" . "<img src='".$row['company_logo']."' width='40'/>" . "</td>";
echo "<td class='mainlist' align='left' width=390 style='font-size: 15px;'>" . $row['company_name'] . "</td>";
echo "<input type=hidden name=companyid[$counter] value=" . $row['company_id'] . " />";
echo "<td class='mainlist'><input value='{$_POST['options[$counter]']}' type=text name=options[$counter] autocomplete=off onclick='this.select()' class='txt' style=' background-color: #FCFCFC;
border: solid 1px #CCCCCC;
font-size: 12px;
padding: 5px;
height: 20px;
text-align: right;'></td>";
echo "</tr>";
$counter=$counter+1;
}
echo "</table>";
echo "<input type='hidden' name='hiddencounter' value='$counter'>";
echo "
<table>
<tr>
<td width='630' height='50'></td>
<td align='right' width='60' style='color: #848580; font-size: 20px;'>Total: </td>
<td align='right' width='40' style='color: #94D90B; font-size: 20px; font-weight: bold; padding-right:20px;'><span id='sum'>0</span></td><td width='10'></td>
</tr><tr height='20px'></tr><tr>
<td width='570' align='center' style='color: #94D90B; font-size: 12px;'>";?>
<?php echo $notenoughoptions; ?>
<?php echo $charactercheck; ?>
<?php echo $toomanycompanies; ?>
<?php echo "
</td>
<td colspan='2' width='100' align='right'><input name='userinvestoptionsdynamic' type='submit' value='Invest!'></td><td width='10'></td>
</tr>
<tr height='20px'></tr>
</table>";
echo "</form>";
?>
The correct syntax is:
echo "{$arrayname($keyname)}";
So for example echo('value=' . $_POST['options'][$counter]); becomes:
echo "value={$_POST['options'][$counter]}";
Currently I have a script that displays the data which is editable and can update the database. I have tried to enter row counts and nothing seem to work. I really like the script to make 3 columns (10 rows per column), please help.
$sql = "SELECT id, pounds FROM price_list ORDER BY id";
$i = 0;
$result = mysql_query($sql);
echo "<form name='prices' method='post' action='updateA.php'>";
while($rows = mysql_fetch_array($result))
{
echo "<body bgColor='#5F5F6B'>";
echo "<table><table border=2 cellspacing=0 cellpadding=1>";
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<td><font color='#FFFFFF'><font size='2'>DAYS {$rows['id']}: </font><font size='2'><font color='#000000'>PRICE:<input type='text' size='1' name='pounds[$i]' value='{$rows['pounds']}' ></tr>";
++$i;
}
echo "</table>";
echo "<input type='submit' value='Update Prices Band A' />";
echo "</form>";
?>
The above is the original code.
I don't really know what you're trying to do, but this code will generate a list of all the entries in the database with the ability to change them. Note that you'll have to remake your update_a.php file:
<style>
body {
background:#5F5F6B;
color:#fff;
}
</style>
<?php
$result = mysql_query("SELECT id, pounds FROM price_list ORDER BY id");
if (!$sql || mysql_num_rows($result)==0)
echo "Price list is empty";
else {
echo '<form name="prices" method="GET" action="update_a.php">'; // Change your filename!
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo 'Day '.$rows['id'].' costs ';
echo '<input type="text" name="'.$rows['id'].'" value="'.$rows['pounds'].'"/> pounds'
echo '<br/>'
$i++;
}
echo '<input type="submit" value="Update Prices Band A"/>';
echo "</form>";
}
?>
First of all many thanks to Leonard Pauli, the code worked perfectly in displaying the data but, it wouldn't update the database using my update.php. Below is the revised code and screenshot of what I was trying to archive.
Screenshot of single lined data displayed in 3 columns
<style>
body {
background:#5F5F6B;
color:#fff;
width:800px;
height:550px;
border:2px solid #bbb;
padding:20px;
float:center;
}
input[type="text"] {
width: 30px;
}
.table {
width:180px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
.header {
width:595px;
margin:1px;
border:2px solid #bbb;
padding:10px;
float:left;
}
</style>
<div class="header"><b>Price List for dates from <font color ="yellow"><?php echo "$SPA"; ?> to <?php echo "$EPA"; ?></font></div>
<?php
$dataprice = $_POST['database'];
$datesrange = $_POST['id'];
$result = mysql_query("SELECT id, pounds FROM $dataprice ORDER BY id");
echo '<form name="prices" method="POST" action="update.php">';
$i = 0;
while ($rows = mysql_fetch_array($result)) {
echo '<div class="table">Day <font color="yellow">'.$rows['id'].' </font> costs ';
echo "<input type='hidden' name='id[$i]' value='{$rows['id']}' >";
echo "<input type='text' name='pounds[$i]' value='{$rows['pounds']}' > Pounds";
echo '<br/></div>';
$i++;
}
echo "<input type='hidden' name='databases' value='$dataprice'>";
echo '<center><input type="submit" value="Update Prices"/>';
echo '<center><font color="yellow"><br><br><br>IF UPDATING PRICE BAND D, ONLY ENTER THE VALUE OF WHICH
PRICES YOU WANT TO INCREASE BY, <br>EXAMPLE: 7 DAYS, IF CURRENT PRICE IS 30, IF YOU WANT TO
CHARGE 34, ONLY ENTER 4 AND LEAVE EVERYTHING ELSE SET TO 0</b></center>';
echo "</form>";
?>
A bit of an idiot really, completely forgot about CSS styling.
I have tried a few things but cant seem to implement pagination properly, can someone point me in the right direction and give me a few code examples of how i can properly implement pagination in my code
<?php
session_start();
?>
<!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" />
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<link href="/lightbox/css/lightbox.css" rel="stylesheet" />
<link rel="stylesheet" href="img/reveal.css">
<script src="/lightbox/js/jquery-1.7.2.min.js"></script>
<script src="/lightbox/js/lightbox.js"></script>
<script src="img/jquery.min.js" type="text/javascript"></script>
<script src="img/jquery.reveal.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.0/jquery.min.js" type="text/javascript"></script>
<style type="text/css">
#divspace {
position: relative;
width: 100%;
height: 50px;
z-index: -9999;
vertical-align bottom;
}
#divspace1 {
position: relative;
width: 100%;
height: 50px;
z-index: -9999;
vertical-align: bottom;
padding-left: 400px;
}
#search1 {
position: absolute;
width: 203px;
height: 30px;
z-index: -9999;
vertical-align: bottom;
left: 832px;
top: 1px;
z-index: 9999;
}
#text1 {
position: absolute;
width: 203px;
height: 30px;
z-index: -9999;
vertical-align: bottom;
top: 13px;
z-index: 9999;
left: 268px;
font-family: Tahoma, Geneva, sans-serif;
font-weight: bold;
color: #FFF;
font-style: italic;
font-size: 22px;
}
#apDiv1 {
position:absolute;
width:560px;
height:27px;
z-index:1;
left: 93px;
top: 247px;
}
#cat {
position:absolute;
width:227px;
height:500px;
z-index:1;
left: 3px;
top: 48px;
background-color: #FFF;
font-family:"Lucida Console", Monaco, monospace;
}
.container1 {
position:relative;
padding: 0 20px 0 20px;
margin: auto;
width: 1000px;
background-image: url(images/skyblue.png);
margin-top: 20px;
margin-bottom: 20px;
padding-bottom: 300px;
-moz-border-radius: 8px;
border-radius: 8px;
}
.label{
text-align:right;
}
#submit{
text-align:center;
}
</style>
<script type = "text/javascript">
function myfunction(url)
{
window.location.href = url;
}
</script>
<script type="text/javascript">
$(document).ready(function(){
$(".expanderHead").click(function(){
var $exsign = $("#expanderSign");
$(this).find("#expanderContent").slideToggle();
$exsign.html($exsign.text() == '+' ? '-': '+');
// simplify your if/else into one line using ternary operator
// if $exsign.text() == "+" then use "-" else "+"
});
});
</script>
</head>
<body>
<div id="header">
<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=439699742746900";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div id="search">
<center>
<form method="GET" action="search.php" style= "padding: 1px;">
<input name="search" id="s" type="text" value="<?php echo $_GET['search']; ?>" size="20" />
<select name="category" id="category" >
<?php if(isset($_GET['submit'])) { ?>
<option value="<?php echo $_GET['category']; ?>" selected="selected"><?php echo $_GET['category']; ?></option>
<?php }else{ ?>
<option value=""> -- select -- </option>
<?php } ?>
<option value="">All</option>
<option value="Books">Books</option>
<option value="Textbooks">TextBooks</option>
<option value="Tickets">Tickets</option>
<option value="Electronics">Electronics</option>
<option value="Clothing">Clothing</option>
<option value="Accessories">Accessories</option>
<option value="Furniture">Furniture</option>
<option value="Imagery">Imagery</option>
<option value="Business">Business</option>
<option value="Clothing">Clothing</option>
<option value="Multi">Multimedia</option>
</select>
<select name="university" id="university" >
<option value="">Aston University</option>
</select>
<input id="searchSubmit" type="submit" value="" name="submit"/>
</form>
</center>
</div>
<div id="imagelogo" onclick = "window.location.href = 'index.php'" >
<p> Buy and sell stuff around University</p>
</div>
<ul id="navigation" name="navigation">
<li id="nav-home">Home | Search | Selling | Buying | FAQ | Contact </li>
</ul>
<div id="account">
<?php
if( isset( $_SESSION['username'] ) ){
echo "<a href='securedpage1.php'>My Account</a><img src='images/uni-icon.png' width='30' height='18' style='vertical-align: middle;'/>";
}else{
echo "<a href='login.php' >Login</a><img src='images/uni-icon.png' width='30' height='18' style='vertical-align: middle;'/>";
}
?>
</div>
<div id="registerlogout">
<?php
if( isset( $_SESSION['username'] ) ){
echo "<a href='logout.php'>Logout</a>";
}else{
echo "<a href='register.php'> Register</a>";
}
?>
</div>
<center>
<center>
</div>
<div class="container1">
<div id="cat">
<table width="225" border="1" cellspacing="10" cellpadding="10">
<tr>
<td>Accessories</td>
</tr>
<tr>
<td>Accommodation</td>
</tr>
<tr>
<td>Books</td>
</tr>
<tr>
<td>Business</td>
</tr>
<tr>
<td>Clothing</td>
</tr>
<tr>
<td>Electronics</td>
</tr>
<tr>
<td>Furniture</td>
</tr>
<tr>
<td>Imagery</td>
</tr>
<tr>
<td>Multimedia</td>
</tr>
<tr>
<td>Services</td>
</tr>
<tr>
<td>Tickets</td>
</tr>
</table>
</div>
<div id="text1">Items For Sale:
</div>
<div id="search1">
<form method="GET" action="search.php" style= "padding: 1px;">
<select name="price" id="price" >
<?php if(isset($_GET['submit'])) { ?>
<option value="<?php echo $_GET['price']; ?>" selected="selected"><?php echo $_GET['price']; ?></option>
<?php }else{ ?>
<option value=""> -- select -- </option>
<?php } ?>
<option value=""></option>
<option value="DESC">Highest to Lowest</option>
<option value="ASC">Lowest to Highest</option>
</select>
<input id="searchSubmit" type="submit" value="" name="submit"/>
</form>
</div>
<div id="divspace"></div>
<div style=" padding-left: 240px" ">
<?php
// Include database connection settings
include('config.php');
include('config.inc');
// Check and set username
$username = (isset($_SESSION['username']) ? $_SESSION['username'] : 'guest');
// Check and set category
$category = (!empty($_GET['category']) ? $_GET['category'] : null);
// Check and set search
if(!empty($_GET['search'])){
$search = $_GET['search'];
}else{
$search = null;
}
// Check that $_GET['price'] is ASC if not set to DESC
// as static values its ok to directly put in the query
if(isset($_GET['price']) && $_GET['price'] == 'ASC'){
$price = 'ASC';
}else{
$price = 'DESC';
}
if ($search !== null){
$sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)";
$q = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->execute();
}
if ($search !== null && $category !== null){
$sql = "SELECT * FROM people WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE) AND category = :category";
$q = $conn->prepare($sql) or die("failed!");
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->execute();
}
if ($category !== null && $search !== null && isset($price)){
$sql = "SELECT *
FROM people
WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)
AND category = :category
ORDER BY price ".$price;
$q = $conn->prepare($sql);
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->bindParam(':category', $category, PDO::PARAM_STR);
$q->execute();
}
if ($category == null && $search !== null && isset($price)){
$sql = "SELECT *
FROM people
WHERE MATCH (lname,fname) AGAINST (:search IN BOOLEAN MODE)
ORDER BY price ".$price;
$q = $conn->prepare($sql);
// Bind the params to the placeholders
$q->bindParam(':search', $search, PDO::PARAM_STR);
$q->execute();
}
if ($q){
//declaring counter
$count=0;
while($r = $q->fetch(PDO::FETCH_ASSOC)){
$row = $r;
$fname = $row['fname'];
$lname = $row['lname'];
$firstname = $row['firstname'];
$surname = $row['surname'];
$expire = $row['expire'];
$oDate = strtotime($row['expire']);
$sDate = date("d/m/y",$oDate);
//counter equals
$count++;
//insert an image every 5 rows
if($count==5){
$count=0;
echo "<table width='50%' style='border-bottom:1px solid #000000;'>";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";
echo "<a href='images/box1.png' rel='lightbox'><img src='images/box1.png' width='160px' height='200px' /></a>";
echo "<div class='reasonbar'><div class='prod-title' style='width: 70%;'>AN AD CAN GO HERE</div><div class='reason' style='width: 29%;'><b>Ad Company</b></div></div>";
echo "<div class='reasonbar'><div class='prod-title1' style='width: 70%;'>Description about the advert from a company</div><div class='reason1' style='width: 29%;'>Category: Advert</div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>HELLO, User</div><div class='reason2' style='width: 29%;'></div></div>";
echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</table>";
}
echo "<table width='50%' style='border-bottom:1px solid #FFFFFF'>";
echo "<tr>";
echo "<td>";
echo "<div id='page-wrap'>";
echo "<div class='discounted-item freeshipping'>";
echo "<a href='./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "' rel='lightbox'><img src=\"./img/users/" . $row['category'] . "/" . $row['username'] . "/" . $row['filename'] . "\" alt=\"\" width='80px' height='100px' /></a>";
echo "<div class='expanderHead'>";
echo "<div class='reasonbar'><div class='prod-title'>" .$row['fname'] . "</div><div class='reason' style='width: 29%;'><b>". $row['firstname'] . " " . $row['surname'] ."</b></div></div>";
echo "<div id='expanderContent' style='display:none'><div class='reasonbar'><div class='prod-title1'>" . $row['lname'] . "</div><div class='reason1' style='width: 29%;'>Category:<br /> ". $row['category'] . "</div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'><form action='adclick.php' method='post'><input type='hidden' name='username' value='" . $row['username'] . "'/><input type='submit' name='submit' value='Reply To this ad'></form></div><div class='reason2' style='width: 29%;'></div></div></div>";
echo "<div class='reasonbar'><div class='prod-title2' style='width: 70%;'>Expires: $sDate</div><div class='reason2' style='width: 29%;'>Price: £". $row['price'] . "</div></div>";
echo "</td>";
echo "</tr>";
echo "</td>";
echo "</tr>";
echo "</div>";
echo "</table>";
}
}
else
echo "No results found for \"<b>$search</b>\"";
//disconnect
mysql_close();
?>
</div>
</div>
<div class="footer">
<p> Private Policy | Terms and Conditions | FAQ </p>
</div>
</body>
</html>
Sample Code:
$start is the starting number,$limit is the ending number (for one page).. $count is total number of records
echo "<h5>Showing ".$start." to ".($start+$limit)." Records of ".$count." Records</h5>";
if($start<=($count-$limit))
{
echo '<a style="float:right" href="'.$_SERVER['PHP_SELF'].'?start='.($start+$limit).'&limit='.$limit"><t1>Next</t1></a>';
}
$prev = $start-$limit;
if ($prev >= 0)
{
echo '<a style="float:left" href="'.$_SERVER['PHP_SELF'].'?start='.$prev.'&limit='.$limit"><t2>Previous</t2></a>';
}
$i=0;
$l=1;
echo "<p align='center'>";
for($i=0;$i < $count;$i=$i+$limit)
{
if($i <> $start)
{
echo "<a href='listing_test.php?start=$i&limit=$limit'><font face='Verdana' size='2'><b> $l </b></font></a> ";
}
else
{
echo "<font face='Verdana' size='4' color=#2E9AFE ><b> $l </b></font>";
}
$l=$l+1;
}
echo "</p>";
EDIT:
$result = mysql_query("SELECT * FROM table_name LIMIT ".$start.",".$limit);
$total=mysql_query("SELECT * FROM table_name");
$count=mysql_num_rows($total);