I have this table venue which consists of:
idVenue
name
description
room_size
What i'm trying to do is
ie. Venue A can have 5 person.
In DB, i have a room_size field which is 5.
So everytime a person is being selected to Venue A, just deduct 1 from the total (which is 5 for now). Once it reaches 0, then don't show out the Venue.
I heard flagging is possible, how do i actually go upon doing that?
Here's the code:
do_select.php
<?php
session_start();
if(($_SESSION['role'])!='Admin'){
echo "You have not logged in as admin yet.<br/>";
echo "Please <a href='login.php'>login</a>.";
exit;
}
?>
<?php
//member id
$id = $_POST['id'];
$idimplode = implode (", ", $id);
$idexplode= explode(", ", $idimplode);
//accept, reject
$select=$_POST['select'];
$comma = implode (", ", $select);
$comma1 = explode(", ", $comma);
$check =($idexplode);
//class id
$idc = $_POST['idc'];
include('dbconfig.php');
for($i=0;$i< sizeof($comma1);$i++)
{
if($comma1[$i]=="accept")
{
//Select Query if status is accept
$query="UPDATE attendance SET status='accept' WHERE Member_idMember ='$check[$i]' and Class_idClass='$idc'" ;
$result = mysqli_query($link, $query) or die(mysqli_error($link));
}
else
{
//Select Query if status is reject
$query2="UPDATE attendance SET status='reject' WHERE Member_idMember ='$check[$i]' and Class_idClass='$idc'" ;
$result1 = mysqli_query($link, $query2) or die(mysqli_error($link));
}
}
//select members based on status
$query3 = "SELECT * FROM member m, attendance a, class c
WHERE a.Member_idMember = m.idMember
AND a.Class_idClass = c.idClass
AND a.status = 'accept'
AND a.Class_idClass = '$idc'
";
$result3 = mysqli_query($link, $query3) or die (mysqli_connect_error($link));
//select query to get the class dates
$query4 = "SELECT day01, day02, day03, day04, day05, day06, day07, day08, day09, day10, day11, day12 FROM class
WHERE idClass = '$idc'";
$result4 = mysqli_query($link, $query4) or die (mysqli_connect_error($link));
//select query to get venue id
$query6 = "SELECT DISTINCT idVenue FROM venue";
$result6 = mysqli_query($link, $query6) or die (mysqli_connect_error($link));
while($row = mysqli_fetch_array($result4, MYSQL_NUM))
{
$day[] = implode(", ", $row);
}
$iday = implode(", ", $day);
$eday = explode(", ", $iday);
while($row = mysqli_fetch_array($result6, MYSQL_NUM))
{
$ven[] = implode(",", $row);
}
$iven = implode(", ", $ven);
$even = explode(", ", $iven);
$date = ($eday);
$venue= ($even);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ST JOHN</title>
<link rel="stylesheet" type="text/css" href="main.css" />
<script language="JavaScript" type="text/javascript">
</script>
</head>
<body>
<!-- Begin Wrapper -->
<div id="wrapper">
<!-- Begin Header -->
<div id="header">
<img src="Image/1.jpg" width="900" height="100" />
</div>
<!-- End Header -->
<!-- Begin Navigation -->
<div id="navigation">
<img src="Image/4.png" width="30" height="30" > Welcome!!! <br>;
Logout;
</div>
<!-- End Navigation -->
<!-- Begin Faux Columns -->
<div id="faux">
<!-- Begin Left Column -->
<div id="leftcolumn">
<center><img src="Image/2.jpg" width="150" height="100" /><br>
<ul>
<li>About Us</li>
<li>Public Courses</li>
<li>Cadet Affairs</li>
<li>Events</li>
<li>Contact Us</li>
</ul></center>
</div>
<!-- End Left Column -->
<!-- Begin Right Column -->
<div id="rightcolumn">
<h1>Assign Venue</h1><br/>
<?php
echo"<table border='1'>";
echo"<th>Name</th>";
echo"<th>Signup Datetime</th>";
echo"<th>Status</th>";
echo"<th>Class</th>";
echo"<th>Venue</th>";
while($row=mysqli_fetch_assoc($result3))
{
$idc=$row['idClass'];
$id=$row['idMember'];
$Name = $row['name'];
$Status = $row['status'];
$Signup_datetime = $row['signup_datetime'];
$class=$row['Class_idClass'];
$idt=$row['Time_Slot_idTime_Slot'];
echo "<form method='post' action='assign_venue.php'>";
echo "<tr>";
echo "<td>".$Name."</td>";
echo "<td>".$Signup_datetime."</td>";
echo "<td>".$Status."</td>";
echo "<td>".$class."</td>";
echo "<input name='idc' type='hidden' value= '$idc'/>";
echo "<input name='id[]' type='hidden' value= '$id'/>";
echo "<td><select id ='idv[]' name='idv[]'>";
for ($v=0; $v <count($venue); $v++)
{
for ($d=0; $d <count($date); $d++)
{
//select query to determine which are the dates that are in conflict with each other
$sql = "SELECT * FROM venue v, class c, attendance a
WHERE a.Venue_idVenue = v.idVenue
AND a.Class_idClass = c.idClass
AND v.idVenue = '$venue[$v]'
AND (day01='$date[$d]' OR day02='$date[$d]' OR day03='$date[$d]' OR day04='$date[$d]' OR day05='$date[$d]' OR day06='$date[$d]'
OR day07='$date[$d]' OR day08='$date[$d]' OR day09='$date[$d]' OR day10='$date[$d]' OR day11='$date[$d]' OR day12='$date[$d]')
AND c.Time_Slot_idTime_Slot = '$idt'";
$rs = mysqli_query($link, $sql) or die (mysqli_connect_error($link));
while ($row = mysqli_fetch_assoc($rs))
{
//if there are no conflict, then display the venue
if (mysqli_num_rows($rs) != 0)
{
$ve[]= $row['idVenue'];
break;
}
}
}
}
$if = implode(",", $ve);
$ef = explode(",", $if);
$ve = ($ef);
for ($f=0; $f <count($ve); $f++)
{
//select query to get venue id and name
$sql1 = "SELECT * FROM venue WHERE idVenue != '$ve[$f]'";
$rs1 = mysqli_query($link, $sql1) or die (mysqli_connect_error($link));
}
while($row = mysqli_fetch_assoc($rs1))
{
//display venue id and venue name
$idv=$row['idVenue'];
$name=$row['name'];
echo"<option name='idv[]' value='$idv'>$name</option> ";
}
echo "</select>";
}
echo "</table>";
echo "<td><input type='submit' value= 'Submit'>
</form>";
mysqli_close($link);
?>
<div class="clear"></div>
</div>
<!-- End Right Column -->
<div class="clear"></div>
</div>
<!-- End Faux Columns -->
<!-- Begin Footer -->
<div id="footer">
<center><p>Copyright© St. John Ambulance Singapore # 420, Beach Road, Singapore 199582 Tel: 6298 0300 Fax: 6296 5797click here for map</p></center>
</div>
<!-- End Footer -->
</div>
<!-- End Wrapper -->
</body>
</html>
you should have another field called current_occupancy
When you create the row
update venue set current_occupancy = room_size where id = <idOfVenue>
Then when someone selects:
update venue set current_occupancy = current_occupancy - 1 where id = <idOfVenue>
And only show fields that match
select * from venue where current_occupancey > 0 <whatever else>
Related
So I have an another problem with my filtering system. I am getting my filtered results when I choose an option from the first dropdown I have. But I also get below the filtered results a block where I see my options from the second dropdown (duplicated) and below that I have again ALL of my results I have in the database. How can I prevent this?
Here is my index.php
<!doctype html>
<html lang="de">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Stylesheets -->
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.3/css/bootstrap.min.css"
integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2"
crossorigin="anonymous">
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<script>
$(document).ready(function(){
// Live anzeigen der 2. Ebene + 1 Ebene Ergebnisse
$('#category').on('change', function(){
var categoryID = $(this).val();
if(categoryID){
$.ajax({
type:'POST',
url:'ajaxdata.php',
data:'category_id='+categoryID,
success:function(html){
$('#subcategory').html(html);
$('#partner').html(html);
$('#subcategory').prop('disabled', false);
}
});
} else {
$('#subcategory').html('<option value="">Zuerst Überkategorie auswählen!</option>');
}
});
// Live Anzeigen der 3. Ebene + 2. Ebene Ergebnisse
$('#subcategory').on('change', function(){
var subcategoryID = $(this).val();
if(subcategoryID){
$.ajax({
type:'POST',
url:'ajaxdata.php',
data:'subcategory_id='+subcategoryID,
success:function(html){
$('#subcategory2').html(html);
$('#partner').html(html);
$('#subcategory2').prop('disabled', false);
}
});
} else {
$('#subcategory2').html('<option value="">Zuerst Unterkategorie auswählen!
</option>');
}
});
// Live anzeigen der 3. Ebene Ergebnisse
$('#subcategory2').on('change', function(){
var subcategory2ID = $(this).val();
if(subcategory2ID){
$.ajax({
type:'POST',
url:'ajaxdata.php',
data:'subcategory2_id='+subcategory2ID,
success:function(html){
$('#partner').html(html);
}
});
} else {
$('#partner').html('<h1>Zuerst Unterkategorie auswählen!</h1>');
}
});
});
</script>
</head>
<body>
<?php
// Include connection.php
include_once 'dbconfig.php';
// Fetch all the category data
$query = "SELECT * FROM categories WHERE status = 1 ORDER BY category_name ASC";
$result = $connect->query($query);
?>
<!-- Category dropdown -->
<div class="container">
<div class="row">
<form action="" method="post">
<div class="col">
<select id="category" name="category" class="dropdown">
<?php
if($result->num_rows > 0){
while($row = $result->FETCH_ASSOC()){
echo '<option value="'.$row['category_id'].'">'.$row['category_name'].'</option>';
}
} else {
echo '<option value="">Nicht verfügbar!</option>';
}
?>
</select>
</div>
<div class="col">
<!-- Subcategory dropdown -->
<select id="subcategory" name="subcategory" class="dropdown" disabled>
<option value="">Kategorie auswählen!</option>
</select>
</div>
<div class="col">
<!-- 2nd subcategory dropdown -->
<select id="subcategory2" name="subcategory2" class="dropdown" disabled>
<option value="">Kategorie auswählen!</option>
</select>
</div>
</form>
</div>
</div>
<!-- Show all results -->
<div id="all_results">
<? /*
$query = "SELECT * FROM partner WHERE status = 1 ORDER BY partner_name ASC";
$result = $connect->query($query);
if ($result->num_rows > 0){
} */
?>
</div>
<!-- Partner results -->
<div id="partner">
<?php
if($result->num_rows > 0){
while($row = $result->FETCH_ASSOC()){
?>
<div>
<h1><? echo $row['partner_name'] ?></h1><br>
<img src="<? echo $row['partner_logo'] ?>"><br>
Zum Unternehmen!
</div>
<?php
}
} else {
echo '<p>Nichts gefunden!<p>';
}
?>
</div>
<!-- jQuery library -->
<script src="js/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
And this is my ajaxdata.php:
<?php
include_once 'dbconfig.php';
//Dropdown No. 1
if(!empty($_POST['category_id']))
{
// Anzeigen von Ergebnisse - 1. Ebene
$query = "SELECT * FROM partner WHERE category_id = ".$_POST['category_id']." AND status = 1
ORDER BY partner_name ASC";
$result = $connect->query($query);
if($result->num_rows > 0)
{
while($row = $result->FETCH_ASSOC())
{
?>
<div class="div_results">
<h1><? echo $row['partner_name'] ?></h1><br>
<img src="<? echo $row['partner_logo'] ?>"><br>
Zum Unternehmen!
</div>
<?php
}
}
// Anzeigen der Kategorien der 2. Ebene
$query = "SELECT * FROM subcategories WHERE category_id = ".$_POST['category_id']." AND status = 1 ORDER BY subcategory_name ASC";
$result = $connect->query($query);
if($result->num_rows > 0)
{
echo '<option value="">Kategorie auswählen!</option>';
while($row = $result->FETCH_ASSOC())
{
echo '<option value="'.$row['subcategory_id'].'">'.$row['subcategory_name'].'</option>';
}
}
// Anzeigen aller Ergebnisse
$query = "SELECT DISTINCT * FROM partner WHERE status = 1 ORDER BY partner_name ASC";
$result = $connect->query($query);
if($_POST["category_id"] != "Alle")
{
while($row = $result->FETCH_ASSOC())
{
?>
<div class="div_results">
<h1><? echo $row['partner_name'] ?></h1><br>
<img src="<? echo $row['partner_logo'] ?>"><br>
Zum Unternehmen!
</div>
<?php
}
}
else {
echo '<option value="">Nothing found!</option>';
}
}
// Dropdown No. 2
elseif(!empty($_POST['subcategory_id']))
{
// Anzeigen von Ergebnisse - 2. Ebene
$query = "SELECT * FROM partner WHERE subcategory_id = ".$_POST['subcategory_id']." AND
status = 1 ORDER BY partner_name ASC";
$result = $connect->query($query);
if($result->num_rows > 0)
{
while($row = $result->FETCH_ASSOC())
{
?>
<div>
<h1><? echo $row['partner_name'] ?></h1><br>
<img src="<? echo $row['partner_logo'] ?>"><br>
Zum Unternehmen!
</div>
<?php
}
}
// Anzeigen der Kategorien der 3. Ebene
$query = "SELECT * FROM subcategories2 WHERE subcategory_id = ".$_POST['subcategory_id']."
AND status = 1 ORDER BY subcategory2_name ASC";
$result = $connect->query($query);
if($result->num_rows > 0)
{
echo '<option value="">Untekategorie auswählen!</option>';
while($row = $result->FETCH_ASSOC())
{
echo '<option
value="'.$row['subcategory2_id'].'">'.$row['subcategory2_name'].'</option>';
}
}
else {
echo '<option value="">Nichts gefunden!</option>';
}
}
// Dropdown No. 3
elseif(!empty($_POST['subcategory2_id'])){
// Anzeigen von Ergebnisse - 3. Ebene (Letzte Ebene)
$query = "SELECT * FROM partner WHERE subcategory2_id = ".$_POST['subcategory2_id']." AND status = 1 ORDER BY partner_name ASC";
$result = $connect->query($query);
if($result->num_rows > 0){
while($row = $result->FETCH_ASSOC()){
?>
<div>
<h1><? echo $row['partner_name'] ?></h1><br>
<img src="<? echo $row['partner_logo'] ?>"><br>
Zum Unternehmen!
</div>
<?php
}
} else {
echo 'Nothing found!';
}
}
?>
What am I doing wrong so this shows everything when I am filtering
For the first problem (returning an unfiltered set of results as well as the filtered set), it's simply that you are running two versions of the SELECT * FROM partner... query, and outputting the results from both. The first version is filtered, but the second version isn't. You just need to remove the second version - it's not clear why that's there to begin with.
For the second problem (outputting the dropdown options after the results), the issue is that you're just outputting one big stream of HTML. Then you've written $('#subcategory').html(html); $('#partner').html(html); which attempts to put the same single stream of HTML into both parts of your page! The first command likely doesn't entirely work correctly because you're trying to put divs inside a select. And the second one prints everything that was output by the PHP - it has no way of telling which bit you wanted to print there, and which bit was intended for the dropdown. You gave it no way to differentiate.
It would make more sense to return a JSON object from the PHP, with two properties - one property containing the HTML for the search result, and one containing the HTML for the dropdown. Then the Javascript can easily read the correct bit into each part of your page separately.
Something like this should work I think (although obviously it's not easy for me to test it):
JavaScript:
$('#category').on('change', function(){
var categoryID = $(this).val();
if(categoryID){
$.ajax({
type:'POST',
url:'ajaxdata.php',
data:'category_id='+categoryID,
dataType: "json",
success:function(response){
$('#subcategory').html(response.subcategories);
$('#partner').html(response.results);
$('#subcategory').prop('disabled', false);
}
});
} else {
$('#subcategory').html('<option value="">Zuerst Überkategorie auswählen!</option>');
}
});
PHP:
//Dropdown No. 1
if(!empty($_POST['category_id']))
{
// Anzeigen von Ergebnisse - 1. Ebene
$query = "SELECT * FROM partner WHERE category_id = ".$_POST['category_id']." AND status = 1
ORDER BY partner_name ASC";
$result = $connect->query($query);
$resultHTML = "";
if($result->num_rows > 0)
{
while($row = $result->FETCH_ASSOC())
{
$resultHTML .=
'<div class="div_results">
<h1>'.$row['partner_name'].'</h1><br>
<img src="'.$row['partner_logo'].'"><br>
Zum Unternehmen!
</div>';
}
}
// Anzeigen der Kategorien der 2. Ebene
$query = "SELECT * FROM subcategories WHERE category_id = ".$_POST['category_id']." AND status = 1 ORDER BY subcategory_name ASC";
$result = $connect->query($query);
$subCategoryHTML = "";
if($result->num_rows > 0)
{
$subCategoryHTML .= '<option value="">Kategorie auswählen!</option>';
while($row = $result->FETCH_ASSOC())
{
$subCategoryHTML .= '<option value="'.$row['subcategory_id'].'">'.$row['subcategory_name'].'</option>';
}
}
$returnData = array("results" => $resultHTML, "subcategories" => $subCategoryHTML);
echo json_encode($returnData);
}
I am currently trying to build a "ToDo-App" which lets me INSERT text into a database, which will then be displayed. There is a "feature" to delete content based on their ID.
If I input two tasks into my application, I get two table records with ID 1 and 2. When I delete record 1, the record with ID 2 still exists. Thus, the record with ID 2 is listed as the first item in the to-do list.
I have to enter "2" in the "delete input field" to delete the first item from the list! How can I get this to be in sync? Is the ID field appropriate for maintaining the logical / application level order of the tasks?
<!doctype HTML>
<html>
<head>
<meta charset="utf-8">
<title>ToDo-APP</title>
<link rel="stylesheet" href="css/Lil-Helper.css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link rel="stylesheet" href="css/webfonts/all.css">
<link rel="stylesheet" href="css/own.css">
</head>
<?php
$con = mysqli_connect("","root","","todo");
$sql = "SELECT text FROM work";
$res = mysqli_query($con, $sql);
if(isset($_POST["text"]))
{
$eingabe = $_POST["text"];
$query = "INSERT INTO work(text) VALUES('$eingabe')";
mysqli_query($con, $query);
header("Refresh:0");
}
else
{
echo "";
}
if(isset($_POST["del"]))
{
$del = $_POST["del"];
$res = mysqli_query($con, $sql);
$sql2 = "DELETE FROM `work` WHERE `work`.`id` = $del";
mysqli_query($con, $sql2);
header("Refresh:0");
}
else
{
echo "";
}
?>
<body>
<header class="lil-menu lil-flex lil-flex-center align-center">
<a href="index.html" class="lil-brand">
<h3>To-Do</h3>
</a>
<a class="lil-menu-item currentLink" href="index.html">ToDo</a>
<a class="lil-menu-item" href="#archive">Archiv</a>
<a class="lil-menu-item" href="#Sprachen">Sprachen</a>
</header>
<div class="main">
<div class="lil-box">
<h3 class="lil-font-rot lil-big-font lil-space lil-font-style" style="font-size: 4rem;">ToDo</h3>
<div class="lil-box">
<form action="index.php" method="post">
<input class="lil-input" name="text" type="text">
<input type="submit" class="lil-button-green" value="Hinzufügen">
</form>
<ol id="liste" class="lil-list">
<?php
while($dsatz = mysqli_fetch_assoc($res))
{
echo "<li>" .$dsatz["text"] ."</li>";
}
?>
</ol>
<form id="form" action="index.php" method="post">
<input class="lil-input" name="del" type="text">
<input type="submit" class="lil-button-red lil-button-small" value=" Löschen ">
</form>
</div>
</div>
</div>
<script src="js/jquery-3.3.1.min.js"></script>
<script>
var anzahl = $("#liste li").length;
if(anzahl < 1)
{
$("#form").hide();
}
else
{
$("form").show();
}
</script>
</body>
</html>
The pictures:
HTML Output
MySQL Dashboard
As discussed in the comment, you can have multiple checkboxes forming an array parameter: <input name="theName[1]"> with explicit key and name="theName[]" with implicit keys.
Further more, you should use prepared statements to prevent SQL injection attacks. Imagine an attacker sends a request with a single quote ' in the field, i.e. he terminates the SQL string delimiter, and adds arbitrary SQL code. Prepared statements use placeholders and the parameters are sent separately.
You should also handle errors. In the code below errors are output as HTML, however, you should define your own logger function rather than just echo into the stream. This can output HTML on development servers but log to disk on production servers.
This is a working example tested on PHP7.3 with MariaDB 10:
<!DOCTYPE HTML>
<html lang="de">
<head>
<meta charset="utf-8">
<title>ToDo-APP</title>
<link rel="stylesheet" href="css/Lil-Helper.css">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<link rel="stylesheet" href="css/webfonts/all.css">
<link rel="stylesheet" href="css/own.css">
<style>
#frm-tasks button
{
padding: 0 18px;
}
</style>
</head>
<body>
<?php
mysqli_report(MYSQLI_REPORT_STRICT);
try
{
$con = new mysqli('localhost', 'testuser', 'testpasswd', 'testdb');
$action = $_POST['action'] ?? 'list';
if(!empty($_POST["text"]))
{
$eingabe = $_POST["text"];
try
{
$stmt = $con->prepare('INSERT INTO work(text) VALUES(?)');
$stmt->bind_param('s', $_POST["text"]);
$stmt->execute();
}
catch (mysqli_sql_exception $e)
{
$msg = $e->getMessage();
echo "<div>Error processing statement: $msg;</div>";
}
}
if('del' === $action && isset($_POST['rows']) && is_array($_POST['rows']))
{
try{
$stmt = $con->prepare('DELETE FROM `work` WHERE `work`.`id` = ?');
$stmt->bind_param('i', $row);
foreach ($_POST['rows'] as $row)
{
$stmt->execute();
if($e = $stmt->error)
echo "<div>DB Error: $e</div>";
}
}
catch (mysqli_sql_exception $e)
{
$msg = $e->getMessage();
echo "<div>Error processing statement: $msg;</div>";
}
}
?>
<header class="lil-menu lil-flex lil-flex-center align-center">
<a href="index.html" class="lil-brand">
<h3>To-Do</h3>
</a>
<a class="lil-menu-item currentLink" href="index.html">ToDo</a>
<a class="lil-menu-item" href="#archive">Archiv</a>
<a class="lil-menu-item" href="#Sprachen">Sprachen</a>
</header>
<div class="main">
<div class="lil-box">
<h3 class="lil-font-rot lil-big-font lil-space lil-font-style" style="font-size: 4rem;">ToDo</h3>
<div class="lil-box">
<!--form action="index.php" method="post"-->
<form id="frm-tasks" action="" method="post">
<input class="lil-input" name="text" type="text">
<button type="submit" class="lil-button-green" name="action" value="add">Hinzufügen</button>
<?php
try
{
$res = $con->query('SELECT id, text FROM work');
if(0 < $res->num_rows)
{
?>
<table>
<thead>
<tr>
<th></th><th>ID</th> <th>Aufgabe</th>
</tr>
</thead>
<tbody>
<?php
while($dsatz = mysqli_fetch_object($res))
{
?>
<tr>
<td><input type="checkbox" name="rows[]" value="<?php echo $dsatz->id;?>"></td><td><?php echo $dsatz->id;?></td> <td><?php echo $dsatz->text;?></td>
</tr>
<?php
}
?>
</tbody>
</table>
<button type="submit" class="lil-button-red lil-button-small" name="action" value="del">Löschen</button>
<?php
}
}
catch (mysqli_sql_exception $e)
{
$msg = $e->getMessage();
echo "<div>Error processing statement: $e->msg;</div>";
}
?>
</form>
</div>
</div>
</div>
<!-- not needed atm script src="js/jquery-3.3.1.min.js"></script-->
<h2>POST</h2>
<?php
var_dump($_POST);
}
catch (mysqli_sql_exception $e)
{
$msg = $e->getMessage();
echo "<div>Error connecting DB: $msg;</div>";
}
?>
</body>
</html>
The key of the list is the 'th' in the database so just fixing limits
Replace
if(isset($_POST["del"]))
{
$del = $_POST["del"];
$res = mysqli_query($con, $sql);
$sql2 = "DELETE FROM `work` WHERE `work`.`id` = $del";
mysqli_query($con, $sql2);
header("Refresh:0");
}
With
if(isset($_POST["del"]))
{
$del = $_POST["del"];
$res = mysqli_query($con, $sql);
$sql2 = "DELETE FROM `work` LIMIT 1 OFFSET ".array_search($del, mysqli_fetch_assoc($res));
mysqli_query($con, $sql2);
header("Refresh:0");
}
I have a php website which get executed twice. When I say echo hello; in config.php file it shows "hello" twice I checked all loops but I don't understand why this happens, anyone please help me out of this.
I'm really very thankful to him/her...
Here is the screenshot
My Website
Thank you in advance
<?
session_start();
//include "config.php";
require("config.php");
global $c,$loggedin;
include "data.php";
global $config;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><? echo $config["site_name"]; ?></title>
<link href="templates/ModernBlue/css/global.css" rel="stylesheet" type="text/css" />
<link href="templates/ModernBlue/css/site.css" rel="stylesheet" type="text/css" />
<!--33brushes-styles--><link href="templates/ModernBlue/33brushes-styles/css/bootstrap.css" rel="stylesheet" type="text/css" />
<link href="templates/ModernBlue/33brushes-styles/css/33brushes-custom.css" rel="stylesheet" type="text/css" />
<link href="templates/ModernBlue/33brushes-styles/css/jquery.onebyone.css" rel="stylesheet" type="text/css">
<link href="templates/ModernBlue/33brushes-styles/css/example1.css" rel="stylesheet" type="text/css">
<link href="templates/ModernBlue/33brushes-styles/css/animate.css" rel="stylesheet" type="text/css">
<link href='https://fonts.googleapis.com/css?family=Cuprum:400,700' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Raleway:400,600' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Lato:400,700,900' rel='stylesheet' type='text/css'>
<link rel="icon" href="favicon.png" type="image/png"/><!--33brushes-styles-->
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.9.1.custom.min.js"></script>
<link href="templates/ModernBlue/css/evolutionscript/jquery-ui-1.9.2.custom.css" rel="stylesheet">
<script type="text/javascript" src="js/evolutionscript.js"></script>
<script type="text/javascript" src="js/l2blockit.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/bootstrap.min.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/bootstrap_custom.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/jquery.onebyone.min.js"></script>
<script type="text/javascript" src="templates/ModernBlue/33brushes-styles/js/jquery.touchwipe.min.js"></script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { $('#slider').oneByOne({ className: 'oneByOne1', easeType: 'random', slideShow: true, slideShowDelay: 5000 }); }); </script>
<? if($_GET['r']){
header('location:cmrf/register.php?r='.$_GET['r']) ;
} ?>
</head><body>
<div class="wrapper"><div class="header-top"> <div class="container">
<div class="logo fl-l"></div>
<div class="header-right"> <div class="top-navi">
<ul class="nav nav-pills fl-l">
<li>Member Login</li>
<li>New Participant List</li>
</ul>
</div>
<div class="navigation">
<ul class="nav nav-pills" style="margin-left: 2px;">
<li>Home</li>
<li> LOGIN </li>
<li>REGISTER </li>
<li> SYSTEM</li>
<li>IDEOLOGY</li>
<li>BONUS</li>
<li>NEWS</li>
<li>CONTACT</li> </ul>
<div class="clear"></div> </div> </div> <!--end header-right--> </div> <!--end container--></div> <!--end header-top-->
<div class="slider-container"> <div class="container"> <div class="slider-content">
<div id="slider">
<div class="oneByOne_item">
<div class="slider-fl1">
<h2>Help To Earn</h2>
<p>The first way to get financial help from PHP Community is by providing help. Currently you will be making 35% in 30 days, calculated daily from the day you pledged to help Someone </p>
</div>
<!--end slider-fl1--> <img src="templates/ModernBlue/33brushes-styles/img/slide1-1.png" class="slide1-1" alt=""></img>
</div> <div class="oneByOne_item">
<div class="slider-fl1">
<h2>OUR GREAT PLAN</h2>
<p>The goal of PHP is today you provide help, tomorrow you may request help when you require for whatever amount. The calculation is just as preventive measure for the parasites of the community from abusing our system.
</p>
</div><!--end slider-fl1--> <img src="templates/ModernBlue/33brushes-styles/img/slide2-1.png" class="slide2-1" alt=""></img>
</div> <div class="oneByOne_item">
<div class="slider-fl1">
<h2>Introduce to Earn !</h2>
<p>Any member can be an introducer, each time your introduced member provide any amount of help, as a normal member you will earn 10% of the amount.
</p>
</div><!--end slider-fl1--> <img src="templates/ModernBlue/33brushes-styles/img/slide3-1.png" class="slide3-1" alt=""></img>
</div> </div>
<div class="clear"></div>
<div class="more-ways">Achieve Success with EASY!!</div> </div> <!--end slider-content-->
</div> <!--end container--> </div> <!--end slider-container-->
<!-- End Content -->
</div><!--end main-content--> <div class="footer-top"> <div class="container">
<div class="span6">
Home •
Login •
Register •
System •
Ideology •
Bonus •
Contact </div>
<div class="social-logos"><br>Copyright © 2016/17 <? echo $config["site_name"]; ?> All rights reserved. </div> </div> <!--end container--></div>
</div> <!--end wrapper--></body>
</html>
config.php
<?php
$dhost = "localhost"; // Isi dengan localhost
$dusername = ""; // database user
$dpassword = ""; // database pass
$ddatabase = ""; // database name
date_default_timezone_set("Africa/Johannesburg");
$con = mysql_connect($dhost, $dusername, $dpassword) or die("Cannot Connect");
mysql_select_db($ddatabase, $con);
if($_COOKIE["usNick"] and $_COOKIE["usPass"])
{
$q = mysql_query("SELECT * FROM tb_users WHERE username='{$_COOKIE['usNick']}' AND password='{$_COOKIE['usPass']}'") or die(mysql_error());
if(mysql_num_rows($q) == 0)
{
$_COOKIE['usNick'] = false;
$_COOKIE['usPass'] = false;
} else {
$loggedin = 1;
$r = mysql_fetch_array($q);
}
}
$da = date("j");
$user=$_COOKIE['usNick'];
mysql_query("UPDATE tb_jual SET status='Success' WHERE saldo='0'") or die(mysql_error());
mysql_query("UPDATE tb_beli SET status='Success' WHERE verify!=''") or die(mysql_error());
$skrg=time();
$query="select * from tb_beli where dpro < '$skrg' and status='Success' and spro=''";
$result=mysql_query($query);
while ($row=mysql_fetch_array($result)) {
$namauser=$row["username"];
$duitc=$row["jpro"];
$idlo=$row["id"];
mysql_query("UPDATE tb_users SET money=money+'$duitc' WHERE username='$namauser'") or die(mysql_error());
mysql_query("UPDATE tb_beli SET spro='berhasil' where id='$idlo'") or die(mysql_error());
}
/*****************GH match with balance*********************/
echo 'hellooooooooooooo';
include_once("function.php");
$pak = $_GET['pak'];
$saldo_arr = array(1,2,3,4,5,6,7,8,9,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100,150,200,250,300,350,400,450,500,600,700,800,900,1000);
for($i=0;$i<count($saldo_arr);$i++)
{
$saldooo = $saldo_arr[$i];
$tablaa = mysql_query("SELECT * FROM tb_jual where status='pending' and saldo!='0' and saldo='$saldooo' and username!='$kurirz' ORDER BY id ASC limit 0,1");
$registroo = mysql_fetch_array($tablaa);
$saldo_match = 0;
$kurir=$registroo["username"];
$biaya=$registroo["saldo"];
$idnya=$registroo["id"];
$pakt=$registroo["paket"];
$skrg=time();
$exp=$skrg+245600;
$sms = mysql_query("SELECT * FROM tb_beli where status='pending' and referer='' and saldo='$biaya' ORDER BY id ASC limit 0,1");
while($registroo1 = mysql_fetch_array($sms)){
$saldo_match = 1;
$kurirz=$registroo1["username"];
$idnyaz=$registroo1["id"];
$pake=$registroo1["paket"];
mysql_query("UPDATE tb_beli SET referer='$kurir', iddb='$idnya', exp='$exp' where status='pending' and id='$idnyaz' ") or die(mysql_error());
mysql_query("UPDATE tb_jual SET status='Waiting for transfer' where id='$idnya'") or die(mysql_error());
}
}
$pak1 = $pak/100;
/* for($n=0;$n<count($saldo_arr);$n++)
{
$saldoe = $saldo_arr[$n];
$tablae = mysql_query("SELECT * FROM tb_jual where status='pending' and saldo!='0' and saldo='$saldoe' and username!='$kurirz' ORDER BY id ASC limit 0,1");
$registroe = mysql_fetch_array($tablae);
//echo $biaya; */
if($saldo_match == 0){
$number = $pak1;
//echo $number.'hii';
if($number>1 && $number<10)
{
$n = 2;
}
elseif($number>10 && $number<100)
{
$n=5;
}
elseif($number>100 && $number<1000)
{
$n=5;
}
$multiple = 1;
$values = get($number, $n, $multiple);
print_r($values);
for($v=0;$v<count($values);$v++){
}
/* $sal = $values[$v];
$query_notmatch = mysql_query("SELECT * FROM tb_beli where status='pending' and referer='' and saldo='$sal' and existed='0' order by id ASC");
$registroo2 = mysql_fetch_row($query_notmatch);
$kurirz=$registroo2[1];
$idnyaz=$registroo2[0];
$pake=$registroo2[5];
$saldoz=$registroo2[6];
if(!$saldoz)
{
$saldoz=0;
echo $saldoz.'hii';
}
$skrg=time();
$exp=$skrg+245600;
if($saldoz!=$sal){
echo "hello123";
$pakett= $sal*100;
$user=$_COOKIE["usNick"];
$nama=$registroo["nama"];
$email=$registroo["email"];
$bank=$registroo["bank"];
$norek=$registroo["norek"];
$phone=$registroo["phone"];
$paket=$sal*100;
$laip = $_SERVER['REMOTE_ADDR'];
$eltiempo=time();
$query = "INSERT INTO tb_jual (username, bank, norek, nama, paket, saldo, phone, email, status, date, ip) VALUES('$user','$bank','$norek','$nama','$paket', '$sal', '$phone', '$email', 'pending','$eltiempo','$laip')";
mysql_query($query) or die(mysql_error());
echo $paket;
mysql_query("UPDATE tb_jual SET status='pending', paket='$pakett', saldo='$sal' where id='$idnya'") or die(mysql_error());
}
else{
mysql_query("UPDATE tb_beli SET referer='$kurir', iddb='$idnya', exp='$exp' , existed='1' where status='pending' and id='$idnyaz'") or die(mysql_error());
mysql_query("UPDATE tb_jual SET status='Waiting for transfer', saldo='$sal' where id='$idnya'") or die(mysql_error());
} */
}
/* } */
/*********************************/
$skrg=time();
$queryf="select * from tb_beli where exp < '$skrg' and exp != '' and status='pending'";
$result=mysql_query($queryf);
while ($rowf=mysql_fetch_array($result)) {
$namaibu=$rowf["username"];
$idbu=$rowf["id"];
$idkol=$rowf["iddb"];
$paket=$rowf["paket"];
mysql_query("DELETE from tb_beli WHERE id='$idbu'") or die(mysql_error());
mysql_query("UPDATE tb_users SET suspend='1' WHERE username='$namaibu'") or die(mysql_error());
mysql_query("UPDATE tb_jual SET status='pending', date='$skrg' WHERE id='$idkol'") or die(mysql_error());
/**************sms send match******************/
/* $sms = mysql_query("SELECT * FROM tb_beli where status='pending' and referer='' and paket='$paket' order by id ASC limit 0,1");
while($sms_values = mysql_fetch_array($sms))
{
$phone=$sms_values['phone'];
$namew= $sms_values['username'];
$username_sms = urlencode("Bluejack");
$password_sms= urlencode("YUS#7860");
$api_id = urlencode("3610145");
$to = urlencode($phone);
$message = urlencode("Dear $namew,
Your order on PHP Community Stokvel is out, Please log in your system for further instructions
,Thank you
");
?>
<div class="sms">
<?php echo file_get_contents("http://www.mymobileapi.com/api5/http5.aspx?Type=sendparam&username=$username_sms&password=$password_sms&numto=$to&data1=$message");
?>
</div>
<? } *//******************End sms********************************/
}
$tablaqa = mysql_query("SELECT * FROM tb_config where item='bintanga'");
while ($registroqa = mysql_fetch_array($tablaqa)) {
$duitq=$registroqa["price"];
$tabla = mysql_query("SELECT * FROM tb_users where referals >=$reffq and jdb >=$duitq and ba=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='1', ba='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b1=b1+1 where username='$kurire'") or die(mysql_error());
}}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang2'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b1 >=$reffq and bi=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='2', bi='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b2=b2+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang3'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b2 >=$reffq and bu=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='3', bu='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b3=b3+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang4'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b3 >=$reffq and be=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='4', be='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b4=b4+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang5'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b4 >=$reffq and bo=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='5', bo='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b5=b5+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang6'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b5 >=$reffq and bz=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='6', bz='ok' where id='$idnya'") or die(mysql_error());
mysql_query("UPDATE tb_users SET b6=b6+1 where username='$kurire'") or die(mysql_error());
}
}
$tablaq = mysql_query("SELECT * FROM tb_config where item='bintang7'");
while ($registroq = mysql_fetch_array($tablaq)) {
$reffq=$registroq["price"];
$tabla = mysql_query("SELECT * FROM tb_users where b6 >=$reffq and bx=''");
while ($registro = mysql_fetch_array($tabla)) {
$kurire=$registro["referer"];
$idnya=$registro["id"];
mysql_query("UPDATE tb_users SET bintang='7', bx='ok' where id='$idnya'") or die(mysql_error());
}
}
?>
Hi I have searched for a simple script that helps med sort my database with php in HTML href link. All I have found is too complicated. My database is holding filenames and who uploaded an image file and what date it was added. It won't sort the images by date or uploader. I can see in the browsers address field that it changes the link value.
Could you please help me?
<?php
include ("includes/localdbc.php");
?>
<!Doctype html>
<html lang="sv"><!--Här bestäms språket-->
<head><!--Övrig information till dokumentet -->
<meta charset = "utf-8"><!--teckenuppsättningen för att hantera svenska tecken-->
<title>Fotoalbum</title><!--Dokumentets titel-->
<link rel ="stylesheet" type = "text/css" href= "stilmall.css">
<link rel="stylesheet" type="text/css" href= "fancybox/source/jquery.fancybox.css" media="screen">
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" src="fancybox/source/jquery.fancybox.js"></script>
<script type="text/javascript" src="fancybox/source/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{$(".fancybox").fancybox();
helpers : {
title: {
type: 'inside'}}
$("a[href$='.jpg']").attr('rel', 'gallery').fancybox();
});
</script>
</head>
<body>
<section class="arbetsyta">
<?php
include ("includes/nav.php");
?>
<div>
<h2> Välkommen!</h2>
<p class="mellanrubrik">Här kan du ladda upp dina foton</p>
<p class="stycke">Bilden ska vara en jpg och inte vara större än 200kb</p>
</div>
<div class="formyta"><!-- formulär för uppladdning av bilder -->
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="200000" /> <!-- 200K max storlek -->
<label for="file">Filnamn:</label><br />
<input type="file" name="file" class="textfalt" /><br />
<label>Beskrivning:</label><br />
<input type="text" title="beskrivning" name="beskrivning" class="textfalt" /><br />
<label>Uppladdad av:</label><br />
<input type="text" name="uppladdare" class="textfalt" /><br />
<input type="submit" value="Ladda upp" class="knapp"/>
</form>
</div>
//Upload images script
<?php
if (isset($_FILES['file'])) {
if ((($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] ==
"image/pjpeg")) && ($_FILES["file"]["size"] < 200000)) {
if ($_FILES["file"]["error"] > 0) {
echo "Felmeddelande: " . $_FILES["file"]["error"] . "<br />";
} else {
if (file_exists("bilder/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " finns redan. Välj ett annat filnamn.";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "bilder/" . $_FILES["file"]["name"]);
$storedfile = $_FILES["file"]["name"];
$thumbnail = "thumb_" . $_FILES["file"]["name"];
$width_thumbnail = 350;
$height_thumbnail = 100;
list($width_thumbnail_orig, $height_thumbnail_orig) = getimagesize('bilder/' .$storedfile);
$ratio_orig = $width_thumbnail_orig / $height_thumbnail_orig;
if ($width_thumbnail / $height_thumbnail > $ratio_orig) {
$width_thumbnail = $height_thumbnail * $ratio_orig;
$height_thumbnail = $width_thumbnail / $ratio_orig;
} else {
$height_thumbnail = $width_thumbnail / $ratio_orig;
$width_thumbnail = $height_thumbnail * $ratio_orig;
}
$image_p = imagecreatetruecolor($width_thumbnail, $height_thumbnail);
$image = imagecreatefromjpeg('bilder/' . $storedfile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width_thumbnail, $height_thumbnail, $width_thumbnail_orig, $height_thumbnail_orig);
imagejpeg($image_p, 'bilder/' . $thumbnail);
$beskrivning = $_POST["beskrivning"];
$beskrivning = mysqli_real_escape_string($dbc, $beskrivning);
$uppladdare = $_POST["uppladdare"];
$uppladdare = mysqli_real_escape_string($dbc, $uppladdare);
$datum = $_POST["datum"];
$datum = mysqli_real_escape_string($dbc, $datum);
$sql="INSERT INTO foto (filnamn, beskrivning, uppladdare)
VALUES
('$storedfile','$beskrivning','$uppladdare')";
if (!mysqli_query($dbc,$sql))
{
die('Error: ' . mysqli_error($dbc));
}
}
}
}
else {
// Här hamnar man om det inte är JPEG/bildfil för stor
echo "Ej JPEG/Bildfilen större än 200kb.";
} //End upload script
?>
<div id="sort">
<?php
$order="";
if(isset($_GET['order'])) {
if($_GET['order']=="uppladdare"){
$order = "ORDER BY uppladdare";
}
if($_GET['order']=="datum"){
$order = "ORDER BY datum DESC";
}
}
$query ="SELECT * FROM foto $order";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result))
// It is here something good should be written ?>
<p class="nav">Sortera bilder:</p>
<a class="nav" href="medlem.php?order=uppladdare">Uppladdad av:</a><span style="padding-left:30px;"></span>
<a class="nav" href="medlem.php?order=datum">Datum:</a>
</div>
<div id="bildyta">
<?php //Images shows
$query = "SELECT * FROM foto";
$result = mysqli_query($dbc, $query) or die('Fel vid SQL-fråga');
while($row = mysqli_fetch_array($result))
{
$storedfile = $row['filnamn'];
$beskrivning = $row['beskrivning'];
$uppladdare =$row['uppladdare'];
$datum = $row['datum'];
$bildtext = "$beskrivning" ." " ."Uppladdad av:"." " ."$uppladdare"." "."$datum";
echo "<a class='fancybox' title='$bildtext' href='bilder/$storedfile'><img src='bilder/thumb_$storedfile' alt='$beskrivning'/></a>\n" . " " . " ";
}
mysqli_close($dbc);
?>
</div>
</section>
</body>
</html>
could you replace this from div id="sort" in your code with the below one
<div id="sort">
<?php /*?><?php
$order="";
if(isset($_GET['order'])) {
if($_GET['order']=="uppladdare"){
$order = "ORDER BY uppladdare";
}
if($_GET['order']=="datum"){
$order = "ORDER BY datum DESC";
}
}
$query ="SELECT * FROM foto $order";
$result = mysqli_query($dbc, $query);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
// It is here something good should be written ?><?php */?>
<p class="nav">Sortera bilder:</p>
<a class="nav" href="medlem.php?order=uppladdare">Uppladdad av:</a><span style="padding-left:30px;"></span>
<a class="nav" href="medlem.php?order=datum">Datum:</a>
</div>
<div id="bildyta">
<?php //Images shows
$order="";
if(isset($_GET['order'])) {
if($_GET['order']=="uppladdare"){
$order = "ORDER BY uppladdare";
}
if($_GET['order']=="datum"){
$order = "ORDER BY datum DESC";
}
}
$query ="SELECT * FROM foto $order";
$result = mysqli_query($dbc, $query) or die('Fel vid SQL-fråga');
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$storedfile = $row['filnamn'];
$beskrivning = $row['beskrivning'];
$uppladdare =$row['uppladdare'];
$datum = $row['datum'];
$bildtext = "$beskrivning" ." " ."Uppladdad av:"." " ."$uppladdare"." "."$datum";
echo "<a class='fancybox' title='$bildtext' href='bilder/$storedfile'><img src='bilder/thumb_$storedfile' alt='$beskrivning'/></a>\n" . " " . " ";
}
mysqli_close($dbc);
?>
</div>
</section>
</body>
</html>
and also one of your if loop is not properly closed. please put a } to close after //End upload script
I am trying to make tabs that contain information about student, these information is stored in the database. I want the first tab to show the information of all students. and the the second tab to show the information of the students that thier grade is A and the the third tab to show the information of the students that thier grade is B.
I made this code but just the first tab shows the information of the students but the second and third tabs don't show anything.
what is wrong with the code?
<html>
<head>
<title>students table</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
</head>
<body>
<div id="tabs">
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<?php
$connection = mysql_connect("","","");
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("", $connection);
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
?>
<div id="tabs-1">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
<?Php
$result2 = mysql_query("SELECT * FROM studentTable WHERE grade = 'A'");
while($row = mysql_fetch_array($result2))
{
?>
<div id="tabs-2">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
<?php
$result3 = mysql_query("SELECT * FROM studentTable WHERE grade = 'B'");
while($row = mysql_fetch_array($result3))
{
?>
<div id="tabs-3">
<?php
echo "Student id: '" . $row["id"];
echo "Student name: '" . $row["name"];
echo "Student grade: '" . $row["grade"];
echo '</table>';
}
?>
</div>
</div>
</body>
</html>
I think your issue is because you have your tabs-# <div> opening tags inside your while() loops.
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
?>
<div id="tabs-1"> //this here needs to be above/outside while($row = mysql_fetch_array($result)){
This is creating n number of <div id="tabs-1">,<div id="tabs-2">,<div id="tabs-3">, without matching closing tags </div>, so now <div id="tabs-2"> & <div id="tabs-3"> are nested in <div id="tabs-1"> and jQuery doesn't know which one to bind tabs to.
try moving them before the while() loops -
<div id="tabs-1">
<?php
$result = mysql_query("SELECT * FROM studentTable");
while($row = mysql_fetch_array($result))
{
...
}
?>
</div>
<div id="tabs-2">
<?php
$result2 = mysql_query("SELECT * FROM studentTable WHERE grade = 'A'");
while($row = mysql_fetch_array($result2))
{
...
}
?>
</div>
<div id="tabs-3">
<?php
$result3 = mysql_query("SELECT * FROM studentTable WHERE grade = 'B'");
while($row = mysql_fetch_array($result3))
{
...
}
?>
</div>
Also, you have echo '</table>'; at the end of each tab div. May want to remove those if you don't actually have a table.
In your script you are trying to use Jquery's tab method.
<script>
$(function() {
$( "#tabs" ).tabs();
});
</script>
This is looking in the HTML for
<div id='tabs'>
You're tabs in here
</div>
Assuming that your SQL statments is not returing "NULL" then I would say you're issue is that you named you're div's tab-1, tab-2, tab-3. With ID's. This means that Jquery can't find anything to turn into tab's.
Change your jquery call to something like this
<script>
$(function() {
$( ".tabsclass" ).tabs();
});
</script>
and instead of using id's use classes.
<div class='tabsclass' id='tab-1'>
You're tabs in here
</div>
<div class='tabsclass' id='tab-2'>
You're tabs in here
</div>
<div class='tabsclass' id='tab-3'>
You're tabs in here
</div>