How to keep sorting order when using pagination? - javascript

I can't figure how to keep sort order when I click on next page. On that page products aren't sorted by selected option, and this is problem. When option Naziv is clicked, only on first page products are sorted by Naziv and when going to next page products aren't sorted by Naziv and they should be.
I've tried with:
page=$next&order=$order. But this doesn't work correctly.
Does anyone have some advice how to fix this.
<html>
<body>
<div>
<div id="container">
<div>
<select name="filter" onchange="window.location.href = 'laptop?order=' + this.value">
<option>Poredaj po: </option>
<option value="naziv">Naziv</option>
<option value="cijenaasc">Cijena Manja-Veća</option>
<option value="cijenadesc">Cijena Veća-Manja</option>
</select>
<form id="Forma" method='post' action="usporedi">
<?php
// 5. record shown amount
$per_page = 10;
// 7. current page
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
// 4. mysql start possition
if ($page <= 1) {
$start = 0;
} else {
$start = $page * $per_page - $per_page;
}
// 2. main sql query
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='laptop'";
$order = isset($_GET['order']) ? $_GET['order'] : '';
if ($order) {
switch ($order) {
case 'cijenaasc':
$order = 'cijena';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='laptop' ORDER BY CAST(cijena AS DECIMAL(8,2)) ASC ";
break;
case 'naziv':
$order = 'naziv';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='laptop' ORDER BY naziv ASC ";
break;
case 'cijenadesc':
$order = 'cijena';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='laptop' ORDER BY CAST(cijena AS DECIMAL(8,2)) DESC ";
break;
}
}
// 7. How much records are in database
$num_rows = mysqli_num_rows(mysqli_query($con, $query));
// 7. How much pages are at all
$num_pages = ceil($num_rows / $per_page);
// 6. Appends limit for shown records
$query .= " LIMIT $start, $per_page";
// 3. Show all records
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$id = $row ['id'];
print
"<div id='proizvod'></br><a style='text-decoration:none; color:black;' class='two' href='proizvod.php?id=$id' >" . $row["naziv"] . "" .
"<p><img src=" . $row["slika"] . " width='200px' height='200px' style='border-radius: 15px;'></p>" .
"<p style='font-size:20px'><b> Cijena za gotovinu: " . $row["cijena"] . " KN </b></p>" .
"<pre id='pre1'>" . $row["opis"] . "</pre>" .
"</a></div>";
}
?>
</form>
</div>
<br/>
<div id="pagination">
<?php
// 8. Prev numbers, next links
$prev = $page - 1;
$next = $page + 1;
// prev
if ($prev > 0) {
echo "<a style='text-decoration:none; color: blue;' href='?page=$prev&order=$order'><b><</b></a> ";
}
//numbers
$number = 1;
for ($number; $number <= $num_pages; $number +=1) {
if ($page == $number) {
echo " <b> $number </b> ";
} else {
echo " <a style='text-decoration:none; color: blue;' href='?page=$number&order=$order'>$number</a> ";
}
}
// next
if ($page < ceil($num_rows / $per_page)) {
echo " <a style='text-decoration:none; color: blue;' href='?page=$next&order=$order'><b>></b></a> ";
}
?>
</div>
</div>
</body>
</html>

To keep sort order when paging trough pages variable
$order = isset($_GET['order']) ? $_GET['order'] : '';
must be in "div id='pagination'".
<html>
<body>
<div id="container">
<?php
$per_page = 10;
if (!isset($_GET['page'])) {
$page = 1;
} else {
$page = $_GET['page'];
}
if ($page <= 1) {
$start = 0;
} else {
$start = $page * $per_page - $per_page;
}
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY id ASC ";
// 7. How much records are in database
$num_rows = mysqli_num_rows(mysqli_query($con, $query));
// 7. How much pages are at all
$num_pages = ceil($num_rows / $per_page);
?>
<div id="gumb">
<div id="usporedivanje">
<input type='submit' form='Forma' name='usporedi' disabled='disabled' id='usporedi' value='Usporedi' onmouseover="" style="cursor: pointer;" />
<div id='sortiranje'>
<select id='filter' style="font-size:20px; height:50px; border: 5px solid #099CDB; border-radius: 10px; border-color: #099bcd;" name="filter" onchange="window.location.href = 'smartphone?order=' + this.value">
<option>Poredaj po: </option>
<option value="naziv">Naziv</option>
<option value="cijenaasc">Cijena Manja-Veća</option>
<option value="cijenadesc">Cijena Veća-Manja</option>
</select>
</div>
</div>
<br/>
<form id="Forma" method='post'>
<?php
$order = isset($_GET['order']) ? $_GET['order'] : '';
if ($order) {
switch ($order) {
case 'cijenaasc':
$order = 'cijena';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY CAST(cijena AS DECIMAL(8,2)) ASC ";
break;
case 'naziv':
$order = 'naziv';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY naziv ASC ";
break;
case 'cijenadesc':
$order = 'cijena';
$query = "SELECT *, FORMAT(cijena,2,'de_DE') as cijena FROM artikli WHERE kategorija='smartphone' ORDER BY CAST(cijena AS DECIMAL(8,2)) DESC ";
break;
}
}
$query .= " LIMIT $start, $per_page";
$result = mysqli_query($con, $query);
while ($row = mysqli_fetch_array($result)) {
$id = $row ['id'];
print
"<div id='proizvod'></br><a style='text-decoration:none; color:black; font-size:20px;' class='two' href='proizvod.php?id=$id' ><b>" . $row["naziv"] . "</b>" .
"<p><img src=" . $row["slika"] . " width='200px' height='200px' style='border-radius: 15px;'></p>" .
"<p style='font-size:20px'><b> Cijena za gotovinu: " . $row["cijena"] . " KN </b></p>" .
"<pre id='pre1'>" . $row["opis"] . "</pre>" .
"</a></div>";
}
?>
</form>
<div id="pagination">
<?php
$prev = $page - 1;
$next = $page + 1;
$order = isset($_GET['order']) ? $_GET['order'] : '';
if ($prev > 0) {
echo "<a style='text-decoration:none; font-size:30px; color: #099BCD;' href='?page=$prev&order='$order'><b><</b></a> ";
}
$number = 1;
for ($number; $number <= $num_pages; $number +=1) {
if ($page == $number) {
echo " <b style='font-size:30px; color: #099BCD;'> $number </b> ";
} else {
echo " <a style='text-decoration:none; font-size:30px; color: #099BCD;' href='?page=$number&order=$order'>$number</a> ";
}
}
if ($page < ceil($num_rows / $per_page)) {
echo " <a style='text-decoration:none; font-size:30px; color: #099BCD;' href='?page=$next&order=$order'><b>></b></a> ";
}
?>
</div>
</div>
<?php include "footer.php"; ?>
</body>
</html>

Related

How to add PHP Pagination in image gallery

I want to add pagination in my image gallery. But it is showing all images in one page instead of 6 images on one page. How can I achieve this ? please help
<?php
echo "<html><head><title>Image</title></head><body>";
$rec_limit = 3;
$conn = mysqli_connect("localhost", "root", "test123#", "imagesdatabase") or die("unable to connect");
$rootPath = '/var/www/html/';
require_once $rootPath.'app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objManager = $bootstrap->getObjectManager();
$state = $objManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$resource = $objManager->get('\Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection('core_write');
$rec_count = 20;
if( isset($_GET{'page'} ) ) {
$page = $_GET{'page'} + 1;
$offset = $rec_limit * $page ;
}else {
$page = 0;
$offset = 0;
}
$left_rec = $rec_count - ($page * $rec_limit);
$url = "www.testwebsite.com". $_SERVER['PHP_SELF'] ;
$entity_ids = mysqli_query($conn,"SELECT e.entity_id,g.value_id,g.value from catalog_product_entity_media_gallery g join catalog_product_entity_media_gallery_value v on (g.value_id = v.value_id) join catalog_product_entity e on (v.entity_id = e.entity_id) where e.attribute_set_id = 62");
while ( $row=mysqli_fetch_array($entity_ids,MYSQLI_ASSOC)) {
//print_r($row);
$entity_id = $row['entity_id'];
$image = $row['value'];
echo $entity_id;
echo '<img src="www.testwebsite.com/pub/media/catalog/product/'.$image.'" alt="Image" width="200px" height="200px"/></a>';
}
echo "<br>";
if( $page > 0 ) {
$last = $page - 2;
echo "Last 10 Records |";
echo "Next 10 Records";
}else if( $page == 0 ) {
echo "Next 10 Records";
}else if( $left_rec < $rec_limit ) {
$last = $page - 2;
echo "Last 10 Records";
}
//mysql_close($conn);
echo "</body></html>";
Images are showing correct but I just want to add pagination and show only 6 images on each page.
Any help would be appreciated . Thanks
After so much patience I have understood each criteria to add pagination and use bootstrap pagination ..
Below is my answer. hope it will help someone.
<!DOCTYPE html>
<html>
<head>
<title>Images Grid View</title>
<style type="text/css">
#thumb {
clear : both;
width : 100%;
margin-left : 0;
}
#thumb ul {
width : 100%;
}
#thumb ul li {
display : inline;
font-family : arial;
float : left;
padding-right : 5px;
width: 210px;
height : 280px;
}
#thumb ul li img {
float : left;
width : 200px;
height : 200px;
border : #ccc solid 1px;
padding : 2px;
}
</style>
</head>
<body>
<?php
$conn = mysqli_connect("localhost", "root", "test123#", "imagesdatabase") or die("unable to connect");
$rootPath = '/htdocs/stage6/html/';
require_once $rootPath.'app/bootstrap.php';
$bootstrap = \Magento\Framework\App\Bootstrap::create(BP, $_SERVER);
$objManager = $bootstrap->getObjectManager();
$state = $objManager->get('\Magento\Framework\App\State');
$state->setAreaCode('frontend');
$resource = $objManager->get('\Magento\Framework\App\ResourceConnection');
$connection = $resource->getConnection('core_write');
$rec_limit = 6;
$rec_count = 50;
if (isset($_GET['pageno'])) {
$pageno = $_GET['pageno'];
} else {
$pageno = 1;
}
$no_of_records_per_page = 12;
$offset = ($pageno-1) * $no_of_records_per_page;
$total_pages_sql = "SELECT count(e.entity_id) from catalog_product_entity_media_gallery g join catalog_product_entity_media_gallery_value v on (g.value_id = v.value_id) join catalog_product_entity e on (v.entity_id = e.entity_id) where e.attribute_set_id = 62";
$result = mysqli_query($conn,$total_pages_sql);
$total_rows = mysqli_fetch_array($result)[0];
$total_pages = ceil($total_rows / $no_of_records_per_page);
$entity_ids = mysqli_query($conn,"SELECT e.entity_id,g.value_id,g.value from catalog_product_entity_media_gallery g join catalog_product_entity_media_gallery_value v on (g.value_id = v.value_id) join catalog_product_entity e on (v.entity_id = e.entity_id) where e.attribute_set_id = 62 limit $offset, $no_of_records_per_page");
echo '<div id="thumb"><ul>';
while ( $row=mysqli_fetch_array($entity_ids,MYSQLI_ASSOC)) {
$entity_id = $row['entity_id'];
$image = $row['value'];
echo '<li><p>' . $entity_id .'</p>';
echo '<img src="https://testwebsite.com/pub/media/catalog/product/'.$image.'" alt="Image" /></a>';
echo '</li>';
}
echo '</ul></div>';
?>
<center>
<ul class="pagination" style="list-style-type:none; display:-webkit-inline-box !important; float: left; font-size: 24px;">
<li style="background-color:gray;">First</li>
<li style="background-color:gray;" class="<?php if($pageno <= 1){ echo 'disabled'; } ?>">
Prev
</li>
<li style="background-color:gray;" class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>">
Next
</li>
<li style="background-color:gray;">Last</li>
</ul>
</center>
</body>
</html>

Bootstrap 3.3.7 hidden-lg-up not working

I'm trying to design a a mobile version of a game I've been working on. Apologies for the messy code, it's nothing serious. I've decided to use a hamburger-menu for the mobile version and want to hide it on desktop devices. For this I found "hidden-lg-up" in the bootstrap documentation but it doesn't seem to be working. I at least know that the bootstrap js is loaded because if I change the name I get an error in the browser console.
The element I'm trying this with is the "hamburger-menu-toggle" and "hamburger-menu".
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CEO Panel</title>
<link rel="shortcut icon" href="favicon.png?v=1"/>
<link rel="stylesheet" href="css/main.css">
<!-- JQUERY -->
<script src="js/libs/jquery-3.1.0.min.js"></script>
<script src="js/libs/jquery-ui-1.12.0/jquery-ui.min.js"></script>
<!-- LIBS AND PLUGINS -->
<script src="js/libs/jquery-mousewheel-3.1.13/jquery.mousewheel.min.js"></script>
<script src="js/libs/mapbox.js/jquery.mapbox.js"></script>
<script src="js/libs/countdown/jquery.countdown.min.js"></script>
<script src="js/libs/jquery.ui.touch-punch.min.js"></script>
<!-- GAME JS -->
<script src="js/game_logic/main.js"></script>
<script src="js/game_logic/buttons.js"></script>
<script src="js/libs/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
</head>
<body>
<main>
<div id="map-wrapper">
<img id="map" src="res/los_santos_map.png" alt="Los Santos Map">
<div id="map-content">
<!--<div class="map-marker owned" id="warehouse1"></div>
<div class="map-marker for-sale" id="warehouse2"></div>-->
<?php
$pdo = pdo();
$username = $_SESSION['username'];
foreach($pdo->query("SELECT * FROM warehouses") as $row){
$warehouse_id = $row['id'];
$statement = $pdo->prepare("SELECT * FROM warehouse_contracts WHERE warehouse_id LIKE '$warehouse_id' AND username LIKE '$username'");
$statement->execute();
$rowCount = $statement->rowCount();
//find out the size of the warehouse
if($row['slots'] < 64){
$size = "small";
}
else if($row['slots'] >= 64 && $row['slots'] < 256){
$size = "medium";
}
else{
$size = "large";
}
//find out if it's owned by the user
if($rowCount>0){
echo '<div class="map-marker owned ' . $size . '" id="warehouse' . $row['id'] . '" style="top: ' . $row['y'] . 'px; left: ' . $row['x'] . 'px;"></div>';
}
else{
echo '<div class="map-marker for-sale ' . $size . '" id="warehouse' . $row['id'] . '" style="top: ' . $row['y'] . 'px; left: ' . $row['x'] . 'px;"></div>';
}
}
?>
</div>
</div>
<div style="background-image: url('res/radar-overlay.png'); width: 100%; height: 100%; position: fixed; background-size: cover; opacity: 0.2; pointer-events: none;"></div>
<div id="HUD">
<div id="hamburger-menu-toggle" class="hidden-lg-up">
<div></div>
<div></div>
<div></div>
</div>
<div id="hamburger-menu" class="hidden-lg-up">
</div>
<div id="logout" class="button">LOGOUT</div>
<?php
if(isset($_SESSION['admin']) && $_SESSION['admin'] === "TRUE"){
echo '
<div id="admin-stats">
<h1>map.x: <span id="map_x"></span><br>map.y: <span id="map_y"></span></h1>
<h1>map.height: <span id="map_height"></span><br>map.width: <span id="map_width"></span><br>mouse.x: <span id="mouse_x"></span><br>mouse.y: <span id="mouse_y"></span></h1>
</div>
';
}
?>
<h1 id="cash">
<?php
$pdo = pdo();
$username = $_SESSION['username'];
$statement = $pdo->prepare("SELECT cash FROM users WHERE username LIKE '$username'");
$statement->execute();
$results = $statement->fetch();
echo '$' . number_format($results['cash']);
?>
</h1>
<div id="warehouse-toggle">
<div class="button toggle-selected">ALL</div>
<div class="button toggle">OWNED</div>
<div class="button toggle">SMALL</div>
<div class="button toggle">MEDIUM</div>
<div class="button toggle">LARGE</div>
</div>
<div id="stock-actions">
<?php
$pdo = pdo();
$username = $_SESSION['username'];
$statement = $pdo->prepare("SELECT * FROM shipments WHERE status LIKE 'active' AND username LIKE ?");
$statement->bindParam(1, $username);
$statement->execute();
$row_count = $statement->rowCount();
if($row_count == 0){
echo '
<div id="buy-stock-button" class="button">BUY</div>
';
$statement = $pdo->prepare("SELECT * FROM storage WHERE username LIKE ?");
$statement->bindParam(1, $username);
$statement->execute();
$row_count = $statement->rowCount();
if($row_count > 0){
echo '
<div id="sell-stock-button" class="button">SELL</div>
';
}
else{
echo '
<div id="sell-stock-button" class="button disabled">SELL</div>
';
}
}
else{
echo '
<div id="buy-stock-button" class="button disabled">BUY</div>
<div id="sell-stock-button" class="button disabled">SELL</div>
';
}
?>
<div id="upgrades-button" class="button">UPGRADES</div>
</div>
<div id="page-toggle">
<div class="button toggle">SUMMARY PAGE</div>
<div class="button toggle-selected">WAREHOUSE MAP</div>
</div>
<div class="dialog" id="owned-warehouse-dialog">
<div class="close-button">x</div>
</div>
<div class="dialog" id="buy-warehouse-dialog">
<div class="close-button">x</div>
<?php
/*
$pdo = pdo();
$warehouse_id = $_GET['warehouse_id'];
$statement = $pdo->prepare("SELECT * FROM warehouses WHERE id LIKE ?");
$statement->bindParam(1, $warehouse_id);
$statement->execute();
$warehouse = $statement->fetch();
echo '
<h1>WAREHOUSE ' . $warehouse_id . '</h1>
<p>STATUS:<span class="right-text">FOR SALE</span></p>
<p>WAREHOUSE SLOTS:<span class="right-text">' . $warehouse['slots'] . '</span></p>
<p>COST:<span class="right-text">' . $warehouse['price'] . '</span></p>
<div class="submit-button">BUY</div>
';
*/
?>
</div>
<div class="dialog" id="buy-warehouse-dialog"></div>
<div class="dialog" id="buy-stock-dialog">
<div class="close-button">x</div>
<form action="index.php?action=buy_crates" method="post">
<h1>BUY CARGO CRATES</h1>
<p>TYPE</p>
<div class="selection-list">
<?php
$pdo = pdo();
foreach($pdo->query("SELECT * FROM crate_types") as $row){
echo '<div class="button toggle">' . strtoupper($row['name']) . '</div>';
}
?>
<input class="hidden" name="type" type="text" required>
</div>
<p>QUANTITY</p>
<div class="selection-list">
<?php
$pdo = pdo();
$username = $_SESSION['username'];
$statement = $pdo->prepare("SELECT SUM(slots) FROM warehouses INNER JOIN warehouse_contracts ON warehouses.id=warehouse_contracts.warehouse_id WHERE username LIKE '$username'");
$statement->execute();
$slots = $statement->fetch();
$statement = $pdo->prepare("SELECT SUM(quantity) FROM storage WHERE username LIKE ?");
$statement->bindParam(1, $username);
$statement->execute();
$crates = $statement->fetch();
$statement = $pdo->prepare("SELECT * FROM transport_upgrades WHERE username LIKE ? AND type LIKE 'storage'");
$statement->bindParam(1, $username);
$statement->execute();
$storage_upgrades = $statement->rowCount() + 1;
$available_slots = $slots['SUM(slots)'] - $crates['SUM(quantity)'];
if($available_slots >= 1 * pow(2, $storage_upgrades)){
echo '<div class="button toggle">' . 1 * pow(2, $storage_upgrades) . '</div>';
}
else{
echo '<div class="disabled">' . 1 * pow(2, $storage_upgrades) . '</div>';
}
if($available_slots >= 2 * pow(2, $storage_upgrades)){
echo '<div class="button toggle">' . 2 * pow(2, $storage_upgrades) . '</div>';
}
else{
echo '<div class="disabled">' . 2 * pow(2, $storage_upgrades) . '</div>';
}
if($available_slots >= 4 * pow(2, $storage_upgrades)){
echo '<div class="button toggle">' . 4 * pow(2, $storage_upgrades) . '</div>';
}
else{
echo '<div class="disabled">' . 4 * pow(2, $storage_upgrades) . '</div>';
}
if($available_slots >= 8 * pow(2, $storage_upgrades)){
echo '<div class="button toggle">' . 8 * pow(2, $storage_upgrades) . '</div>';
}
else{
echo '<div class="disabled">' . 8 * pow(2, $storage_upgrades) . '</div>';
}
if($available_slots >= 16 * pow(2, $storage_upgrades)){
echo '<div class="button toggle">' . 16 * pow(2, $storage_upgrades) . '</div>';
}
else{
echo '<div class="disabled">' . 16 * pow(2, $storage_upgrades) . '</div>';
}
if($available_slots >= 32 * pow(2, $storage_upgrades)){
echo '<div class="button toggle">' . 32 * pow(2, $storage_upgrades) . '</div>';
}
else{
echo '<div class="disabled">' . 32 * pow(2, $storage_upgrades) . '</div>';
}
if($available_slots < 1 * pow(2, $storage_upgrades)){
echo '
<input class="hidden" name="quantity" type="text" required>
</div>
<p>RISK:<span class="right-text" id="delivery-risk">0%</span></p>
<p>PROFIT MARGIN:<span class="right-text" id="delivery-profit">0%</span></p>
<p>PRICE:<span class="right-text" id="delivery-price">$0</span></p>
<input class="submit-button disabled" type="submit" value="BUY">
';
}
else{
echo '
<input class="hidden" name="quantity" type="text" required>
</div>
<p>RISK:<span class="right-text" id="delivery-risk">0%</span></p>
<p>PROFIT MARGIN:<span class="right-text" id="delivery-profit">0%</span></p>
<p>PRICE:<span class="right-text" id="delivery-price">$0</span></p>
<input class="submit-button" type="submit" value="BUY">
';
}
?>
</form>
</div>
<div class="dialog" id="sell-stock-dialog">
<div class="close-button">x</div>
<?php
$pdo = pdo();
$statement = $pdo->prepare("SELECT SUM((price*((profit/100)+1))*quantity), SUM(price*quantity), SUM(quantity), AVG(profit) FROM storage INNER JOIN crate_types ON storage.crate_type_id=crate_types.id WHERE username LIKE ?");
$statement->bindParam(1, $username);
$statement->execute();
$rows = $statement->fetch();
$quantity = $rows['SUM(quantity)'];
$value = round($rows['SUM((price*((profit/100)+1))*quantity)'], 0);
$original_cost = round($rows['SUM(price*quantity)'], 0);
$profit_margin = round($rows['AVG(profit)'], 0);
echo '
<h1>SELL CARGO CRATES</h1>
<p>CRATES: <span class="right-text">' . $quantity . '</span></p>
<p>RISK: <span class="right-text"></span></p>
<p>PROFIT MARGIN: <span class="right-text">' . $profit_margin . '%</span></p>
<p>ORIGINAL COST: <span class="right-text">$' . number_format($original_cost) .'</span></p>
<p>PROFIT: <span class="right-text">$' . number_format($value - $original_cost) . '</span></p>
<p>TOTAL VALUE: <span class="right-text">$' . number_format($value) .'</span></p>
<div class="submit-button">SELL</div>
';
?>
</div>
<?php
$pdo = pdo();
$username = $_SESSION['username'];
$statement = $pdo->prepare("SELECT * FROM shipments WHERE username LIKE '$username' AND status LIKE 'active' LIMIT 1");
$statement->execute();
$row_count = $statement->rowCount();
$row1 = $statement->fetch();
$statement = $pdo->prepare("SELECT * FROM shipments INNER JOIN crate_types ON shipments.crate_type_id=crate_types.id WHERE username LIKE '$username' AND status LIKE 'active' LIMIT 1");
$statement->execute();
$row2 = $statement->fetch();
if($row_count > 0){
echo '<div id="active-shipment">';
if($row1['type'] === "purchase"){
echo '
<h1 id="countdown"></h1>
<p>Incoming shipment of ' . $row2['quantity'] . ' crates of ' . $row2['name'] . '</p>
';
}
else if($row1['type'] === "sale"){
echo '
<h1 id="countdown"></h1>
<p>Outgoing shipment of ' . $row1['quantity'] . ' crates with a value of $' . number_format($row1['value']) . '</p>
';
}
echo '
</div>
<script type="text/javascript">
$("#countdown").countdown("' . $row1['arrival'] . '", function(event) {
var arrival = {
days: event.strftime("%D"),
hours: event.strftime("%H"),
minutes: event.strftime("%M"),
seconds: event.strftime("%Ss")
};
if(arrival.days <= 0){
arrival.days = "";
}
else{
arrival.days += "d";
}
if(arrival.hours <= 0){
arrival.hours = "";
}
else{
arrival.hours += "h";
}
if(arrival.minutes <= 0){
arrival.minutes = "";
}
else{
arrival.minutes += "m";
}
$(this).text(arrival.days + " " + arrival.hours + " " + arrival.minutes + " " + arrival.seconds);
if(new Date("' . $row1['arrival'] . '") <= new Date()){
window.location.replace("index.php");
}
});
$("title").countdown("' . $row1['arrival'] . '", function(event){
var arrival = {
days: event.strftime("%D"),
hours: event.strftime("%H"),
minutes: event.strftime("%M"),
seconds: event.strftime("%Ss")
};
if(arrival.days <= 0){
arrival.days = "";
}
else{
arrival.days += "d";
}
if(arrival.hours <= 0){
arrival.hours = "";
}
else{
arrival.hours += "h";
}
if(arrival.minutes <= 0){
arrival.minutes = "";
}
else{
arrival.minutes += "m";
}
$(this).text(arrival.days + " " + arrival.hours + " " + arrival.minutes + " " + arrival.seconds + " - CEO Panel");
});
</script>
';
}
?>
<div class="dialog" id="upgrades-dialog">
<div class="close-button">x</div>
<h1>UPGRADES</h1>
<p>TRANSPORT TRUCKS</p>
<p style="font-size: 16px;">These trucks are used for <strong>purchases</strong>.</p>
<?php
$upgrade_cost = calculate_upgrade_cost("trucks", "speed");
$pdo = pdo();
$statement = $pdo->prepare("SELECT cash FROM users WHERE username LIKE ?");
$statement->bindParam(1, $_SESSION['username']);
$statement->execute();
$user = $statement->fetch();
$statement = $pdo->prepare("SELECT * FROM transport_upgrades WHERE vehicle LIKE 'trucks' AND username LIKE ? AND type LIKE 'speed'");
$statement->bindParam(1, $username);
$statement->execute();
$previous_upgrades = $statement->rowCount();
$crate_delivery_time = explode('.', 1 * (3 * (1 - ($previous_upgrades * 0.03))));
if(strpos((string)$crate_delivery_time[0], "-") !== false){
$crate_delivery_time[0] = 0;
$crate_delivery_time[1] = 0;
}
if(($crate_delivery_time[0] <= 0 && $crate_delivery_time[1] <= 0) || $crate_delivery_time[0] < 0){
echo '
<div class="upgrade">
<p>SPEED</p><div class="upgrade-button-disabled">UPGRADE</div>
<div class="upgrade-cost">Limit for upgrades reached.</div>
</div>
';
}
else if($user['cash'] < $upgrade_cost){
echo '
<div class="upgrade">
<p>SPEED</p><div class="upgrade-button-disabled">UPGRADE</div>
<div class="upgrade-cost">COST <span class="right-text red-text">$' . number_format($upgrade_cost) . '</span></div>
</div>
';
}
else if($user['cash'] >= $upgrade_cost){
echo '
<div class="upgrade">
<p>SPEED</p><div class="upgrade-button">UPGRADE</div>
<div class="upgrade-cost">COST <span class="right-text">$' . number_format($upgrade_cost) . '</span></div>
</div>
';
}
$upgrade_cost = calculate_upgrade_cost("trucks", "storage");
$statement = $pdo->prepare("SELECT cash FROM users WHERE username LIKE ?");
$statement->bindParam(1, $_SESSION['username']);
$statement->execute();
$user = $statement->fetch();
if($user['cash'] >= $upgrade_cost){
echo '
<div class="upgrade">
<p>STORAGE</p><div class="upgrade-button">UPGRADE</div>
<div class="upgrade-cost">COST <span class="right-text">$' . number_format($upgrade_cost) . '</span></div>
</div>
';
}
else{
echo '
<div class="upgrade">
<p>STORAGE</p><div class="upgrade-button-disabled">UPGRADE</div>
<div class="upgrade-cost">COST <span class="right-text red-text">$' . number_format($upgrade_cost) . '</span></div>
</div>
';
}
?>
<!--
<div class="upgrade">
<p>STORAGE</p><div class="upgrade-button">UPGRADE</div>
</div>
-->
<br>
<p>TRANSPORT PLANES</p>
<p style="font-size: 16px;">These planes are used for <strong>sales</strong>.</p>
<?php
$upgrade_cost = calculate_upgrade_cost("planes", "speed");
$pdo = pdo();
$statement = $pdo->prepare("SELECT cash FROM users WHERE username LIKE ?");
$statement->bindParam(1, $_SESSION['username']);
$statement->execute();
$user = $statement->fetch();
$statement = $pdo->prepare("SELECT * FROM transport_upgrades WHERE vehicle LIKE 'planes' AND username LIKE ? AND type LIKE 'speed'");
$statement->bindParam(1, $username);
$statement->execute();
$previous_upgrades = $statement->rowCount();
$crate_delivery_time = explode('.', 1 * (3 * (1 - ($previous_upgrades * 0.03))));
if(strpos((string)$crate_delivery_time[0], "-") !== false){
$crate_delivery_time[0] = 0;
$crate_delivery_time[1] = 0;
}
if(($crate_delivery_time[0] <= 0 && $crate_delivery_time[1] <= 0) || $crate_delivery_time[0] < 0){
echo '
<div class="upgrade">
<p>SPEED</p><div class="upgrade-button-disabled">UPGRADE</div>
<div class="upgrade-cost">Limit for upgrades reached.</div>
</div>
';
}
else if($user['cash'] < $upgrade_cost){
echo '
<div class="upgrade">
<p>SPEED</p><div class="upgrade-button-disabled">UPGRADE</div>
<div class="upgrade-cost">COST <span class="right-text red-text">$' . number_format($upgrade_cost) . '</span></div>
</div>
';
}
else if($user['cash'] >= $upgrade_cost){
echo '
<div class="upgrade">
<p>SPEED</p><div class="upgrade-button">UPGRADE</div>
<div class="upgrade-cost">COST <span class="right-text">$' . number_format($upgrade_cost) . '</span></div>
</div>
';
}
?>
</div>
<div id="warehouse-space">
<div id="used-space"></div>
<p>Used warehouse space:
<?php
$pdo = pdo();
$username = $_SESSION['username'];
$statement = $pdo->prepare("SELECT SUM(slots) FROM warehouses INNER JOIN warehouse_contracts ON warehouses.id=warehouse_contracts.warehouse_id WHERE username LIKE '$username'");
$statement->execute();
$row = $statement->fetch();
$slots = $row['SUM(slots)'];
$statement = $pdo->prepare("SELECT SUM(quantity) FROM storage WHERE username LIKE '$username'");
$statement->execute();
$row = $statement->fetch();
$crates = $row['SUM(quantity)'];
if($crates === 0 || !isset($crates)){
$crates = 0;
}
$percentage_used = round(($crates/$slots)*100, 1);
echo $crates . '/' . $slots . ' (' . $percentage_used . '%)';
?>
</p>
<?php
echo '
<script>
$("#used-space").css("width", ' . $percentage_used . ' + "%");
</script>
';
?>
</div>
</div>
<div id="summary"></div>
<?php
if(isset($_SESSION['random_event']) && $_SESSION['random_event']['recent'] === true){
$robbers = array(
"Hell's Angels",
"The Lost",
"some asian streetpunks",
"a pair of irish virgins",
"the russian mob",
"some methheads",
"a korean crew"
);
if($_SESSION['random_event']['shipment_type'] === "purchase"){
echo '
<div class="alert-background"></div>
<div class="alert">
<img class="companion-speech" src="res/companion-speeches/random-event.png">
<h1>Oh no!</h1>
<p>Boss, I\'ve got some bad news. Your recent shipment of <strong>' . $_SESSION['random_event']['ordered_quantity'] . '</strong> crates was hijacked during transport by ' . $robbers[rand(0, count($robbers) - 1)] . '. They managed to get away with <strong>' . $_SESSION['random_event']['random_event_penalty'] . '</strong> crates. Though, your crew did kill <strong>' . rand(1, 20) . '</strong> of them before they took off with the product.</p>
<div class="ok-button">OK</div>
</div>
';
}
unset($_SESSION['random_event']);
}
?>
</main>
<div id="loading">
<p>Loading, please wait..</p>
</div>
</body>
</html>
In Bootstrap 3.x, you'll want to use class = "hidden-md hidden-lg" to hide content on desktops (screen resolutions >= 992 pixels).
<div id="HUD">
<div id="hamburger-menu-toggle" class="hidden-md hidden-lg">
<div></div>
<div></div>
<div></div>
</div>
<div id="hamburger-menu" class="hidden-md hidden-lg">
</div>
Bootstrap 4 is in alpha still, so I wouldn't recommend using it yet, aside from for testing purposes.
Also, make sure you put this in your head section:
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
this feature is a new feature in the new version of bootstrap v4 but you are using bootstrap 3, you can use .hidden-md and .hidden-lg instead.
Bootstrap Doc
You can skip using bootstrap CSS, and use jQuery like this:
$(document).ready(function () {
if ($(window).width() <= 997) {
$('p').hide();
}
$(window).resize(function () {
if ($(window).width() <= 997) {
$('#hamburger-menu-toggle').hide();
} else {
$('#hamburger-menu-toggle').show();
}
});
});

How Can I Fix Apend Designing Issues In Isotope?

I have append the ajax coding, data are coming fine, here during appending this style="position: absolute; left: 468px; top: 0px;" css is not adding to my new append data. How can I do this? Below is my ajax code. Please suggest me.
See image here
<?php
$per_page=20;
$latestImages = mysql_query("select * from ".GIFIMAGES." WHERE isActive = '1' AND not_update='1' order by modified ");
$total_record=mysql_num_rows($latestImages)/5;
$maxPage=number_format((float) $total_record, 2, '.', '');
?>
<script>
var lastX = 0;
var currentX = 0;
var page = 1;
function loadMore() {
if (page < '<?php echo $maxPage;?>') {
page++;
$('#load-more').html('Loading...');
$.post("ajax_append.php", {'ajax_append':'<?php echo $per_page;?>','page':page},function(data)
{
alert(data);
$('#homeload').append(data);
$('#load-more').html('VIEW MORE');
});
} else {
$('#load-more').hide();
}
}
</script>
Below is external(html) file append coding.(grid-splash-item)No css is calling for this same class, which I have been used in pageloading.plz check it.
<?php
$i=50;
$latestImages = mysql_query("select * from ".GIFIMAGES." WHERE isActive = '1' AND not_update='1' order by modified DESC limit $total_records,$page_records");
while($getLatestGif=mysql_fetch_array($latestImages)){
$i++;
$categoryName = mysql_fetch_array(mysql_query("select name from ".CATEGORY." where id='".$getLatestGif['cat_id']."'"));
$checkLatestUsers = mysql_num_rows(mysql_query("select * from ". YEAH." where user_id = '".$_SESSION['USER_ID']."' and gifimageid ='".$getLatestGif['id']."'"));
$yeahCount = mysql_num_rows(mysql_query("select gifimageid from ". YEAH ." where gifimageid = '".$getLatestGif['id']."'"));
$yeahCountLatest = mysql_query("update ".GIFIMAGES." set yeahCount ='$yeahCount' where id = '".$getLatestGif['id']."'");
$comment = mysql_query("select * from ".COMMENTS." where gifid='". $getLatestGif['id']."' order by id desc");
$getLatestUser=mysql_fetch_array(mysql_query("SELECT username,photo FROM ".TBL_USERS." WHERE id='".$getLatestGif['userId']."'"));
$commnetsCounts = mysql_num_rows($comment);
?>
<div class="grid-splash-item">
<!-- <img src="images/img-2.jpg" /> -->
<a href="<?php echo HTTP_ROOT.'funny-'.$categoryName['name'].'-images/'. makeSeoUrl($getLatestGif['title']).'/'.$getLatestGif['uniq_id'];?>" > <img width="198" height="169" src="<?php echo HTTP_ROOT.DIR_GIF.$getLatestGif['gifphoto'];?>" /> </a>
<div class="gif-details">
<div class="gif-details-menu">
<span>
<div class="gif-details-menu-box" <?php if(!empty($_SESSION['USER_ID']) && $checkLatestUsers){?> <?php } else {?> <?php } ?>>
//My coding present.I have removed it(too long).
</div>
</span>
<p><?php echo substr($getLatestGif['title'],0,20);?></p>
</div>
</div>
</div>
<?php } ?>
try adding the inline css in html only like,
change this
<div class="grid-splash-item">
to
<?php
$counter = 1;
while ($getLatestGif = mysql_fetch_array($latestImages)) {
$i++;
$categoryName = mysql_fetch_array(mysql_query("select name from " . CATEGORY . " where id='" . $getLatestGif['cat_id'] . "'"));
$checkLatestUsers = mysql_num_rows(mysql_query("select * from " . YEAH . " where user_id = '" . $_SESSION['USER_ID'] . "' and gifimageid ='" . $getLatestGif['id'] . "'"));
$yeahCount = mysql_num_rows(mysql_query("select gifimageid from " . YEAH . " where gifimageid = '" . $getLatestGif['id'] . "'"));
$yeahCountLatest = mysql_query("update " . GIFIMAGES . " set yeahCount ='$yeahCount' where id = '" . $getLatestGif['id'] . "'");
$comment = mysql_query("select * from " . COMMENTS . " where gifid='" . $getLatestGif['id'] . "' order by id desc");
$getLatestUser = mysql_fetch_array(mysql_query("SELECT username,photo FROM " . TBL_USERS . " WHERE id='" . $getLatestGif['userId'] . "'"));
$commnetsCounts = mysql_num_rows($comment);
if ($counter % 4 == 1) {
$style = 'style="position: absolute; left: 0px; top: 175px;"';
} else if ($counter % 4 == 2) {
$style = 'style="position: absolute; left: 234px; top: 175px;"';
} else if ($counter % 4 == 3) {
$style='style="position: absolute; left: 468px; top: 175px;"';
} else {
$style='style="position: absolute; left: 702px; top: 175px;"';
}
$counter++;
?>
<div class="grid-splash-item" <?= $style ?>>
<!-- <img src="images/img-2.jpg" /> -->
<a href="<?php echo HTTP_ROOT . 'funny-' . $categoryName['name'] . '-images/' . makeSeoUrl($getLatestGif['title']) . '/' . $getLatestGif['uniq_id']; ?>" > <img width="198" height="169" src="<?php echo HTTP_ROOT . DIR_GIF . $getLatestGif['gifphoto']; ?>" /> </a>
<div class="gif-details">
<div class="gif-details-menu">
<span>
<div class="gif-details-menu-box" <?php if (!empty($_SESSION['USER_ID']) && $checkLatestUsers) { ?> <?php } else { ?> <?php } ?>>
//My coding present.I have removed it(too long).
</div>
</span>
<p><?php echo substr($getLatestGif['title'], 0, 20); ?></p>
</div>
</div>
</div>
After researching a lot,i came to a accurate result.Here its only need to change two things.Here i have not written any inline css,after appending its coming fine,with proper css.
Below is my new code.Which is working perfectly.
This is my new script coding.I have modified a little
<?php $per_page=20; $latestImages = mysql_query("select * from ".GIFIMAGES." WHERE isActive = '1' AND not_update='1' order by modified "); $total_record=mysql_num_rows($latestImages)/5;$maxPage=number_format((float) $total_record, 2, '.', ''); ?>
<script>
$(function(){
var $container = $('#container');
var lastX = 0;
var currentX = 0;
var page = 1;
$('#append a').click(function(){
if (page < '<?php echo $maxPage;?>') {
page++;
$('.funny-gifts').html('Loading...');
$.post("ajax_append.php", {'ajax_append':'<?php echo $per_page;?>','page':page},function(data)
{
// $('#container').append(data);
var $newItems = $(data);
$('#container').isotope( 'insert', $newItems );
$('.funny-gifts').html('More Funny Gifs');
});
} else {
$('.funny-gifts').hide();
}
});
});
</script>
***var $newItems = $(data);
$('#container').isotope( 'insert', $newItems );***
This above two line coding is very important for appending.
Dont use $('#container').append(data); for appending.Result will come but,having a designing issues.Then after it replace the view more button slightly.Below is coding.
<div id="append">More Funny Gifs</div>

how to apply infinte scroll to this costom pagination page

I'm using this page to list all the users to a page. I'm listing it using custom pagination, now I have to display using infinite scroll using ajax or jquery . googled/stackoverflowed lots of solutions nothings seems to work with this custom pagination in the page
$paging_Obj = new Pagination();
$perPagerecord = 6;
$page = $this->getRequest()->getParam('page');
if($page){
$start = ($page - 1) * $perPagerecord;
}else{
$start = 0;
}
if($page == 0){
$page = 1;
}
$prev = $page - 1;
$next = $page + 1;
$limitCond = "LIMIT $start, $perPagerecord";
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
//echo $artistTotalQuery = "SELECT * FROM marketplace_userdata WHERE mageuserid IN (SELECT userid FROM marketplace_product GROUP BY userid) AND partnerstatus = 'Seller' AND wantpartner = '1' ORDER BY autoid ASC";die;
$artistTotalQuery = "SELECT mu.*,cev.value as first_name,cev1.value as last_name FROM marketplace_userdata as mu LEFT JOIN customer_entity_varchar AS cev ON (cev.entity_id = mu.mageuserid) AND (cev.attribute_id = '5') LEFT JOIN customer_entity_varchar AS cev1 ON (cev1.entity_id = mu.mageuserid) AND (cev1.attribute_id = '7') WHERE mu.mageuserid IN (SELECT userid FROM marketplace_product GROUP BY userid) AND mu.partnerstatus = 'Seller' AND mu.wantpartner = '1'
GROUP BY cev.entity_id ORDER BY cev1.value ASC";
$sellerlist_total = $readConnection->fetchAll($artistTotalQuery);
$count = count($sellerlist_total);
$artistQuery = "SELECT mu.*,cev.value as first_name,cev1.value as last_name FROM marketplace_userdata as mu LEFT JOIN customer_entity_varchar AS cev ON (cev.entity_id = mu.mageuserid) AND (cev.attribute_id = '5') LEFT JOIN customer_entity_varchar AS cev1 ON (cev1.entity_id = mu.mageuserid) AND (cev1.attribute_id = '7') WHERE mu.mageuserid IN (SELECT userid FROM marketplace_product GROUP BY userid) AND mu.partnerstatus = 'Seller' AND mu.wantpartner = '1' GROUP BY cev.entity_id ORDER BY cev1.value ASC $limitCond";
$sellerlist = $readConnection->fetchAll($artistQuery);
if($count>0){
?>
<?php
$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter();
$allcatid = array();
$k=0;
foreach ($categories as $c) {
$allcatid[$k] = $c->getId();
$k++;
}
$finalcat=array_shift($allcatid);
?>
<div class="div_Row">
<?php
$pagination = "";
$nextDisplayPagesLimit = 3;
$callPaging = $paging_Obj->Pagination($pagination,$count,$nextDisplayPagesLimit,$perPagerecord,$page,$next,$prev,$redirectUrl);
echo $callPaging;
?>
</div>
</div>
</div>
<div class="div_Row">
<?php
$m = 1;
foreach($sellerlist as $seller){
$customerid=$seller['mageuserid'];
$customer=Mage::getModel('customer/customer')->load($customerid);
/*********User Total Products and get last add product image Start************/
$query = "SELECT count(*) as total, max(mageproductid) as lastProduct_id FROM marketplace_product WHERE userid = $customerid";
$Product_result = $readConnection->fetchAll($query);
$totalProducts = $Product_result[0]['total'];
if(isset($totalProducts) && $totalProducts > 0){
$product_id = $Product_result[0]['lastProduct_id'];
$productDetails = Mage::getModel('catalog/product')->load($product_id);
$height = $this->helper('catalog/image')->init($productDetails, 'small_image')->getOriginalHeight();
$width = $this->helper('catalog/image')->init($productDetails, 'small_image')->getOriginalWidth();
$Product_image = $this->helper('catalog/image')->init($productDetails, 'small_image');
}else{
$Product_image = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).$APHolder;
//$profileURLArtist = Mage::getUrl()."marketplace/seller/profile/".$seller['profileurl']."/list";
$profileURLArtist = Mage::getUrl()."artist/".$seller['profileurl'];
?>
<div class="Artist_list_box span4">
<div class="Artist_main_img">
<a class="product-image-listing" href="<?php echo $profileURLArtist; ?>">
<img alt="<?php echo $customer_name; ?>" title="" src="<?php echo $Product_image;?>" style="width:<?php echo $widthRe."px";?>;max-width:<?php echo $widthRe."px";?>;margin-top:<?php echo $imageHeightDiff."px";?>; margin-left:<?php echo $imageWidthDiff."px";?>;">
</a>
</div>
<div class="List_inner_box">
<!-- <div class="List_them_bg">
</div>-->
<div class="List_inner_text">
<div class="list_Name_title">
<?php echo $customer_name; ?>
<?php if($city!='' && $country!=''){?>
<span> <?php echo $city.", ".$country;?></span>
<?php }?>
<div class="pieces"><p style="margin-bottom:0;"><?php echo $totalProducts?> Artworks</p></div>
</div>
<div class="List_them">
<a href="<?php echo $profileURLArtist; ?>">
<img style="height:50px;width:50px;" alt="<?php echo $customer_name; ?>" src="<?php echo $logo;?>">
</a>
</div>
<div class="list_text"><?php //echo $customer_desc;?></div>
</div>
</div>
</div>
<?php if($m % 4 == 0){?>
<div style="clear:both"></div>
<?php } $m++;?>
<?php
} ?>
</div>
<div class="div_Row">
<div class="pager">
<?php
$pagination = "";
$nextDisplayPagesLimit = 3;
$callPaging = $paging_Obj->Pagination($pagination,$count,$nextDisplayPagesLimit,$perPagerecord,$page,$next,$prev,$redirectUrl);
echo $callPaging;
?>
</div>
</div>
<?php
have you tried Paul Irishs jquery plugin?
https://github.com/paulirish/infinite-scroll
Should work

How can I get a value from a select box on the same page

I'm trying to use PHP and Javascript to make a category selector box.
I've set it up so that the Javascript will show the steps in order of being selected, and hide after being deselected.
However, I can't figure out how to take the selected options "id" or "value" and pass it to the next line. (once the chosen id or value is passed on, the next list can load)
Here is my code, Thanks in advance for looking. And please, if I'm doing something wrong or not the right way. Let me know and/or show me the right way to do it.
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/inc/header.php");
include($_SERVER["DOCUMENT_ROOT"] . "/inc/search.php");
?>
<div class="content">
<form>
<select name="categorys" class="newcatediv" id="step1" size="3" onchange="mine(this.value)">
<?php
$result_c = mysqli_query($con,"SELECT * FROM categories ORDER BY category_name ASC");
while($row = mysqli_fetch_array($result_c))
{
echo '<option class="mso" id="'. $row['category_nameid'] .'"value="';
echo $row['category_nameid'] .'">' . $row['category_name'] . '</option>';
}
?>
</select>
<select name="sections" class="newcatediv" id="step2" size="3" onchange="mine2(this.value)">
<?php
$var_c = ????
$result_s = mysqli_query($con,"SELECT * FROM sections WHERE category_nameid='$var_c' ORDER BY section_name ASC");
while($row = mysqli_fetch_array($result_s))
{
echo '<option class="mso" id="'. $row['section_nameid'] .'"value="';
echo $row['section_nameid'] .'">' . $row['section_name'] . '</option>';
}
?>
</select>
<select name="subsections" class="newcatediv" id="step3" size="3">
<?php
$var_s = ????
$result_ss = mysqli_query($con,"SELECT * FROM subsections WHERE section_nameid='$var_s' ORDER BY subsection_name ASC");
while($row = mysqli_fetch_array($result_ss))
{
echo '<option class="mso" id="'. $row['subsection_nameid'] .'"value="';
echo $row['subsection_nameid'] .'">' . $row['subsection_name'] . '</option>';
}
?>
</select>
</form>
</div>
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/inc/footer.php");
?>
By default, the first option in a <select> is selected, so this would work:
<select name="categorys" class="newcatediv" id="step1" size="3" onchange="mine(this.value)">
<?php
$result_c = mysqli_query($con,"SELECT * FROM categories ORDER BY category_name ASC");
$var_c = null;
while($row = mysqli_fetch_array($result_c))
{
if($var_c == null) $var_c = $row['category_nameid'];
echo '<option class="mso" id="'. $row['category_nameid'] .'"value="';
echo $row['category_nameid'] .'">' . $row['category_name'] . '</option>';
}
?>
</select>
<select name="sections" class="newcatediv" id="step2" size="3" onchange="mine2(this.value)">
<?php
$result_s = mysqli_query($con,"SELECT * FROM sections WHERE category_nameid='$var_c' ORDER BY section_name ASC");
$var_s = null;
while($row = mysqli_fetch_array($result_s))
{
if($var_s == null) $var_s = $row['section_nameid'];
echo '<option class="mso" id="'. $row['section_nameid'] .'"value="';
echo $row['section_nameid'] .'">' . $row['section_name'] . '</option>';
}
?>
</select>
<select name="subsections" class="newcatediv" id="step3" size="3">
<?php
$result_ss = mysqli_query($con,"SELECT * FROM subsections WHERE section_nameid='$var_s' ORDER BY subsection_name ASC");
while($row = mysqli_fetch_array($result_ss))
{
echo '<option class="mso" id="'. $row['subsection_nameid'] .'"value="';
echo $row['subsection_nameid'] .'">' . $row['subsection_name'] . '</option>';
}
?>
</select>
Cheers
Hi :) You Can't Process that at the same page using Php. But you can do that with this jquery including 3 pages.
First Page:
$(document).ready(function(){
$("#step1").change(function(){
var id=$("#step1").val();
alert(id); //shouts the value of the selected step1
$.post("select_step2.php", {id:id}, function(data){
$("#step2").empty();
$("#step2").append(data);
$("#step2").change(function(){
var id2=$("#step2").val();
alert(id2); //shouts the value of the selected step2
$.post("select_step3.php", {id:id2}, function(data){
$("#step3").empty();
$("#step3").append(data);
});
});
});
});
});
The above code is for jquery where you can call each data's that depends on each step.
<?php
include($_SERVER["DOCUMENT_ROOT"] . "/inc/header.php");
include($_SERVER["DOCUMENT_ROOT"] . "/inc/search.php");
?>
<form>
First Step: <select name="categorys" class="newcatediv" id="step1" size="3">
<?php
$result_c = mysqli_query($con,"SELECT * FROM categories ORDER BY category_name ASC");
while($row = mysqli_fetch_array($result_c))
{
echo '<option class="mso" id="'. $row['category_nameid'] .'"value="';
echo $row['category_nameid'] .'">' . $row['category_name'] . '</option>';
}
?>
</select>
Second Step: <select name="sections" class="newcatediv" id="step2" size="3"></select>
Third Step: <select name="subsections" class="newcatediv" id="step3" size="3"></select>
Code for you select_step2.php:
<?php
//Please include the connection to your database here :)
$var_c = trim($_POST['id']);
$section = "";
$result_s = mysqli_query($con,"SELECT * FROM sections WHERE category_nameid='$var_c' ORDER BY section_name ASC");
while($row = mysqli_fetch_array($result_s))
{
$section.="<option value='$row[section_nameid]'>$row[section_name]</option>";
}
echo $section;
?>
Code for your select_step3.php:
<?php
//database connection here
$var_s = trim($_POST['id']);
$subsection= "";
$result_ss = mysqli_query($con,"SELECT * FROM subsections WHERE section_nameid='$var_s' ORDER BY subsection_name ASC");
while($row = mysqli_fetch_array($result_ss))
{
$subsection.="<option value='$row[subsection_nameid]'>$row[subsection_name]</option>";
}
echo $subsection;
?>

Categories