jquery tabs with mysql and pgp - php

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>

Related

how to change image from sql database during hover in php

PHP
I am trying to change the image during hover. For hover I used jquery, but the problem is that the first image is showing from the SQL database but the image is not changing while I already saved the second image in database
<?php
include('dbconnect.php');
$sql = "SELECT * FROM `products` JOIN `images` ON products.product_id=images.product_id";
$res = mysqli_query($conn, $sql);
echo "</h3> Total: " . mysqli_num_rows($res) . " Items Found </h3>";
?>
<br><br>
<div class="container">
<div class="row">
<?php
while ($row = mysqli_fetch_assoc($res)) {
?>
<div class="col item_col">
<?php echo $row["img_id"] . "<br>" . $row["product_id"] ."<br>". "<img src ='".$row["image_path1"]."' width=100px height=100px data-src1='".$row['image_path1']."' data-src2='".$row['image_path2']."'>"; ?>
</div>
<?php
}
?>
</div>
</div>
<?php
include('dbclose.php');
?>
jquery
<script type="text/javascript">
$(document).ready(function () {
$(".imgs").each(function(i,el){
$(this).mouseenter(function(){
$(this).attr("src",$(this).attr("data-src2"))
}).mouseleave(function(){
$(this).attr("src",$(this).attr("data-src1"))
})
})
});
</script>

PHP and HTML commenting system

I'm trying to build a comment system
this is my code
<html>
<head>
<link rel="stylesheet" type="text/css" href="css.css">
<style>
.back_glob{width: 350px}
</style>
<script type="text/javascript" src="jquery-3.1.0.min.js"></script>
<script type="text/javascript">
$(function(){
$( ".tombol_login" ).click(function() {
var txt = $("[name=comment]").val();
$("#comment").submit();
})});
</script>
<style>
.back_glob{width: 450px}
</style>
</head>
<body>
<div class = "back_glob">
<div class="tableC">
<img src="img\back.png" alt="back" height="42" width="42">
<div class ="back_header">
<h4>comment</h4>
</div>
<div class= "table">
<form id="comment" name="comment" action="contet2.php" method="post">
<div class="row">
<div class="col">comment</div>
<div class="col">:</div>
<div class="col"><textarea name="comment" rows ="10" cols="40"></textarea></div>
</div>
<div class="tom">
<button type="button" class="tombol_login">Submit</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
$servername = "localhost";
$dbname = "databaseform";
$username = "root";
$password = "";
session_start();
$page = 2;
$conn = new PDO("mysql:host =$servername ; dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = "SELECT form.Username, comment.Comment, comment.time FROM
form, comment WHERE
form.pkey=comment.pkey AND
comment.page=$page
ORDER BY comment.time DESC";
$result = $conn->query($query);
$hasil = $result->fetchAll();
$Comment = $_POST['comment'];
try
{
// injec
$query = "INSERT INTO comment (pkey,Comment,time,page)
VALUES (:Username,:Comment,NOW(),:page)";
$sql = $conn->prepare($query) ;
$sql->BindValue(':Username',reset($_SESSION['txt_login']));
$sql->BindValue(':Comment',$Comment);
$sql->BindValue(':page',$page);
$sql->execute();
$query = "SELECT form.Username, comment.Comment, comment.time FROM
form, comment WHERE
form.pkey=comment.pkey AND
comment.page=$page
ORDER BY comment.time DESC";
$result = $conn->query($query);
$hasil = $result->fetchAll();
echo '<div class="back_glob">';
echo '<div class = "table">';
echo '<div class = "tableC">';
echo '</div>';
}
catch(PDOException $e)
{
echo $query . "<br>" . $e->getMessage();
}
for($i = 0 ; $i < count($hasil);$i++)
{
echo'<div class="row">';
echo '<div class="col2">'.$result[$i]['Username'].'</div>';
echo '<div class="col2">'.$result[$i]['Comment'].'</div>';
echo '<div class="col2">'.$result[$i]['time'].'</div>';
echo'</div>';
}
?>
but the php part won't recognize the $_POST['comment'] before the submit button , i can't show the previous comment unless I click the submit button.
Is there any solution to correct this ??
I am really confused about your way of asking a question. I think you should have to read this tutorial of Smashing Magazine. So you can better understand of code and comment system.
I hope it will help you.

How to get value from mysql database row by row after each click on button?

I want to get questions one by one by clicking on button from mysql database table. Each question is one single row, want to get every next question by clicking on "next" button from every next row. I have made this code but this only shows first question in the table of first row in the database. My html code is:
<span ng-repeat="record in records" id="next">
<p id="hello">{{record.ques_no}}.
{{record.question}}</p>
<p><input type="text" ng-model="ans" id="ans" value=""></p>
<p align="center">Next</p>
</span>
php code getting value from database is:
$result=mysqli_query($con,"SELECT * FROM quest limit 1");
$record=array();
$number = 0;
while($row =mysqli_fetch_array($result))
{
$record[] = array(
'ques_no'=> $row['ques_no'],
'question'=> $row['question'],
'answer'=> $row['answer']
);
$number++;
}
<html>
<head>
<style>
.invisible{
display:none;
}
.visible{
display:visible;
}
</style>
<script src="js/jquery.min.js"></script>
<script>$(function()
{
$( "#button" ).click(function()
{
$( "div.container div.invisible" ).first().addClass( "visible" ).removeClass("invisible");
});
});
</script>
</head>
<div class="container">
<div class="invisible">1</div>
<div class="invisible">2</div>
<div class="invisible">3</div>
<div class="invisible">4</div>
<div class="invisible">5</div>
<div class="invisible">6</div>
<div class="invisible">7</div>
<div class="invisible">8</div>
<div class="invisible">9</div>
<div class="invisible">10</div>
</div>
<input type="button" id="button"/>
</html>
Something I put together real quick.
$("#nex").click(function() {
var formData1 = $("#ques").val();
$.ajax({
type:'POST',
data:{'tota':formData1},
url:'list1.php',
success:function(data){
alert(data);
var json = $.parseJSON(data);
// $("#hello").html(data);
$("#hello").html(json[0]);
}
});
});
list1.php
<?php
$total=$_POST['tota'];
$input=1;
$con=mysqli_connect("localhost","root","root","school");
$result=mysqli_query($con,"SELECT * FROM quest LIMIT $total OFFSET $input");
$record=array();
echo $input;
while($row =mysqli_fetch_array($result))
{
$record[] = array(
'ques_no'=> $row['ques_no'],
'question'=> $row['question'],
'answer'=> $row['answer']
);
}
echo json_encode($record);
mysqli_close($con);
?>
Facing some problem in retreiving json data

Retrieving Data from mySQL and display in PopUp

I am retrieving data from mySQL using PHP and able to show it, like the Job Titles in List Items. And would like to show the Job Skills and Description in a PopUp when it is clicked. Each Job Title will have unique Skills and Description. Please, help me...
Sample Code :
<?php
//including the database connection file
include_once("includes/db.php");
// Get all the data from the table
$result = mysql_query("SELECT * FROM job_posting ORDER BY id DESC") or die(mysql_error());
echo "<ul>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
// Print out the contents of each row into a table
echo "<li> <a href='post_resume.php?id=".base64_encode($row['id'])."'>" . $row['title'] . "</a></li>";
}
echo "<ul>";
?>
With reference to : http://jqueryui.com/dialog/
Put a div inside your li .
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.8.3.js"></script>
<script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<script>
$(function() {
$( ".dialog" ).dialog({ autoOpen: false });
});
</script>
<body>
<ul>
<li>
<div class="dialog" title="SOME TEXT">
<p>
JOB SKILLS AND DESCRIPTION
</p>
</div> </li> </ul> </body>

Deducting Numbers From Database Php

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>

Categories