Related
I am trying to set the variable $OnWishList to display a tick or a plus symbol depending on if the property is in the wish list. Though it does this it skips the first property in the wile loop and shows the correct symbol for the first property on the second property. How can I get the symbols to show on the correct properties. I apologize if this is a simple question as I am new to PHP and SQL and have struggled with this problem for a while.
$city = (isset($_GET['city'])) ? $_GET['city'] : 0;
$suburb = (isset($_GET['suburb'])) ? $_GET['suburb'] : 0;
$minBed = (isset($_GET['minBed'])) ? $_GET['minBed'] : 0;
$maxBed = (isset($_GET['maxBed'])) ? $_GET['maxBed'] : 0;
$minBath = (isset($_GET['minBath'])) ? $_GET['minBath'] : 0;
$maxBath = (isset($_GET['maxBath'])) ? $_GET['maxBath'] : 0;
$minPrice = (isset($_GET['minPrice'])) ? $_GET['minPrice'] : 0;
$maxPrice = (isset($_GET['maxPrice'])) ? $_GET['maxPrice'] : 0;
$pagingVariable = '';
$cityName ='';
//}
$rowsPerPage = 8; // edit the number of rows per page
$query = "SELECT tbl_property.property_ID, tbl_property.name, tbl_property.location, tbl_property.description, tbl_property. price, tbl_property.landsize, tbl_property.property_image, tbl_property.bedrooms, tbl_property.bathrooms, tbl_property.garage, tbl_agents.agent_name, tbl_agents.agent_image, tbl_city.cityName FROM tbl_property INNER JOIN tbl_agents ON tbl_property.agent_ID=tbl_agents.agent_ID INNER JOIN tbl_city ON tbl_property.city_ID=tbl_city.city_ID";
//$query = "SELECT tbl_property.property_ID, tbl_property.name, tbl_property.location, tbl_property.description, tbl_property. price, tbl_property.landsize, tbl_property.property_image, tbl_property.bedrooms, tbl_property.bathrooms, tbl_property.garage, tbl_agents.agent_name, tbl_agents.agent_image FROM tbl_property INNER JOIN tbl_agents ON tbl_property.agent_ID=tbl_agents.agent_ID";
$pagingLink = getPagingLink($query, $rowsPerPage);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
if($city == 0){
$query .= " WHERE ";
}
if($city != 0){
$query = "SELECT tbl_property.property_ID, tbl_property.name, tbl_property.location, tbl_property.description, tbl_property.price, tbl_property.landsize, tbl_property.property_image, tbl_property.bedrooms, tbl_property.bathrooms, tbl_property.garage, tbl_agents.agent_name, tbl_agents.agent_image, tbl_city.cityName FROM tbl_property INNER JOIN tbl_agents ON tbl_property.agent_ID=tbl_agents.agent_ID INNER JOIN tbl_city ON tbl_property.city_ID=tbl_city.city_ID WHERE tbl_property.city_ID ='$city'";
$pagingVariable .= "&city=".$_GET['city'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($suburb != 0){
$query .= "AND suburb_ID ='$suburb'";
$pagingVariable .= "&suburb=".$_GET['suburb'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBed != 0 && $maxBed == 0 && $city == 0){
$query .= " bedrooms >='$minBed'";
$pagingVariable .= "&minBed=".$_GET['minBed'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBed != 0 && $city != 0){
$query .= "AND bedrooms >='$minBed'";
$pagingVariable .= "&minBed=".$_GET['minBed'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($maxBed != 0 && $minBed == 0 && $city == 0){
$query .= " bedrooms <='$maxBed'";
$pagingVariable .= "&maxBed=".$_GET['maxBed'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($maxBed != 0 && $minBed == 0 && $city != 0){
$query .= "AND bedrooms <='$maxBed'";
$pagingVariable .= "&maxBed=".$_GET['maxBed'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBed != 0 && $maxBed != 0 && $city != 0){
$query .= "AND (bedrooms BETWEEN '$minBed' AND '$maxBed')";
$pagingVariable .= "&minBed=".$_GET['minBed']."&maxBed=".$_GET['maxBed'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBed != 0 && $maxBed != 0 && $city == 0){
$query .= " (bedrooms BETWEEN '$minBed' AND '$maxBed')";
$pagingVariable .= "&minBed=".$_GET['minBed']."&maxBed=".$_GET['maxBed'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if ( ((($minBed != 0 || $maxBed != 0) && $city != 0)) || ((($minBed != 0 || $maxBed != 0) && $city == 0)) || ((($minBed == 0 && $maxBed == 0) && $city != 0))){
$query .= " AND";
}
if($minBath != 0 && $maxBath == 0 && $city == 0){
$query .= " bathrooms >='$minBath'";
$pagingVariable .= "&minBath=".$_GET['minBath'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBath != 0 && $maxBath == 0 && $city != 0){
$query .= " bathrooms >='$minBath'";
$pagingVariable .= "&minBath=".$_GET['minBath'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBath != 0 && $maxBath != 0 && $city == 0){
$query .= " (bathrooms BETWEEN '$minBath' AND '$maxBath')";
$pagingVariable .= "&minBath=".$_GET['minBath']."&maxBath=".$_GET['maxBath'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minBath != 0 && $maxBath != 0 && $city != 0){
$query .= " (bathrooms BETWEEN '$minBath' AND '$maxBath')";
$pagingVariable .= "&minBath=".$_GET['minBath']."&maxBath=".$_GET['maxBath'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($maxBath != 0 && $minBath == 0 && $city == 0){
$query .= " bathrooms <='$maxBath'";
$pagingVariable .= "&maxBath=".$_GET['maxBath'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($maxBath != 0 && $minBath == 0 && $city != 0){
$query .= " bathrooms <='$maxBath'";
$pagingVariable .= "&maxBath=".$_GET['maxBath'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
//
//
if ($minBath != 0 || $maxBath != 0){
$query .= " AND";
}
if($minPrice != 0 && $maxPrice == 0 && $city == 0){
$query .= " Price >='$minPrice'";
$pagingVariable .= "&minPrice=".$_GET['minPrice'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minPrice != 0 && $maxPrice == 0 && $city != 0){
$query .= " Price >='$minPrice'";
$pagingVariable .= "&minPrice=".$_GET['minPrice'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minPrice != 0 && $maxPrice != 0 && $city == 0){
$query .= " (Price BETWEEN '$minPrice' AND '$maxPrice')";
$pagingVariable .= "&minPrice=".$_GET['minPrice']."&maxPrice=".$_GET['maxPrice'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($minPrice != 0 && $maxPrice != 0 && $city != 0){
$query .= " (Price BETWEEN '$minPrice' AND '$maxPrice')";
$pagingVariable .= "&minPrice=".$_GET['minPrice']."&maxPrice=".$_GET['maxPrice'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($maxPrice != 0 && $minPrice == 0 && $city == 0){
$query .= " Price <='$maxPrice'";
$pagingVariable .= "&maxPrice=".$_GET['maxPrice'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if($maxPrice != 0 && $minPrice == 0 && $city != 0){
$query .= " Price <='$maxPrice'";
$pagingVariable .= "&maxPrice=".$_GET['maxPrice'];
$pagingLink = getPagingLink($query, $rowsPerPage, $pagingVariable);
$result = mysqli_query($link, getPagingQuery($query, $rowsPerPage));
}
if (mysqli_num_rows($result) < 1) {
$noResults = "Sorry, no results were found!";
} else {
while($row = mysqli_fetch_array($result)) {
extract($row);
?>
<div class="col-md-6">
<div class="propertyCardOuter card">
<div title="add to watchlist" class="displayWishAdd"><div class="plusSymbol"><?php echo $OnWishList;?></div></div>
<a class="propertyCardLink" href="viewProperty.php?propertyID=<?php echo $row['property_ID']; ?>"><div class="card propertyCard">
<div class="propertyImgContainer">
<img alt="Photo" class="PropertyImagesHome img-fluid" src="<?php echo 'property-images/'.$row['property_image']; ?>" title="<?php echo $row['name']; ?>" />
</div>
<div class="row">
<div class="col-md-9 propertyInfoBox">
<div class="propertyName">
<?php echo $row['name']; ?></div>
<div style="font-size: 14px;">
<?php echo $row['location']; ?>
</div>
<hr>
<div class="houseDetails">
<?php echo $row['bedrooms']; ?> <i class="fa fa-bed icons"></i><?php echo $row['bathrooms']; ?>
<i class="fa fa-bath icons"></i><?php echo $row['garage']; ?>
<i class="fa fa-car icons"></i><?php echo $row['landsize'] . 'sqm'; ?>
<img src="images/landSizeIcon.png" width="19px;" alt="landsize"/>
<span class="propertyPrice"><?php echo '$' . number_format($row['price']); ?></span>
</div>
</div>
<div class=" col-sm-12 col-md-3">
<div class="agentContainer">
<div class="agentPhotoContainer">
<img alt="Photo" class="agentImage" src="<?php echo 'property-images/'.$row['agent_image']; ?>" title="photo" />
</div>
<div style="text-align:center; margin-top: 10px;"><?php echo $row['agent_name']; ?></div></div>
</div>
</div>
</div></a></div>
<h3 style="text-align:right;">
</h3>
</div>
<?php
$propertyID2 = $row['property_ID'];
$query2 = "SELECT * FROM tbl_wishlist WHERE member_ID='$memberID' && property_wishList_ID='$propertyID2' ";
$result2 = mysqli_query($link, $query2); // execute the SQL
if ($row = mysqli_fetch_array($result2)) {
$OnWishList = "<span id='tickSpan'>โ</span>";
}
else {
$OnWishList = "<span id='plusSpan'>+</span>";
}
}
} // end of while loop
}
?>
I would like the $OnWishList variable to display the tick and plus symbols starting with the first property in the while loop. However the symbols are displayed skipping the first property in the loop and showing its symbol on the second property and so on.
It is generally considered, though there is some debate, that it yields better performance to craft a prepared statement before any loops and execute multiple times within a loop with different variables being passed in. That was the intention here in using a prepared statement and assigning variables to placeholders in the sql.
By moving this code to near the top of the loop on the first iteration into the loop it will be called before you attempt to use the variable $OnWishList
<?php
$sql='select * from `tbl_wishlist` where `member_id`=? and `property_wishlist_id`=?';
$stmt=$link->prepare( $sql );
$stmt->bind_param( 'ii', $memberID, $wishlistid );
while( $row = mysqli_fetch_array( $result ) ) {
extract( $row );
$wishlistid=$row['property_ID'];
$stmt->execute();
$stmt->store_result();
$count=$stmt->num_rows;
$OnWishList=$count > 0 ? "<span id='tickSpan'>โ</span>" : "<span id='plusSpan'>+</span>";
?>
<div class="col-md-6">
<div class="propertyCardOuter card">
<a href="addWishList.php?propertyID=<?php echo $row['property_ID']; ?>">
<div title="add to watchlist" class="displayWishAdd">
<div class="plusSymbol"><?php echo $OnWishList;?></div>
</div>
</a>
<a class="propertyCardLink" href="viewProperty.php?propertyID=<?php echo $row['property_ID']; ?>">
<div class="card propertyCard">
<div class="propertyImgContainer">
<img alt="Photo" class="PropertyImagesHome img-fluid" src="<?php echo 'property-images/'.$row['property_image']; ?>" title="<?php echo $row['name']; ?>" />
</div>
<div class="row">
<div class="col-md-9 propertyInfoBox">
<div class="propertyName">
<?php echo $row['name']; ?>
</div>
<div style="font-size: 14px;">
<?php echo $row['location']; ?>
</div>
<hr>
<div class="houseDetails">
<?php echo $row['bedrooms']; ?><i class="fa fa-bed icons"></i>
<?php echo $row['bathrooms']; ?><i class="fa fa-bath icons"></i>
<?php echo $row['garage']; ?><i class="fa fa-car icons"></i>
<?php echo $row['landsize'] . 'sqm'; ?><img src="images/landSizeIcon.png" width="19px;" alt="landsize"/>
<span class="propertyPrice"><?php echo '$' . number_format($row['price']); ?></span>
</div>
</div>
<div class=" col-sm-12 col-md-3">
<div class="agentContainer">
<div class="agentPhotoContainer">
<img alt="Photo" class="agentImage" src="<?php echo 'property-images/'.$row['agent_image']; ?>" title="photo" />
</div>
<div style="text-align:center; margin-top: 10px;"><?php echo $row['agent_name']; ?></div>
</div>
</div>
</div>
</div>
</a>
</div>
<h3 style="text-align:right;"></h3>
</div>
<?php
}//end while loop
?>
There is huge error in your second if clause:
if ($row = mysqli_fetch_array($result2)) {
// ^ only one equal sign !!
$OnWishList = "<span id='tickSpan'>โ</span>";
}
else {
$OnWishList = "<span id='plusSpan'>+</span>";
// this will NEVER be executed
}
So instead checking if the row is equal to something, you are actually checking, if $row can be assigned mysqli_fetch_array($result2) Therefore, the else clause will be executed only if you cannot assign new value to the $row variable.
Check first iteration in while loop like
<?php
$i=1;
while($row = mysqli_fetch_array($result)) {
?>
<?php
if($i==1){
echo "Yes or your code";
}
else
{
echo "no or your code";
}
?>
<?php $i++; } ?>
Hello i just finish my pagination and face a problem with my filter system i use from to filter and $_POST to extract data but the thing is when i go to second page the post meaning get to nothing and i am missing some data then in my case i got more then i filter it , i mean if i filter by location (london) i get 32 of 36 but when i go to second page i will get all 36 because $_post loses his meaning hare is my code and live page : My website
Top code :
$cat1 = '';
$perpage = 10;
if(isset($_GET["catid"])){
$p1 = '';
$p2 = '';
$catid = $_GET["catid"];
$l1 = substr($catid,0,1);
$l2 = substr($catid,1,1);
$p1 = "CAT".$l1;
if(!empty($l2)){
$p2 = "CAT".$l1."-".$l2;
$p3 = $p2;
}
$cat1 = #$lang[$p1];
$cat2 = #$lang[$p2];
}
$postid = '';
$userid = '';
$pricemin = '';
$pricemax = '';
$location = '';
if(isset($_POST["filter"])){
$pricemin = $_POST["min"];
$pricemax = $_POST["max"];
$location = $_POST["location"];
}
///////////////////////////////////////PAGINATION //////////////////
if(empty($p1) && empty($p2)){
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.id > 0 ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($pricemin)){
$sql .= "AND price>='$pricemin' ";
}
if(!empty($pricemax)){
$sql .= "AND price<='$pricemax' ";
}
} else if(!empty($p2)){
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE catid='$p2' ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($pricemin)){
$sql .= "AND price>='$pricemin' ";
}
if(!empty($pricemax)){
$sql .= "AND price<='$pricemax' ";
}
} else {
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.catid LIKE '$p1%' ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($pricemin)){
$sql .= "AND price>='$pricemin' ";
}
if(!empty($pricemax)){
$sql .= "AND price<='$pricemax' ";
}
}
$res = mysqli_query($connect,$sql);
$rows = mysqli_num_rows($res);
$last = ceil($rows/$perpage);
if($last < 1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET["pn"])){
$pagenum = preg_replace("#[^0-9]#", "", $_GET["pn"]);
}
if($pagenum < 1){
$pagenum = 1;
} else if($pagenum > $last){
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $perpage.',' .$perpage;
$paginationCtrls = '';
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= 'Previous ';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= ''.$i.' ';
}
}
}
$paginationCtrls .= ''.$pagenum.' ';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= ''.$i.' ';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' Next ';
}
}
?>
and main html code with mysql query :
<div class="fp">
<div class="filter">
<b style="padding-left: 10px;">Filters:</b>
<form class="filterform" action="" method="post"><br>
Location: <br>
<input name="location" ><br>
Price Range:<br>
Min:<input type="text" name="min" size="5"> Max:<input type="text" name="max" size="5"><br><br>
<input class="submit-button" type="submit" name="filter" value="Filter">
</form>
</div>
<div class="posts">
<div id="adcat"><?php
if(!empty($cat2)){
?>
<a href="cat.php?catid=<?php echo $l1; ?>" ><?php echo $cat1." ยป "; ?></a><span><?php echo $cat2; ?></span>
<?php
} else {
echo "<font color='grey'>".$cat1."</font>";
}
?>
</div>
<div id="totalrez">
<?php echo "Total: ".$rows; ?><br>
<?php echo "Page".$pagenum." of ".$last; ?>
</div>
<br><br>
<div id="detailformscat">
<?php
if(empty($p1) && empty($p2)){
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.id > 0 ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($pricemin)){
$sql .= "AND price>='$pricemin' ";
}
if(!empty($pricemax)){
$sql .= "AND price<='$pricemax' ";
}
$sql .= "$limit";
} else if(!empty($p2)){
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE catid='$p2' ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($pricemin)){
$sql .= "AND price>='$pricemin' ";
}
if(!empty($pricemax)){
$sql .= "AND price<='$pricemax' ";
}
$sql .= "$limit";
} else {
$sql = "SELECT * FROM posts p JOIN images i ON p.id = i.postid WHERE p.catid LIKE '$p1%' ";
if(!empty($location)){
$sql .= "AND location='$location'";
}
if(!empty($pricemin)){
$sql .= "AND price>='$pricemin' ";
}
if(!empty($pricemax)){
$sql .= "AND price<='$pricemax' ";
}
$sql .= "$limit";
}
$res = mysqli_query($connect,$sql);
$rows = mysqli_num_rows($res);
while ($row = mysqli_fetch_assoc($res)) {
$postid = $row["postid"];
?>
<div id="ads">
<div id="adfavcat">
<?php if(!isset($_SESSION["userid"])) { ?>
<?php } else {
$userid = $_SESSION["userid"];
$sql2 = "SELECT * FROM fav WHERE userid='$userid' AND postid='$postid' ";
$res2 = mysqli_query($connect,$sql2);
$rowcount = mysqli_num_rows($res2);
if ($rowcount > 0){ ?>
<?php
} else { ?>
<?php }
} ?>
</div>
<div id="titlepic">
<?php echo $row["title"]; ?><br>
<img src="<?php if(!empty($row["path1"])) { echo $row["path1"]; } else echo "image/noimage.png"; ?>" height="100px" width="150px">
</div>
<div id="datescat">
<b>Date Added:</b> <?php echo date('m/d/Y H:i', $row["dateadded"]); ?><br>
<b>Renew Date:</b> <?php if($row["renewdate"] > 0){ echo date('m/d/Y H:i', $row["renewdate"]); } ?><br>
<b>Location:</b> <?php echo $row["location"]; ?><br>
<b>Price:</b> <?php echo $row["price"]."£"; ?><br>
</div>
</div>
<hr width="100%">
<?php
}
?>
<div id="paginationctrl"><br>
<?php echo $paginationCtrls; ?>
</div>
</div>
</div>
</div>
i need a possible solution for that , to catch post data and keep there until u change hare with a post method again or some other solution because now $_POST will be equal to null if u pass the second page on pagination
For this case you can instead change from $_POST to $_GET as this will be easier so solve your problem as well as any problems you might encounter in future. I think the majority of websites with pagination use variables in URL because it's much easier to track. Moreover, you're not sending any private data, so I don't see a reason why not switch to other method. You will have an option to use something like $_POST['page'] and accordingly to that you can retrieve other rows.
I'm working on a real basic chat that is mostly php powered. I'd like to use jQuery to check for new messages and update the #cbox div every few seconds. So far I have tried accomplishing that using the code below. For a frame of reference, this is my first time including jQuery into any of my scripts, so the problem is likely a very simple error that I am overlooking in my newbishness.
The problem I'm running into is the #cbox div displays blank, it doesn't seem to be calling to chat_post.php at all. I will post that code as well, in case the problem is with that and not with my jQuery. To fix, I tried also including <div id='cbox'> in chat_post.php, but that yielded no results. At this point, I'm pretty much grasping at straws.
<div id='sb_content'>
<center><div id='chat'>
<div id='ribbon' style='position: relative; margin-top:-50px; margin-left:-32px;'><center><span class='ribbon'>chat box</span></center></div>
<div style='margin-top: -20px;'><center><span style='text-shadow: 0 0 0.2em #000;' class='admin'>admin</span> || <span style='text-shadow: 0 0 0.2em #000;' class='mod'>mod</span></center></div>
<div id="cbox">
<script>
$(document).ready(function() {
setInterval(function(){getUpdates()}, 2000);
});
function getUpdates() {
$("#cbox").load("chat_post.php");
}
</script>
</div>
<form name="message" method='post' action="chat_post.php" id="cbox_input">
<input name="usermsg"id='usermsg' type="text" size="63" maxlength="255" />
</form>
</div></center>
</div>
chat_post.php
<div id='cbox' align='left'>
<?php
$username = $_SESSION['login'];
$ug = $_SESSION['user_group'];
// Display messages
$sql = <<<SQL
SELECT *
FROM `chat_entries`
ORDER BY `ts` DESC
LIMIT 0,50
SQL;
$result = $db->query($sql);
$count = $result->num_rows;
if ($count != 0){
while ($row = mysqli_fetch_array($result)) {
$c_name = $row['author'];
$c_text = $row['text'];
$c_ts = $row['ts'];
$c_id = $row['id'];
$sqlm = <<<SQL
SELECT *
FROM `users`
WHERE username = '$c_name'
SQL;
$resultm = $db->query($sqlm);
$countm = $resultm->num_rows;
if ($count != 0){
while ($rowm = mysqli_fetch_array($resultm)) {
$c_level = $rowm['user_group'];
}
}
if ($c_level == 'mod') {
echo "
<a href='/user/" . $c_name . "' class='mod'>" . $c_name . "</a>
";
}
if ($c_level == 'admin') {
echo "
<a href='/user/" . $c_name . "' class='admin'>" . $c_name . "</a>
";
}
if ($c_level == 'member') {
echo "
<a href='/user/" . $c_name . "' class='member'>" . $c_name . "</a>
";
}
if ($c_level == 'guest') {
echo "
<i>" . $c_name . "</i>
";
}
echo "
: " . $c_text . "<div id='cbox_div'>";
echo "<span style='float:left;'><i>" . $c_ts . "</i></span>";
echo "<span style='float:right;'>";
if ($ug == 'mod' || $ug == 'admin'){
echo " <a href='#'>Delete</a> || <a href='#'>Block</a> ||";
}
if ($_SESSION['login']) {
echo "Report</span></div>
";
}
}
}
?>
After removing the extra id on chat_post.php, my code worked just fine. Funny how something so simple can really mess things up. (: Thank you everyone for your help!
This is my order list sortOrder.php:
<?php
$queryMain ="SELECT newsvid.id, newsvid.addName, newsvid.vidTitle, newsvid.vidType, newsvid.size, newsvid.url, newsvid.vidSD, newsvid.published, videoinformation.vidLD, videoinformation.vidYear, videoinformation.vidCity, videoinformation.vidZanr, videoinformation.vidZanr2, videoinformation.vidZanr3, videoinformation.vidQuality, videoinformation.vidTranslated, videoinformation.vidTime FROM newsvid, videoinformation WHERE newsvid.id = videoinformation.id AND approved='1'";
// Video type
$vType = isset($_GET['vType']) ? $_GET['vType'] : 'ALL';
$goodTypeParam = array("AnyType", "Film", "Serials", "Cartoon", "Anime");
if (in_array($vType, $goodTypeParam)) {
if($vType == 'AnyType'){}
else{$queryMain .= " AND newsvid.vidType ='".$_GET['vType']."'";}
}
//Video Genre one
$vGenre = isset($_GET['vGenre']) ? $_GET['vGenre'] : 'ALL';
$goodGenreParam = array("AnyGenre1", "Action", "Adventure", "Comedy", "Crime", "Faction", "Fantasy", "Historical", "Horror", "Mystery", "Paranoid", "Philosophical", "Political", "Realistic", "Romance", "Saga", "Satire", "Science-Fiction", "Slice-Of-Life", "Speculative", "Anime");
if (in_array($vGenre, $goodGenreParam)) {
if($vGenre == 'AnyGenre1'){}
else{$queryMain .= " AND ( videoinformation.vidZanr ='".$_GET['vGenre']."' OR videoinformation.vidZanr2 ='".$_GET['vGenre']."' OR videoinformation.vidZanr3 ='".$_GET['vGenre']."')";}
}
//Video Genre two
$vGenre2 = isset($_GET['vGenre2']) ? $_GET['vGenre2'] : 'ALL';
$goodGenre2Param = array("AnyGenre2", "Action2", "Adventure2", "Comedy2", "Crime2", "Faction2", "Fantasy2", "Historical2", "Horror2", "Mystery2", "Paranoid2", "Philosophical2", "Political2", "Realistic2", "Romance2", "Saga2", "Satire2", "Science-Fiction2", "Slice-Of-Life2", "Speculative2", "Anime2");
if (in_array(vGenre2, $goodGenre2Param)) {
if(vGenre2 == 'AnyGenre2'){}
else{$queryMain .= " AND ( videoinformation.vidZanr ='".$_GET['vGenre2']."' OR videoinformation.vidZanr2 ='".$_GET['vGenre2']."' OR videoinformation.vidZanr3 ='".$_GET['vGenre2']."')";}
}
//Video Genre three
$vGenre3 = isset($_GET['vGenre3']) ? $_GET['vGenre3'] : 'ALL';
$goodGenre3Param = array("AnyGenre3", "Action", "Adventure", "Comedy", "Crime", "Faction", "Fantasy", "Historical", "Horror", "Mystery", "Paranoid", "Philosophical", "Political", "Realistic", "Romance", "Saga", "Satire", "Science-Fiction", "Slice-Of-Life", "Speculative", "Anime");
if (in_array($vGenre, $goodGenre3Param)) {
if($vGenre3 == 'AnyGenre3'){}
else{$queryMain .= " AND ( videoinformation.vidZanr ='".$_GET['vGenre3']."' OR videoinformation.vidZanr2 ='".$_GET['vGenre3']."' OR videoinformation.vidZanr3 ='".$_GET['vGenre3']."')";}
}
// Video Years
$vYear = isset($_GET['vYear']) ? $_GET['vYear'] : 'ALL';
$goodYearParam = array("AnyYear", "2014", "2013", "2012", "2011", "2010", "2009", "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998", "1997");
if (in_array($vType, $goodYearParam)) {
if($vYear == 'AnyYear'){}
else{$queryMain .= " AND newsvid.vidYear ='".$_GET['vYear']."'";}
}
// Video City
$vCity = isset($_GET['vCity']) ? $_GET['vCity'] : 'ALL';
$goodCityParam = array("AnyCity", "Russian", "England");
if (in_array($vCity, $goodCityParam)) {
if($vCity == 'AnyCity'){}
else{$queryMain .= " AND newsvid.vidCity ='".$_GET['vCity']."'";}
}
//NEW of OLD
$order = isset($_GET['order']) ? $_GET['order'] : 'ALL';
$goodParam = array("NEW", "OLD");
if (in_array($order, $goodParam)) {
if($order == 'NEW'){
$queryMain .= " ORDER BY newsvid.id ASC";
}else if($order == 'OLD'){
$queryMain .= " ORDER BY newsvid.id DESC";
}else{
$queryMain .= " AND videoinformation.vidYear = 2014";
}
}
?>
And this is main page view.php:
<!DOCTYPE lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<?php include 'BSH.php' ?>
<link rel="stylesheet" type="text/css" href="CSS/sdvid.css">
<title><?php echo $lang['PAGE_TITLE_MAIN'] ?></title>
</head>
<body>
<?php
include_once 'userPages/check_login_status.php';
include_once 'incIndex/headerTop.php';
include 'connect/con.php';
include_once 'inc/sortOrder.php';
?>
<?php
$sqlPages = "SELECT COUNT(id) FROM newsvid WHERE approved='1'";
$queryPages = mysqli_query($con, $sqlPages);
$row = mysqli_fetch_row($queryPages);
// Here we have the total row count
$rows = $row[0];
// This is the number of results we want displayed per page
$page_rows = 1;
// This tells us the page number of our last page
$last = ceil($rows/$page_rows);
// This makes sure $last cannot be less than 1
if($last < 1){
$last = 1;
}
// Establish the $pagenum variable
$pagenum = 1;
// Get pagenum from URL vars if it is present, else it is = 1
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
// This makes sure the page number isn't below 1, or more than our $last page
if ($pagenum < 1) {
$pagenum = 1;
} else if ($pagenum > $last) {
$pagenum = $last;
}
// This sets the range of rows to query for the chosen $pagenum
$limit = "LIMIT " .($pagenum - 1) * $page_rows ."," .$page_rows;
// This is your query again, it is for grabbing just one page worth of rows by applying $limit
$queryMainList = $queryMain . $limit;
$resultDisplay = mysqli_query($con, $queryMainList);
// This shows the user what page they are on, and the total number of pages
$pagesTitle = "On website <b>$rows</b>";
$pagesOutOf = "Page <b>$pagenum</b> of <b>$last</b>";
// Establish the $paginationCtrls variable
$paginationCtrls = '';
// If there is more than 1 page worth of results
if($last != 1){
/* First we check if we are on page one. If we are then we don't need a link to
the previous page or the first page so we do nothing. If we aren't then we
generate links to the first page, and to the previous page. */
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= 'Previous ';
// Render clickable number links that should appear on the left of the target page number
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= ''.$i.' ';
}
}
}
// Render the target page number, but without it being a link
$paginationCtrls .= ''.$pagenum.' ';
// Render clickable number links that should appear on the right of the target page number
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= ''.$i.' ';
if($i >= $pagenum+4){
break;
}
}
// This does the same as above, only checking if we are on the last page, and then generating the "Next"
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' Next ';
}
}
$list = '';
while($row = mysqli_fetch_array($resultDisplay, MYSQLI_ASSOC)){
$list .= "<div class=\"panel-heading\">
<div><a class=\"panel-title btn-block\" href=\"details.php?id=".$row['id']."\"><h3>".$row['id']." | ".$row['vidTitle']."</h3></a></div>
</div>
<div class=\"panel-body\">
<div class=\"imgCover\"><img class=\"imageCover\"src=\"" . $row['url'] . "\"></div>
<div class=\"vidSD\">" . $row['vidSD'] . "</div>
<div class=\"vidDetails\">
<hr class=\"style-two\">
<table>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtYear'] . "</strong></td><td class=\"vidDetailsTD\">" . $row['vidYear'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtCity'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidCity'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtGenre'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidZanr'] ." , ". $row['vidZanr2'] ." , ". $row['vidZanr3'] . "</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtQuality'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidQuality'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtTranslatedBy'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidTranslated'] ."</td></tr>
<tr><td class=\"vidDetailsTD\"><strong>" . $lang['vtVideoTime'] . "</strong></td><td class=\"vidDetailsTD\">". $row['vidTime'] . "</td></tr>
</table>
</div></div>
<div class=\"panel-footer\">
<h6><strong>" . $lang['vsdAuthor'] . "</strong>".$row['addName']."</h6>
<div><h6><strong>" . $lang['vsdPublished'] . "</strong>" . $row['published'] . "</h6></div>
</div>";
}
mysqli_close($con);
?>
<div class="mainLeftCover">
<form action="view.php" method="GET">
<div class="input-group" style="width:180px">
<span class="input-group-addon" style="width:65px"><?php echo $lang['vidOrderTitleNew'] ?></span>
<select class="form-control" name = "order">
<option value="NEW">NEW</option>
<option value="OLD">OLD</option>
</select>
</div>
<?php
include_once 'inc/sortInc/sortType.php';
include_once 'inc/sortInc/sortGenre.php';
include_once 'inc/sortInc/sortGenre2.php';
include_once 'inc/sortInc/sortGenre3.php';
include_once 'inc/sortInc/sortYear.php';
include_once 'inc/sortInc/sortCity.php';
?>
<br><button type="submit" class="btn btn-default" style="width:180px">Submit</button>
</form>
<?php echo" <div id=\"pagination_controls\">" .$paginationCtrls. "</div>"; ?>
</div>
<?php
echo "<div class=\"maincover \" data-role=\"scrollbox\" data-scroll=\"vertical\">";
echo "<div class=\"panel panel-default\">";
echo" <div style=\"background-color:#fff\">" .$list. "</div>";
echo "</div></div>";
?>
Just for encase I gave full code. The problem is, that PAGINATION on it's own working fine... And ORDER function working fine separately as well. BUT TOGETHER they do not want to work. As result I have working pagination and if try to use sort it's just become empty page.
What I need..is somehow make sorting method working with pagination together, but i'm stuck how to do it.
I have this url when I'm using pagination:
http://example.net/view.php?pn=3
And this one when I'm using order:
http://example.net/view.php?order=NEW&vType=Film&vGenre=AnyGenre1&vGenre2=AnyGenre2&vGenre3=AnyGenre3&vYear=AnyYear&vCity=AnyCity
AND I need that URL will be like this:
http://example.net/view.php?pn=3&order=NEW&vType=Film&vGenre=AnyGenre1&vGenre2=AnyGenre2&vGenre3=AnyGenre3&vYear=AnyYear&vCity=AnyCity
That if you sort the page... it will remember how user was sort the list and open pages (pn=1, pn=2) will change.
May be some how save sort result and then use it in pagination..need to save it maybe when submit button pressed? But how can I save result from user???
<?php
session_start();
include_once 'dbconnect.php';
?>
<?php include ('head.php') ; ?>
<?php include ('menu.php') ; ?>
<?php if (isset($_SESSION['usr_id'])) { ?>
<?
$per_page = 15;
if (isset($_GET["page"])) {$page = $_GET["page"];}else {$page = 1;}
if (isset($_GET["order"])) {$order = $_GET["order"];}else {$order = username;}
$start_from = ($page-1) * $per_page;
if(isset($_GET['order']) && $_GET['order'] == 'user_id'){
$query = "select * from users order by user_id DESC limit $start_from, $per_page";}
if(isset($_GET['order']) && $_GET['order'] == 'username'){
$query = "select * from users order by username ASC limit $start_from, $per_page";}
if(isset($_GET['order']) && $_GET['order'] == 'posts'){
$query = "select * from users order by posts DESC limit $start_from, $per_page";}
$result = mysqli_query ($DBcon, $query);
$user_list_result = $DBcon->query("select * from users order by $order ASC limit 100");
$session = $_SESSION['usr_name'];
$query = $DBcon->query("SELECT * FROM users WHERE username='$session'");
$userRow=$query->fetch_array();
if ($userRow['userlevel'] > 0) {
?>
<div class="container">
<div class="row">
<div class="col-lg-6 col-sm-12">
<div class="panel panel-default panel-compact panel-wallet">
<div class="panel-body">
<center><h1>Userlist </h1></center>
<center>
<table >
<tr> <td width="20%"><b>ID </b></td>
<td width="20%"><b>Nickname </b></td>
<td width="20%"><b>Posts </b></td>
<td width="20%"><b>Message </b></td>
<td width="20%"><b>Click </b></td> </tr>
<?php
while($UserlistRow = $result->fetch_array())
{
echo "
<tr>
<td>$UserlistRow[user_id]</td>
<td><a href=user_profile.php?user=$UserlistRow[username]>$UserlistRow[username]</a></td>
<td>$UserlistRow[posts]</td>
</center>
<td><a href=msg_send.php?to=$UserlistRow[username]>Send Message</a></td>
<td><a href=user_click.php?to=$UserlistRow[username]>Click</a></td> ";?>
</tr>
<?php } ?> </table>
</center>
<?
$query = "select * from users order by $order";
$result = mysqli_query($DBcon, $query);
$total_records = mysqli_num_rows($result);
$total_pages = ceil($total_records / $per_page);
echo "<a href='user_list.php?page=" . ($_GET['page']+1) . "&order=" . ($_GET['order']) . "'>Next Page</a>";
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='user_list.php?page=".$i."&order=" . ($_GET['order']) . "'>".$i."</a> ";
};
echo "<a href='user_list.php?page=" . ($_GET['page']-1) . "&order=" . ($_GET['order']) . "'>Previous Page</a>";
?>
</div>
</div>
</div>
</div>
</div>
<?php } ?>
<?php } else { include('login_frame.php'); } ?>
<?php include ('footer.php') ; ?>
I have a webpage i am working on, the link is:
http://nexusdesign.org.uk/irejobs/training-courses.html
The code for which is below. Now in the backend i have created entries for the training courses as shown but these arent showing, From what i can father these should be pulled from the database db_trainings both into here and the seperate feature box below,
Can anyone advise whats going wrong here ??
<?php
ob_start();
require_once("conn.php");
$pagename = "training";
$submenu = "trainings";
require_once("header.php");
require_once("pager.php");
$__table = "db_trainings";
$__page = $_SERVER['PHP_SELF'];
$__id = "TrainingID";
$__uploadfolder = "myimages/";
$NUM_COL = 2;
$NUM_ROW = 5;
$perPage = $NUM_COL * $NUM_ROW;
$page=isset($_GET['page']) ? intval($_GET['page']):1;
$MemberID = $_GET['MemberID'];
if($MemberID != "")
$andmember = " and MemberID = '".$MemberID."'";
$category = "";
$i = 0;
$r1 = mysql_query("select * from db_training_categories") or die(mysql_error());
while($a1 = mysql_fetch_array($r1))
{
if($_GET['category-'.$a1['CatID']] == "1")
{
if($i != 0)
$andcategory .= " or ";
$andcategory .= " t.category = ".$a1['CatID'];
$i++;
}
}
if($andcategory != "")
$andcategory = " and (".$andcategory.")";
$city = $_GET['city'];
if($city == "enter city")
$city = $_GET['citys'];
if($city != "" and $city != "enter city")
$andcity = " and t.city = '".$city."'";
$country = $_GET['country'];
if($country != "")
$andcountry = " and t.country = '".$country."'";
$stxt = $_GET['srchTxt'];
if($stxt == "enter keywords")
$stxt = $_GET['srchTxts'];
if($stxt != "" and $stxt != "enter keywords")
{
$srchTxt = " and (t.title like '".$stxt."%' or t.title like '%".$stxt."' or t.title like '%".$stxt."%'";
$srchTxt .= " or t.provider like '".$stxt."%' or t.provider like '%".$stxt."' or t.provider like '%".$stxt."%'";
$srchTxt .= " or t.city like '".$stxt."%' or t.city like '%".$stxt."' or t.city like '%".$stxt."%'";
$srchTxt .= " or t.terms like '".$terms."%' or t.city like '%".$stxt."' or t.terms like '%".$stxt."%'";
$srchTxt .= " or t.price like '".$stxt."%' or t.price like '%".$stxt."' or t.price like '%".$stxt."%'";
$srchTxt .= " or t.duration like '".$stxt."%' or t.duration like '%".$stxt."' or t.duration like '%".$stxt."%'";
$srchTxt .= " or t.qualification like '".$stxt."%' or t.qualification like '%".$stxt."' or t.qualification like '%".$stxt."%'";
$srchTxt .= " or t.awardingbody like '".$stxt."%' or t.awardingbody like '%".$stxt."' or t.awardingbody like '%".$stxt."%'";
$srchTxt .= " or t.description like '".$stxt."%' or t.description like '%".$stxt."' or t.description like '%".$stxt."%'";
$srchTxt .= " )";
}
if ($_GET['sortby'] == "newest") {
$sortby = "newest";
$sortbyt = " order by t.TrainingID desc";
}
elseif ($_GET['sortby'] == "oldest") {
$sortby = "oldest";
$sortbyt = " order by t.TrainingID asc";
}
else
$sortbyt = " order by t.TrainingID desc";
$textQuery = "select *,t.city,t.country from db_trainings t, db_members m where t.MemberID <> '' and t.MemberID = m.MemberID and m.advertisementexpiry > 0 and t.active = 'yes' ". $andmember . $andcountry . $andcity . $andcategory . $andmember . $srchTxt . $sortbyt;
//for paging
$ress = mysql_query($textQuery);
$total=mysql_num_rows($ress);
$maxpage = floor($total/$perPage);
if($total%$perPage !=0)
$maxpage += 1;
if($page == 0)
{
$start = 0;
$page = 1;
}
else
$start = ($perPage * $page) - $perPage;
$stop = $start + $perPage;
$qry = $textQuery." limit $start, $perPage";
//echo $qry;
$r = mysql_query($qry);
?>
<script language="javascript">
function showRecords(id)
{
document.frmItems.page.value = id;
document.frmItems.method = "get";
document.frmItems.action = "training-courses.html";
document.frmItems.submit();
}
function validateForm()
{
document.frm.action = "training-courses.html";
document.frm.submit();
}
</script>
<div id="container">
<div class="wrap">
<div class="corner-box-bot">
<?
if($_SESSION['MemberType'] == 'Employer')
include("employer-menu.html");
elseif($_SESSION['MemberType'] == 'Seeking')
include("seeker-menu.html");
elseif($_SESSION['MemberType'] == 'Training')
include("training-menu.html");
?>
<div class="content">
<div style="float:left;width:280px;"><h1>Training & Skills</h1>
<strong class="blue" style="line-height: 31px; font-size: 14px;">
Upgrade
your skills and qualifications?<br />
Find out what's available near you:
<br /><br />
</strong></div>
<div style="float:right;width:550px;">
<p><strong>Training providers: </strong>use www.PaediatricNursingJobs.com to effectively promote your courses to students in the UK & internationally .</p>
<strong>Reach out and speak to a global market of clients and students</strong>
<?
if($_SESSION['MemberID'] == "")
echo "<a href='login-training.html' class='blue-btn-04' style='font-size:13px;margin-top:20px;'>ADVERTISE YOUR COURSES HERE</a>";
else
echo "<a href='training-courses-add.html' class='blue-btn-04' style='font-size:13px;margin-top:20px;'>ADVERTISE YOUR COURSES HERE</a>";
?>
</div>
<div class="clear"></div>
<form name="frmItems" id="frmItems">
<input type="hidden" name="page" value="">
<input type="hidden" name="MemberID" value="<?=$MemberID?>">
<input type="hidden" name="srchTxts" value="<?=$stxt?>">
<div class="side_bar">
<h1 style="line-height:1;">Advanced Search</h1>
<h2 class="blue">Course Location</h2>
<div class="custom-select-2" id="select-box-01">
<select name="country">
<option value="">select country</option>
<?
$r2 = mysql_query("select * from db_countries order by Name = 'United Kingdom' desc, Name") or die(mysql_error());
while($a2 = mysql_fetch_array($r2))
{
if($a2['CountryID'] == $country)
echo "<option value='".$a2['CountryID']."' selected>".$a2['Name']."</option>";
else
echo "<option value='".$a2['CountryID']."'>".$a2['Name']."</option>";
}
?>
</select>
</div>
<div class="custom-select-2" id="select-box-02">
<input type='text' name='city' class='txt-field-2' value='enter city' />
</div>
<div class="clear"></div>
<div style="border-top: 1px solid #d4d4d4; padding-top: 20px; margin-top: 10px;">
<h2 class="blue">Course Subject</h2>
<div class="custom-select-2" id="select-box-04">
<?
$r1 = mysql_query("select * from db_training_categories order by CatName") or die(mysql_error());
while($a1 = mysql_fetch_array($r1))
{
if($_GET['category-'.$a1['CatID']] == "1")
echo "<input type='checkbox' name='category-".$a1['CatID']."' value='1' checked /> ".$a1['CatName']."<br />";
else
echo "<input type='checkbox' name='category-".$a1['CatID']."' value='1' /> ".$a1['CatName']."<br />";
}
?>
</div>
</div>
<div style="border-top: 1px solid #d4d4d4; padding-top: 20px; margin-top: 20px;">
Search for course
</div>
</div>
<div class="col_710 r-content">
<?
if(mysql_num_rows($r) > 0)
{
$query = $_SERVER['QUERY_STRING'];
$arr = explode('&', $query);
if(strchr($arr[count($arr)-1],'page')!='')
array_pop($arr);
$purl = 'training-courses.html?'.implode('&', $arr);
?>
<div class="search-box">
<div>
<label>Training Title (e.g. Nurse)</label>
<input type="text" class="txt-field" name="srchTxt" />
</div>
<div>
<label>Training Location (e.g. Bristol)</label>
<input type="text" class="txt-field" name="citys" value="<?=$city?>" />
</div>
Search
<div class="clear"></div>
</div>
<div class="clear"></div>
<div class="sort-bar">
<span style="float: left; display: block; padding-top: 4px; width: 420px;"><strong class="blue"><?=$total?> courses found</strong></span>
<span style="float: left; display: block; padding-top: 4px;">Sort by</span>
<div class="custom-select-2" id="select-box-05">
<select name="sortby" id="sortby" class="input" onChange="showRecords(1);">
<option value="newest" <? if($_GET['sortby']=='newest') echo "selected"; ?>>Newest</option>
<option value="oldest" <? if($_GET['sortby']=='oldest') echo "selected"; ?>>Oldest</option>
</select>
</div>
<div class="clear"></div>
</div>
<div style="padding: 25px 0 0 25px;">
<?
$i=0;
while($a = mysql_fetch_array($r))
{
$r1 = mysql_query("select * from db_members where MemberID = '".$a['MemberID']."'") or die(mysql_error());
$a1 = mysql_fetch_array($r1);
$r2 = mysql_query("select * from db_categories where CatID = '".$a['category']."'") or die(mysql_error());
$a2 = mysql_fetch_array($r2);
$r3 = mysql_query("select * from db_countries where CountryID = '".$a['country']."'") or die(mysql_error());
$a3 = mysql_fetch_array($r3);
$r4 = mysql_query("select * from db_training_categories where CatID = '".$a['category']."'") or die(mysql_error());
$a4 = mysql_fetch_array($r4);
echo "
<div class='block-result'>
<img alt='' src='".$__uploadfolder.$a['logo']."' width='134' />
<div class='desc'>
<a href='training-courses-view.html?TrainingID=".$a['TrainingID']."'> ".cleaninput($a['title'],"ss|he|tr")."</a>
<span class='blue'>Location:</span> ".cleaninput($a['city'].", ".$a3['Name'],"ss|he|tr")."<br/>
<span class='blue'>Sector:</span> ".cleaninput($a4['CatName'],"ss|he|tr")."<br/>
<span class='blue'>Price:</span> ".$currency.cleaninput($a['price'],"ss|he|tr")."<br/>
<span class='blue'>Duration:</span> ".cleaninput($a['duration'],"ss|he|tr")." hours<br/>
</div>
</div>
";
$i++;
}
?>
</div>
<?
if($maxpage > 1)
echo showpage($page,$purl,$total,$maxpage,$perPage);
}
else
echo "
<div class='sort-bar' style='margin-top: 0px'>
<span style='float: left; display: block; padding-top: 4px; width: 420px;'><strong class='blue'>No results found...</strong></span>
<div class='clear'></div>
</div>
";
?>
</div>
</form>
<div class="clear"></div>
</div>
</div>
<? include("bottom-featuredcourses.php"); ?>
<div class="clear"></div>
</div>
</div>
<?php
require_once("footer.php");
ob_flush();
?>
From the comments above:
all of the members tables show advertisementexpiry at 0
Your query tries to match anything with advertisementexpiry > 0. That means the query will never match any rows since none are greater than 0.
you need to break down this bit t.MemberID <> '' and t.MemberID = m.MemberID and m.advertisementexpiry > 0 and t.active = 'yes'
test each piece to debug
t.MemberID <> ''
looks like its not needed as i am pursuming every member has a id.