I have created a calender using php, javascript and mySQL.
The calender itself worked but once I attempted to add and view events on a particular day it refuses to load and I'm not too sure why. This example is taken from Sam's teach yourself PHP, MySQL and Apache all in one.
The code is as follows:
<?php
//$display = "";
$host = "xx";
$user = "xx";
$pass = "xx";
$db = "xx";
$mysqli = mysqli_connect($host, $user, $pass, $db);
// Check connection
define("ADAY", (60*60*24));
if ((!isset($_POST['month'])) || (!isset($_POST['year']))) {
$nowArray = getdate();
$month = $nowArray['mon'];
$year = $nowArray['year'];
} else {
$month = $_POST['month'];
$year = $_POST['year'];
}
$start = mktime (12, 0, 0, $month, 1, $year);
$firstDayArray = getdate($start);
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo "Calender: ".$firstDayArray['month']."
".$firstDayArray['year'] ?></title>
</head>
<style type="text/css">
table {
border: 1px solid black;
border-collapse: collapse;
}
th {
border: 1px solid black;
padding: 6px;
font-weight: bold;
background: #ccc;
}
td {
border: 1px solid black;
padding: 6px;
vertical-align: top;
width 100px;
}
</style>
<script type="text/javascript">
function eventWindow(url) {
event_popupWin = window.open(url, 'event', 'resizable=yes, scrollbars=yes, toolbar=no, width=400, height=400');
event_popupWin.opener = self;
}
</script>
<body>
<h1>Select a Month/Year Combination</h1>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name ="month">
<?php
$months = Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
for ($x=1; $x <= count($months); $x++) {
echo"<option value=\." $x ".\"";
if ($x == $month) {
echo " selected";
}
echo ">".$months[$x-1]."</option>";
}
?>
</select>
<select name="year">
<?php
for ($x=1990; $x<=2020; $x++) {
echo "<option";
if ($x == $year) {
echo " selected";
}
echo ">." $x ."</option>";
}
?>
</select>
<button type="submit" name="submit" value="submit">Go!</button>
</form>
<br/>
<?php
$days = Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
echo "<table><tr>\n";
foreach ($days as $day) {
echo "<th>$day</th>\n";
}
for ($count=0; $count < (6*7); $count++) { //initialise a variable called count
$dayArray = getdate($start);
if (($count% 7) == 0) {
if ($dayArray['mon'] != $month) {
break;
} else {
echo "</tr><tr>\n";
}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] !=$month) {
echo "<td> </td>\n";
} else {
echo "<td>".$dayArray['mday']."</td>\n";
$start += ADAY;
}
}
if ($count < $firstDayArray['wday'] || $dayArray['mon'] !=$month) {
echo "<td> </td>\n";
} else {
$mysqli = mysqli_connect($host, $user, $pass, $db);
$chkEvent_sql = "SELECT event_title FROM calender_events WHERE
month(event_start) = '".$month."' AND
dayofmonth(event_start) = '".$dayArray['mday']."' AND
year(event_start) = '".$year."'
ORDER BY event_start";
$chkEvent_res = mysqli_query($mysqli, $chkEvent_sql);
or die(mysqli_error($mysqli));
if (mysqli_num_rows($chkEvent_res) > 0) {
while ($ev = mysqli_fetch_array($chkEvent_res)) {
$event_title .= stripslashes($ev['event_title']);
}
} else {
event_title = "";
}
echo "<td><a href=\"javascript:eventWindow('event.php?m= ".$month."&d=".$dayArray['mday']."&y=".$year."');/>".$dayArray['mday']."</a><br/> <br/>".$event_title."</td>\n";
unset($event_title);
$start += ADAY;
}
echo "</tr><table>";
?>
<body>
</html>
However, I believe the problem is with this section code:
$chkEvent_res = mysqli_query($mysqli, $chkEvent_sql);
or die(mysqli_error($mysqli));
if (mysqli_num_rows($chkEvent_res) > 0) {
while ($ev = mysqli_fetch_array($chkEvent_res)) {
$event_title .= stripslashes($ev['event_title']);
}
} else {
event_title = "";
}
echo "<td><a href=\"javascript:eventWindow('event.php?m= ".$month."&d=".$dayArray['mday']."&y=".$year."');/>".$dayArray['mday']."</a><br/> <br/>".$event_title."</td>\n";
Can anyone help? Thanks
Related
I've tried different codes, but the codes always not working. I want to reload just the specific section every 5 seconds, not reloading the whole page. It's important not to refresh the whole page, because it includes an chat function. If I would reload the whole page, people can't enter text without loosing it every 5 seccond. Like I said, I've tried some codes from stackOverflow but somehow they don't work for me.
Here's my code
<script type="text/javascript">
$(document).ready(function(){
setInterval(function(){
$("#context").load(window.location.href + " #context" );
}, 5000);
});
</script>
<--variables explained --->
$fid = $_GET['fid']
$username = $_SESSION['username']
$db :
$servername = "localhost";
$dbname = "psychopath";
$username = "root";
$password = "";
try{
$dsn = "mysql:host=" . $servername . ";dbname=" . $dbname;
$db = new PDO($dsn, $username, $password);
echo "";
}catch(PDOException $e){
echo $e.getMessage();
}
<--- variables END ----->
$display_messages = $db->prepare("SELECT * FROM mychat_from WHERE (user_to_name = ? OR userfrom_name = ?) AND (user_to_id = ? OR userfrom_id = ?)");
$display_messages->execute([$username , $username, $fid, $fid]);
while($row=$display_messages->fetch(PDO::FETCH_ASSOC)){
$userfrom = $row['userfrom'];
if($userfrom != $username){
$messagefrom2 = $row['message_from'];
$messagefrombreak2 = wordwrap($messagefrom2, 27, "\n", true);
?>
<?php
?><section id="context" name="context"><?php echo '<b> '.$userfrom.'</b>said:<br>';
echo "<section style='background: black; float: left; margin-left: 5px; border-radius: 7px; color: white;'> <font style='float: left;'> ".$messagefrombreak2."</font></section>";?>
</section>
<?php echo "<br><br>";
?>
And here is full code:
<!-- end snippet -->if(isset($_GET['fid'])){
$fid = $_GET['fid'];
?>
<section>
<section>
<?php
$get_friend = $db->prepare("do stuff");
$get_friend->execute([$fid]);
while($row=$get_friend->fetch(PDO::ROW STUFF)){
}
?>
</section>
<section>
<?php
$username = $_SESSION['username'];
$get_id = $db->prepare("do stuff");
$get_id->execute([$fid]);
while($row=$get_id->fetch(ROW STUFF)){
$get_your_id = $db->prepare("do stugg");
$get_your_id->execute([$username]);
while($row=$get_your_id->fetch(ROW STUFF)){
$display_messages = $db->prepare("DO STUFF");
$display_messages->execute([$your_id, $your_id, $fid, $fid]);
while($row=$display_messages->fetch(DO STUFF)){
$userfrom = $row['userfrom'];
if($userfrom != $username){
$messagefrom2 = $row['message_from'];
$messagefrombreak2 = wordwrap($messagefrom2, 27, "\n", true);
?>
<?php
?><div id="container" name="container"><div id="context" name="context"><?php echo '<b> '.$userfrom.'</b>said:<br>';
echo "<section style='background: black; float: left; margin-left: 5px; border-radius: 7px; color: white;'> <font style='float: left;'> ".$messagefrombreak2."</font></section>";?>
</div></div>
<?php echo "<br><br>";
?>
<script type="text/javascript">
$(document).ready(function(){
setInterval(function(){
$("#context").load(window.location.href + " #container" );
}, 5000);
});
</script>
<?php
}else{
$messagefrom = $row['message_from'];
$messagefrombreak = wordwrap($messagefrom, 27, "\n ", true);
echo "<font style='float: right;'><b>You </b>said: </font><br>";
echo "<section style='background: #960505; float: right; margin-right: 5px; border-radius: 7px; color:
white;'><font style='float: right;'> ".$messagefrombreak." </font></section><br><br>";
}}}}
?>
</section>
use ajax and json
ajax to make a call to server within the page
json little simple format
use setInterval
like
var myVar = setInterval(my_func, 5000);
my_func is a function that will hold ajax action. and do what do you need
PHP Code:
<?php
include 'security.php';
$mysqli = new mysqli('localhost', 'root', '', 'halcondentalclinic');
if (isset($_GET['date'])) {
$date = $_GET['date'];
$stmt = $mysqli->prepare("select * from bookings where dates = ?");
$stmt->bind_param('s', $date);
$bookings = array();
if ($stmt->execute()) {
$result = $stmt->get_result();
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$bookings[] = $row['timeslot'];
}
$stmt->close();
}
}
}
$duration = 30;
$cleanup = 00;
$start = "9:00";
$end = "16:00";
function timeslots($duration, $cleanup, $start, $end)
{
$start = new DateTime($start);
$end = new DateTime($end);
$interval = new DateInterval("PT" . $duration . "M");
$cleanupinterval = new DateInterval("PT" . $cleanup . "M");
$slots = array();
for ($intStart = $start; $intStart < $end; $intStart->add($interval)->add($cleanupinterval)) {
$endPeriod = clone $intStart;
$endPeriod->add($interval);
if ($endPeriod > $end) {
break;
}
$slots[] = $intStart->format("H:iA") . "-" . $endPeriod->format("H:iA");
}
return $slots;
}
?>
html and php
<div class="container">
<h1 class="text-center">Book for Date: <?php echo date('m/d/Y', strtotime($date)); ?></h1>
<hr>
<div class="row">
<div class="col-md-12">
<?php echo isset($msg) ? $msg : ""; ?>
</div>
<?php $timeslots = timeslots($duration, $cleanup, $start, $end);
foreach ($timeslots as $ts) {
?>
<div class="col-md-2">
<div class="form-group">
<?php if (in_array($ts, $bookings)) { ?>
<button class="btn btn-danger"><?php echo $ts; ?></button>
<?php } else { ?>
<button class="btn btn-success book"
data-timeslot="<?php echo $ts; ?>"><?php echo $ts; ?></button>
<?php } ?>
</div>
</div>
<?php
} ?>
</div>
</div>
This is the appointment system I want if the date is already past the button for the calendar time change to red and become disabled. For example, 9:00 am - 9:30 am so if the date is already 12:00 pm the 9:00 am - 9:30 become disabled
It is possible to do it? Sorry I am a beginner in PHP and MySQL.
I am not Php developer but as I see you can define a php function to check time is past
function isPastTime($time){
// check $time is past
}
And when you render view, you can add class to remark past booking
<?php if(isPastTime){ ?>
<button class="btn btn-past"><?php echo $ts;?></button>
.btn-past {
color: red;
pointer-events: none;
}
It is my advise. Hope you can resolve it.
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>
I want to try get a traffic light colour scheme with my time text where if the time is between 0.0000 and 10.0000 the text if green if between 10.0100 and 15.0000 the text is orange and between 15.0100 and 20.0000 then its red i cant get my function to run i may be missing something but im not sure what.
currently the mysql query returns result as 14.6263 with this value constantly changing
my current code is :
<!doctype html>
<html>
<head>
<title>time stats</title>
<style>
body {
background-color: black;
}
.box1 {
width: 300px;
height: 400px;
border: 15px solid yellow;
padding: 15px;
margin: 15px;
display: inline-block;
color: white;
font-size:40px;
color: lime;
.container {
text-align: center;
}
</style>
<body>
<div class="box1">
<?php
$q = intval($_GET['q']);
$con = mysqli_connect('localhost','username','password','test');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"ajax_demo");
$sql="select avg(time_format(delivery_avg,'%i:%s')) as time_avg from test.del where location = 'yellow'";
$result = mysqli_query($con,$sql);
echo "<table>
<thead>
<th>time Average</th>
</thead>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['time_avg'] . "</td>";
echo "</tr>";}
echo "</table>";
mysqli_close($con);
?>
</div>
function updatecolor() {
//console.log('function called');
{
if ($box1.td < 10)
return '#00FF00';
else if ($box1.td >= 11 && $box1.td<= 15)
return = '#FFA500';
else if ($box1.td >= 16 && $box1.td<= 20)
return = '#ff0000';
}
});
}
var updateInterval = setInterval(updatecolor, 1000);
</body>
</html>
Here's a little function that will return your colors depending on the $valueToCheck parameter of the function:
<?php
function addColor($valueToCheck) {
{
if ($valueToCheck <= 10) {
return '#00FF00';
} else if ($valueToCheck >= 11 && $valueToCheck <= 15) {
return '#FFA500';
} else if ($valueToCheck >= 16 && $valueToCheck <= 20) {
return '#ff0000';
}
};
}
?>
Wrapped it in <?php ?> tags, since it's a PHP function.
Use it in your HTML like so:
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td style=\"color:" . addColor($row['time_avg']) . "\">";
echo $row['time_avg'];
echo "</td>";
echo "</tr>";
}
As for your code:
return = '#FFA500'; is not valid, remove the =.
If $box1 were available:
if ($box1.td < 10)
return '#00FF00';
else if ($box1.td >= 11 && $box1.td<= 15)
What about 10? You never check for 10>x>11.
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>