I am currently having a trouble using the radio button, I'm getting confuse because of the output of my codes. In the left picture that's what my output like, in the right picture I want my output like that. When I choose from the candidates both radio button can choose instead of only one should be can be chosen.
Here's my code:
<?php
$YearNow=Date('Y');
$dsds=$rowasa['posid'];
$results = $db->prepare("SELECT * FROM candidates,student,school_year,partylist where student.idno = candidates.idno AND school_year.syearid = candidates.syearid AND posid =:a AND candidates.partyid = partylist.partyid AND school_year.from_year like $YearNow ");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
?>
//here's the part that i was confuse
<input type ="radio"><input style="padding: 35px 50px 35px 80px; background:url('admin/candidates/images/<?php echo $rows['image']; ?>') no-repeat scroll 5px 7px / 70px auto rgba(0, 0, 0, 0);"
value="<?php echo $rows['candid'] . "-" ." ". $rows['lastname'] .",". " ". $rows['firstname'] ?>"><?php echo $rows['lastname'] ?>,
<?php echo $rows['firstname'] ?>
- <?php
echo $rows['party_name']?>
<?php
}
?>
It looks like you SQL query is giving you the right results however I would really look into using JOINs. Regardless, im assuming your SQL results are something like this:
$candidates = array(
array(
"id" => "1",
"firstname" => "John",
"image" => "some/image/path",
"party_name" => "Party1",
),
array(
"id" => "2",
"firstname" => "Jane",
"image" => "some/image/path",
"party_name" => "Party2",
)
);
To iterate through this and build your HTML, it will be a lot easier to use foreach like so:
<form method="post" action="submit.php">
<?php
foreach ($candidates as $candidate) {
?>
<div class="box">
<div class="image">
<img src="admin/candidates/images/<?php echo $candidate['image']; ?>" alt="">
</div>
<div class="input">
<input type="radio" name="candidate_selected" value="<?= $candidate['id'] ?>">
</div>
<div class="text">
<?php echo $candidate['firstname'] . " - " . $candidate['party_name'] ?>
</div>
</div>
<?php
}
?>
<input type="submit">
</form>
Notice how the input has the same name and the id of your candidate results. Once this is submitted, you should only see the id of the selected candidate in your submit.php handler.
Now add some CSS:
.box {
display: inline-block;
text-align: center;
}
.box .image {
padding: 15px;
}
.box .image img {
width: 150px;
height: 150px;
display: block;
}
Hope this helps.
Try echo the radio button like this.
<?php
$YearNow=Date('Y');
$dsds=$rowasa['posid'];
$results = $db->prepare("SELECT * FROM candidates,student,school_year,partylist where student.idno = candidates.idno AND school_year.syearid = candidates.syearid AND posid =:a AND candidates.partyid = partylist.partyid AND school_year.from_year like $YearNow ");
$results->bindParam(':a', $dsds);
$results->execute();
for($i=0; $rows = $results->fetch(); $i++){
//here's the part that i was confuse
echo "<input type ='radio'><input style='padding: 35px 50px 35px 80px; background:url('admin/candidates/images/". $rows['image'] . "') no-repeat scroll 5px 7px / 70px auto rgba(0, 0, 0, 0);
value='" . $rows['candid'] . " - "$rows['lastname'] ", ". $rows['firstname'] . "'>" . $rows['lastname'] . "," . $rows['firstname'];
echo $rows['firstname'] ." - ". $rows['party_name'];
}
?>
Related
I have a problem with displaying images in carousel. I want to display 2 images per carousel slide. I took images from database using while loop to create slides. The problem is that with my code it only displays one image per slide.
This is how it looks now:
Check the image
<?php
$brojacPoStrani = 0;
$sqlIzvestaji = mysqli_query($con, "SELECT operacije.nazivEng, izvestaji.operacija, izvestaji.ucinak, izvestaji.id FROM izvestaji INNER JOIN operacije ON izvestaji.operacijaId=operacije.id WHERE projekatId='$projekatId' AND datum='$datum'");
while ($row = mysqli_fetch_array($sqlIzvestaji)) {
$id = $row['id'];
$sqlSlike = mysqli_query($con, "SELECT img_name FROM slike WHERE izvestajId='$id' AND datum='$datum'");
$brojacDuplikata = false;
while ($row2 = mysqli_fetch_array($sqlSlike)) {
if ($brojacPoStrani % 2 == 0) {
?>
<div class="carousel-cell" style="background-image: url('img/izvestaji.jpg'); background-repeat: no-repeat; background-size: 100% 350px;">
<h1 style="color: #fff; text-align: left; padding-left: 15px; font-weight: bold;"><?php echo $row['nazivEng']; ?></h1>
<?php
if ($brojacDuplikata === false) {
$brojacDuplikata = true;
?>
<p style="text-align: left; padding-left: 45px; padding-top: 20px; padding-bottom: 10px;"><?php echo $row['operacija'] . " - " . $row['ucinak']; ?></p>
<?php
} else {
?>
<p style="text-align: left; padding-left: 45px; padding-top: 40px; padding-bottom: 10px;"></p>
<?php
}
?>
<div class="row">
<?php
if ($brojacPoStrani % 2 == 0) {
?>
<div class="col-lg-6">
<img src="../files/izvestaji/<?php echo $project; ?>/<?php echo $datum; ?>/<?php echo $row['nazivEng']; ?>/<?php echo $row2['img_name']; ?>" style="width: 350px; height: 350px; padding-left: 10px;" class="float-right" />
</div>
<?php
} else {
?>
<div class="col-lg-6">
<img src="../files/izvestaji/<?php echo $project; ?>/<?php echo $datum; ?>/<?php echo $row['nazivEng']; ?>/<?php echo $row2['img_name']; ?>" style="width: 350px; height: 350px; padding-right: 10px;" class="float-left" />
</div>
<?php
}
?>
</div>
<br />
</div>
<?php
}
$brojacPoStrani++;
}
$brojacPoStrani = 0;
}
As mentioned it looks like you should be able to use a single query rather than having nested queries - and to display 2 images per carousel slide you effectively want to select data from the current and next rows. One easy way to do that would be to assign the entire recordset to a variable and then process that array using a for loop. The following is a simplified, semi-pseudo code version that attempts to combine the sql queries and assign recordset to an array. It is not tested as such but it might? be of use.
$sql="select
o.naziveng,
i.operacija,
i.ucinak,
i.id,
s.img_name
from izvestaji i
inner join operacije o on i.operacijaid=o.id
inner join slike s on s.izvestajId=i.id
where projekatid='$projekatid' and datum='$datum'";
$res = mysqli_query( $con, $sql );
if( $res ){
$arr = mysqli_fetch_all( $res, MYSQLI_BOTH );
for( $i=0; $i < count( $arr ); $i+=2 ){
try{
$r1=array_key_exists( $i+0, $arr ) ? $arr[ $i+0 ] : false;
$r2=array_key_exists( $i+1, $arr ) ? $arr[ $i+1 ] : false;
/*
generate the HTML structure and add two images
*/
echo '<div class="carousel-cell">'; # simplified version
if( $r1 )echo 'row 1: '.$r1['img_name'];
if( $r2 )echo 'row 2: '.$r2['img_name'];
echo '</div>';
}catch( Exception $e ){
continue;
}
}
}
Here's what I'm basically trying to do:
Retrieve the values of a column
Store those values into an array in PHP
Echo each value with a line break in between each value
Here's my attempted code:
<?php
$connection = mysqli_connect("localhost", "root", "bruhfrogzombie098", "growtapi_social");
if (!$connection) {
die("Failed to connect to MYSQL: " . mysqli_connect_errno());
};
$members = mysqli_query($connection, "SELECT Username FROM s_users");
$members_status = mysqli_query($connection, "SELECT Status_Content FROM s_users");
$members_array = array();
while ($member = mysqli_fetch_assoc($members)) {
$members_array[] = $member;
};
$members_status_array = array();
while ($status = mysqli_fetch_assoc($members_status)) {
$members_status_array[] = $status;
};
?>
And this is where I want to echo out the values:
<center>
<h1>Members Directory</h1>
<div style="width: 20%; height; 75%; border: 3px solid black; margin: auto; overflow: hidden; overflow-y: scroll;">
<?php echo $members_array['$member'];
echo "<br />";
?>
</div>
</center>
I don't receive any errors, but the problem is that nothing shows up in the div, meaning that I either didn't retrieve the data properly or didn't use it right.
Note: I've finally moved on to writing up-to-date code, so I hope no one here comments that somewhere in this code I have outdated code ( ͡° ͜ʖ ͡°)
$members_array = array();
while ($member = mysqli_fetch_assoc($members)) {
$members_array[] = $member;
//$members_array is array and $member is array so $members_array like $members_array[][];
};
<center>
<h1>Members Directory</h1>
<div style="width: 20%; height; 75%; border: 3px solid black; margin: auto; overflow: hidden; overflow-y: scroll;">
<?
$member_count = count($members_array);
for( $i = 0 ; $i < $member_count ; $i++ ){
echo $member_array[$i]['Username'];
echo "<br />";
}
?>
</div>
</center>
So my "type1" select statement will select an issue category, and then based on that issue I want a dropdown of employees that deal with that issue in another drop down. Also how do I make all the hidden select statements occupy the same space?
Here is my code:
<!DOCTYPE html>
<html>
<head>
<title>IssueReport</title>
<script src = "../../jquery.js"></script>
<style>
body{
padding:0;
margin:0;
}
#box {
padding: 5px;
color:black;
margin: 0 auto;
border-style: solid;
border-color: #0000E6;
border-width: 2px;
background-color: #58C6EB;
width: 162px;
height: 687px;
float: left;
border-radius: 10px;
}
.word{
color: #0000E6;
}
.buttons{
background-color: #CCFFFF;
border-radius: 5px;
}
</style>
<script>
function showForm(){
var issue = document.getElementById("type1").value;
if(issue == 'Program Glitch'){
document.getElementById("IT1").style.display = "block";
}
$("#type1").onchange(function{
});
}
$(document).ready(function(){
$("#sub").click(function(){
var user_issue = $("#issue").val();
var user_priority = $("#priority").val();
var user_type = $("#type1").val();
var user_author = $("#author").val();
$.post("BugReport.php",{issue:user_issue,priority:user_priority,type1:user_type,author:user_author},function(data){
$("#result").html(data);
});
});
$("#sub").click(function(){
document.getElementById('issue').value='';
$('#type1').prop('selectedIndex', 0);
$('#priority').prop('selectedIndex', 1);
});
});
</script>
</head>
<body>
<div id="box">
<h3 class = "word" style = "margin:10px 30px 30px 30px;">Issue Report</h3>
<div class = "word" style = "width: 100px; margin-left: auto; margin-right: auto">Type Of Issue:</div>
<div style = " max-width: 150px; margin-left: auto; margin-right: auto; padding: 2px">
<form action="BugReport.html" method="post">
<select onchange = "showForm()" class = "buttons" name = "type1" id = "type1" style = 'max-width: 150px;'>
<?php
$servername = "localhost";
$username = "user";
$password = "pass";
$database = "database";
$con = mysqli_connect($servername,$username,$password,$database);
if($con->connect_error){
die("Connection failed " . $con->connect_error);
}
$sql1 = "select issue_name, issue_description from Issue";
$result = mysqli_query($con,$sql1);
while ($row = mysqli_fetch_array($result)) {
$issue = $row['issue_name'];
$des = $row['issue_description'];
echo "<option value = '$issue' title = '$des'>$issue</option>";
}
?>
</select>
</form></div>
<form action="BugReport.html" method="post">
<div id = "Buyers1" style = "visibility:hidden;"><select class = "buttons" name = "author" id = "Buyers" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = '1'";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></div></form>
<div id = "Operations1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "Operations" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 2";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "IT1" style = "display:none;"><form action="BugReport.html" method="post">
<select onchange = "showForm()" class = "buttons" name = "author" id = "IT" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 3";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "CustomerService1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "CustomerService" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 4";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "HR1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "HR" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 5";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<div id = "Logistics1" style = "visibility:hidden;"><form action="BugReport.html" method="post">
<select class = "buttons" name = "author" id = "Logistics" style = "margin: 0px 30px 0px 30px;">
<?php
$sql = "select first, last from Employee where department_id = 6";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_array($result)) {
$name = $row['first'] . ' ' . $row['last'];
echo "<option value = '$name'>$name</option>";
}
?>
</select></form></div>
<form action="BugDisplayAndReply.html" method="post">
<label></label><br>
<textarea style = "max-width: 156px; background-color: #F3F9FF; border-color: #0000E6;" cols="20" rows="34" name="issue" id = "issue" placeholder = "Enter Your Issue Here" "></textarea></form><br>
<div class = "word" style = "width: 50px; margin-left: auto; margin-right: auto">Priority:</div>
<div style = "width: 70px; margin-left: auto; margin-right: auto; padding: 2px">
<form action="BugReport.html" method="post">
<select class = "buttons" name = "priority" id = "priority">
<option value = "Low">Low</option>
<option value = "Regular" selected>Regular</option>
<option value = "High">High</option>
<option value = "Urgent">Urgent</option>
</select>
</form></div>
<div style = "width: 50px; margin-left: auto; margin-right: auto; padding: 2px">
<input class = "buttons" type ="submit" name = "sub" value = "Submit" id = "sub"></div>
<div id="result"></div>
</div>
</body>
</html>
Why always do the first result of my search term will not come out?
I noticed that it will only appear when I navigate to the page number 0.
How can I solve this?
I hope that when I navigate to page number 1, the first result will come out too!
PHP Code:
<?php
//php code goes here
include 'connect.php'; // for database connection
include 'script_suggestion.php';
include 'script_close_suggestion_box.php';
$query = $_GET['q']; // query
$button = $_GET ['submit'];
if (isset($_GET['page'])) {
$page_number = (int)$_GET['page'];
$page_number = mysqli_real_escape_string($page_number);
} else {
$page_number = 1;
}
$results_per_page = 10;
?>
HTML Code:
<html>
<head>
<title>
Brandon's Search Engine
</title>
<style type="text/css">
#title a {
font-size: 17pt;
margin: 5px;
padding: 2px;
border-color: black;
text-decoration: underline;
width: 544px;
}
#search-result {
display: block;
border: 1px solid grey;
border-color: grey;
}
#search-result:hover {
background-color: #dddddd;
width: 544px;
}
#link {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#description {
font-size: 17pt;
margin: 5px;
padding: 2px;
width: 544px;
}
#search-page-number {
display: block;
width: auto;
height: auto;
border: 1px solid gray;
margin: 2px;
padding-left: 5px;
padding-right: 5px;
padding-bottom: 2px;
padding-top: 2px;
list-style: none;
float: left;
text-align: center;
}
#search-page-number:hover {
background-color: #dddddd;
}
#suggestion {
border: 1px solid black;
visibility: hidden;
position: absolute;
background-color: white;
z-index: 10;
}
#suggestion a {
font-size: 12pt;
color: black;
text-decoration: none;
display: block;
width: 548px;
height: auto;
text-align: left;
padding: 2px;
}
#suggestion a:hover {
background-color: #dddddd;
width: 544px;
padding: 2px;
}
</style>
</head>
<body>
<form method="GET" action="search.php">
<table>
<tr>
<td>
<h2>
Brandon's Search Engine
</h2>
</td>
</tr>
<tr>
<td>
<input type="text" value="<?php echo htmlspecialchars($_GET['q']); ?>" name="q" style="height: 27px; width: 550px; padding: 2px" name="q"
onkeyup="getSuggestion(this.value)" autocomplete="off" onblur="closeBox()" placeholder="Search Now"/>
<input type="submit" value="Search" style="height: auto; width: 60px; padding: 2px" />
<div id="suggestion" style="width: 548px">
</div>
</td>
</tr>
</table>
<br>
<hr>
<table>
<tr>
<td>
<?php
//count
$count_sql = "SELECT count(*) as c FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' ";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];
//SQL query
$page_number = (int)$_GET['page'];
$stmt = "SELECT * FROM searchengine WHERE title LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR keywords LIKE '%" . mysqli_real_escape_string($con,$query) . "%' OR link LIKE '%" . mysqli_real_escape_string($con,$query) . "%' LIMIT " . $page_number . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
//$number_of_result = mysqli_num_rows($result);
if ($number_of_result < 1) {
echo "<b>No results found!</b>";
echo "<p>";
echo "Your search - <b>$query</b>" . " - did not match any documents. Please try different keywords.";
}
elseif ($number_of_result > 1) {
echo "<b>$number_of_result results found!</b>";
echo "<p>";
//results found here and display them
while (($row = \mysqli_fetch_array($result))) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
//echo "<p>";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
}
}
elseif ($number_of_result == 1) {
echo "<b>$number_of_result result found!</b>";
echo "<p>";
//results found here and display them
while (($row = \mysqli_fetch_array($result))) {//10 results per page
$title = $row["title"];
$description = $row["description"];
$link = $row["link"];
echo "<div id='search-result'>";
echo "<div id='title'><a href='$link'>" . $title . "</a></div>";
//echo "<br />";
echo "<div id='link'><small>" . $link . "</small></div>";
echo "<br />";
echo "<div id='description'><small>" . $description . "</small></div>";
echo "</div>";
echo "<br />";
}
}
?>
</td>
</tr>
<tr>
<td>
<input type="hidden" name="page" value="<?php echo 1; ?>" />
<div id="page-number">
<?php
$max_page_number = ceil($number_of_result / $results_per_page);
if ($number_of_result == 0) {
echo " ";
}
elseif ($number_of_result != 0) {
echo "You are on page $page_number of $max_page_number.";
}
//ie if 35 results are therer then we require 4 pages that are 0 to max_page_number
//current page number is equal to page_number
//echo $max_page_number;
echo "<ul>";
//both the condition are not the neccesary
if ($max_page_number >= 1) { // if more than 2 pages
if ($page_number != 1) { //First
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=1>First</a>";
echo "</li>";
}
if ($page_number != 1) { //Previous
echo "<li id='search-page-number'>";
$prev = $page_number - 1;
echo "Previous";
echo "</li>";
}
for($index = 1 ; $index <= $max_page_number ; $index++) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=".($index).">";
echo ($index) . "</a>";
echo "</li>";
}
if ($page_number != $max_page_number) { //Next
echo "<li id='search-page-number'>";
$next = $page_number + 1;
echo "Next";
echo "</li>";
}
if ($page_number != $max_page_number) { //Last
echo "<li id='search-page-number'>";
echo "Last";
echo "</li>";
}
} elseif (($max_page_number == 1 ) ) {
echo "<li id='search-page-number'>";
echo "<a href=search.php?q=$query&page=1>1</a>";
echo "</li>";
}
echo "</ul>";
?>
</div>
</td>
</tr>
<tr>
<td align="center">
To insert your site in result fill in the form at here.
</td>
</tr>
</table>
</form>
</body>
</html>
Your query ends with:
"LIMIT " . $page_number . ", $results_per_page"
But that's not how the LIMIT clause works in SQL. It's defined to be:
LIMIT offset, row_count
offset is a row number, starting from 0. So if you do:
LIMIT 1, 10
You'll get records 2 through 11, not 1 through 10. The correct way to do it is:
"LIMIT " . ($page_number-1)*$results_per_page . ", $results_per_page"
Something else you should find useful is the SQL_CALC_FOUND_ROWS option to the SELECT statement. This tells MySQL to calculate how many total rows matched the criteria, even though you used LIMIT to return just a subset. This way you don't have to do two queries, one with COUNT(*) and another to get a page of data. After doing a query with this option, you can use SELECT FOUND_ROWS() to get the full count.
$safequery = mysqli_real_escape_string($con,$query);
$stmt = "SELECT SQL_CALC_FOUND_ROWS *
FROM searchengine
WHERE title LIKE '%" . $safequery . "%'
OR keywords LIKE '%" . $safequery . "%'
OR link LIKE '%" . $safequery . "%'
LIMIT " . ($page_number-1)*results_per_page . " , $results_per_page";
$result = mysqli_query($con,$stmt) or die(mysqli_error($con));
$count_sql = "SELECT FOUND_ROWS() AS c";
$search_count = mysqli_fetch_array(mysqli_query($con,$count_sql));
$number_of_result = $search_count['c'];
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);