Actually I am working on the 2002 ( old php project) based on the requirement. So my work is to show the difference between events markers based on the dates by placing some width dynamically in php. So I wrote the code after that it is not even displaying the events markers in the page.
I will provide the code which I wrote for this requirement.
function getEvents($uid)
{
$timeLineQry = mysql_query("select * from timelines where user_id = $uid and status=1 order by id desc");
if(mysql_num_rows($timeLineQry) > 0)
{
$data='';
while($tres = mysql_fetch_assoc($timeLineQry))
{
$data.='<div class="events-chat" id="timeline'.$tres['id'].'">
<button class="btn btn-success" onclick="addEvent('.$tres['id'].')"> Add Event</button>
<div id="" style="float:right;">
<span style="margin-left: 10px;color: #696767;
cursor: pointer;margin-right: 25px;font-size: 16px;font-weight: bolder;font-family: inherit;" onclick="getTimeLine(\''.$tres['title'].'\',\''.$tres['description'].'\',\''.$tres['id'].'\')">'.$tres['title'].'</span>
<i class="glyphicon glyphicon-trash" onclick="deleteTimeline('.$tres['id'].')"></i>
</div>
<div style="clear:both;margin-bottom:35px;"></div>
<div id="eventBlck'.$tres['id'].'">';
//echo "select * from events where user_id = $uid and timeline=".$tres['id'];exit;
$user_exe1 = mysql_query("select * from events where user_id = $uid and timeline=".$tres['id']." order by date asc");
if(mysql_num_rows($user_exe1) > 0) {
$i=1;
$data.='<div class="events-chat-inner">
<div class="all-cht-blk">
<div class="event-border">
<div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
<div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
</div>
';
while($res = mysql_fetch_assoc($user_exe1))
{
//Here is the code I just tried to subtract the date of one event from date of another event.
$datecount = count($res['date']);
for($j = 0; $j <= $datecount; $j++){
$previous_event_date = strtotime($res['date'][j]);
$present_event_date = strtotime($res['date'][j+1]);
$distance = $previous_event_date - $present_event_date;
$distance = floor($distance/(60 * 60 * 24));
$case1 = range(0,20);
$case2 = range(1,40);
if(in_array($distance,$case1))
{
$distancestyle = 'width:130px';
}
elseif(in_array($distance,$case2))
{
$distancestyle = 'width:180px';
}
else
{
$distancestyle = 'width:230px';
}
if($i%2==0){$bc='#f45e34';}else if($i%3==0){$bc='#fa454a';}else if($i%4==0){$bc='#3cb54b';}else if($i%5==0){$bc='#03aeac';}else{$bc='#9f388b';}
if($i%2==0)
{
$data.='<div class="event-ct-blk" style='\$distancestyle\'>
<h3 onclick="getData('.$res['id'].',
\''.str_replace("'","\'",$res['name']).'\',
\''.str_replace("'","\'",$res['description']).'\',
\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['name'].'</h3>
<p onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['description'].' </p>
<div class="pointer">
<div class="c-dot"></div>
<div class="p-strip-2" style="height:125px;"></div>
<div class="q-circle-outer" onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">
<div class="q-circle" style="background: '.$bc.';"></div>
</div>
<div class="p-strip" style="height:25px;"></div>
<div class="c-dot"></div>
</div>
<p class="q-date" onclick="getData('.$res['id'].',
\''.str_replace("'","\'",$res['name']).'\',
\''.str_replace("'","\'",$res['description']).'\',
\''.date('m-d-Y',strtotime($res['date'])).'\');"> Date: '.date('M-d-Y',strtotime($res['date'])).' </p>
</div>';
}
else
{
$data.='<div class="event-ct-blk" style='\$distancestyle\'>
<h3 onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['name'].'</h3>
<p onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">'.$res['description'].' </p>
<div class="pointer">
<div class="c-dot"></div>
<div class="p-strip" style="height:25px;"></div>
<div class="q-circle-outer" onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');">
<div class="q-circle" style="background: '.$bc.';"></div>
</div>
<div class="p-strip-2" style="height:125px;"></div>
<div class="c-dot"></div>
</div>
<p class="q-date" onclick="getData('.$res['id'].',\''.str_replace("'","\'",$res['name']).'\',\''.str_replace("'","\'",$res['description']).'\',\''.date('m-d-Y',strtotime($res['date'])).'\');"> Date: '.date('M-d-Y',strtotime($res['date'])).' </p>
</div>';
}
$i++;
}
$data.='</div></div>';
}
else
{
$data.='<div class="event-border" style="width:96%;">
<div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
<div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
</div><div style="text-align:center;margin-top:78px;font-size: 18px;"><p>No events added.</p></div>';
}
$data.='</div></div>';
}
}
else
{
$data='<div class="events-chat" id="timeline1"> <button class="btn btn-success" onclick="addEvent(1)"> Add Event</button><div style="clear:both;margin-bottom:35px;"></div><div id="eventBlck1"> <div class="event-border" style="width:96%;">
<div class="c-dot" style="float:left;position:absolute;left:-4px;top:-4px;"></div>
<div class="c-dot" style="float:right;position:absolute;right:-4px;top:-4px;"></div>
</div><div style="text-align:center;margin-top:78px;font-size: 18px;"><p>No events added.</p></div></div></div>';
}
}//end for loop
return $data;
}
In this code I place the code which I marked as the comments and actually this is the code I have present but after working on this file events are not showing canyou please see the issue in this code or any errors.
I am creating a seat reservation system. In my system, the code check number of seats a bus contains then pass it inside a for loop. When a user pick 2 passengers, it means two seats will be booked. How can I validate the checkbox in the for loop depending on the number of passenger(s) selected.
Using the GUI for more explanation.
on the main page, 2 there indicates number of passenger(s) selected.
When you come to the second page where the values are passed to, you can see 2 Adults as the selected number of passengers. When you click on Submit Button it does not validate the checkbox based on the number of passenger(s) selected. And if I should put required in the checkbox it validates the whole checkbox since it is in a loop
$_SESSION['seat_no'] is the number of seat(s) a bus contains. Let assume a user that want to book a seat selected two passengers which means two seats is booked, how can I validate the checkbox based on the number of seat(s) selected?
Here is my code:
<?php
for ($i = 1; $i <= $_SESSION['seat_no']; $i++) {
if(in_array($i,$mseat)){
echo "<div class='checkbox_wrapper_pick'>
<label>".$i."</label>
</div>";
}else{
echo "<div class='checkbox_wrapper'>
<input type='checkbox' value=".$i." name='seat_book[]' />
<label>".$i."</label>
</div>";
}
}
?>
The full source code:
<?php include("header.php"); error_reporting(0); ?>
<?php
if(isset($_POST['submit'])){
$from = $_POST['from'];
$to = $_POST['to'];
$date = $_POST['d_date'];
$nop = $_POST['nop'];
$_SESSION['from'] = $from;
$_SESSION['to'] = $to;
$_SESSION['date'] = $date;
$_SESSION['nop'] = $nop;
$get = mysqli_query($mysqli,"SELECT * FROM routes WHERE present_loc = '$from' and destination = '$to' ");
while($roys = mysqli_fetch_array($get)){
//get bus details
$bno = $roys['bus_no'];
$ploc = $roys['present_loc'];
$des = $roys['destination'];
$time = $roys['dept_time'];
$_SESSION['time'] = $time;
$amt = $roys['amount'];
$_SESSION['amt'] = $amt;
$b = str_replace( ',', '',$_SESSION['amt'] );
if( is_numeric($b) ) {
$a = $b;
}
$bus = mysqli_query($mysqli,"select * from bus where bus_no = '$bno'");
while($bu = mysqli_fetch_array($bus)){
$_SESSION['model'] = $bu['model'];
$_SESSION['seat_no'] = $bu['seat_no'];
$_SESSION['ac'] = $bu['bus_type'];
$_SESSION['excess_luggage'] = $bu['excess_luggage'];
$_SESSION['more_legs'] = $bu['more_legs'];
$_SESSION['id'] = $bu['id'];
}
$coun = mysqli_query($mysqli, "select count(booking_id) as seat, seats from booking where bus_no = '$bno' and seats !='' GROUP by booking_id" );
$mseat = array();
while($e = mysqli_fetch_array($coun)){
$bseat = $e['seat'];
$mseat[] = $e['seats'];
}
//$seatss = array();
$seat_string = implode(",",$mseat);
//get seats
$couns = mysqli_query($mysqli, "select sum(counter) as seat from booking where bus_no = '$bno' and seats !='' GROUP by bus_no" );
$rseats = mysqli_fetch_array($couns);
$lseat = $rseats['seat'];
if($_SESSION['seat_no'] == $lseat){
$tell = " No more seat(s) available.";
}else{
$tell = $_SESSION['seat_no'] - $lseat. " Seat(s) remaining.";
}
}
}
?>
<!--Main layout-->
<main class="mt-5">
<!--Main container-->
<form action="details" method="POST">
<!--Grid row-->
<div class="row">
<div class="col-lg-12 title-header mb-3 mx-auto z-depth-1">
<div class="row">
<div class="col-lg-8">
<?php echo '<h2> '.$_SESSION['from']. ' to '. $_SESSION['to']. '</h2>'; ?><br/>
<b><?php echo $_SESSION['date']; ?> :: <?php if($_SESSION['nop'] < '2') { echo $_SESSION['nop'] . ' Adult'; }
elseif($_SESSION['nop'] > 1) { echo $_SESSION['nop'] . ' Adults'; }
?></b>
</div>
</div>
</div>
<div class="col-lg-12 mbody"> <label style="margin-left: 4%; font-weight:bolder; font-size:20px; color:#000;">Details </label> </div>
<div class="col-lg-12 mbody bg-white ">
<table class="table table_view" style = "width: 100%; margin-left: 4%; margin-right:4%;">
<tbody>
<tr>
<td><b><?php echo $_SESSION['model']; ?></b><br/><?php echo $_SESSION['from']. ' to '. $_SESSION['to']; ?>
<br/><?php if($_SESSION['ac'] == 'AC') { echo '<span class="alert-info ac">'. $_SESSION['ac'] .'</span>'; }
else{ echo '<span class="alert-warning">No AC</pan>'; } ?>
<?php if($_SESSION['more_legs'] == 'Yes') { echo '<span class="alert-info ac">More Leg Room</span>'; }
else{ echo '<span class="alert-warning no">More Leg Not Available</pan>'; } ?>
</td>
<td><b>Departing Time</b><br/><i class="fa fa-clock-o" aria-hidden="true"></i> <?php echo $_SESSION['time']; ?></td>
<td> <img id = "seatimg" src="../images/seatsLayout/av.gif" class="img-responsive"> <?php echo $tell; ?></td>
<td>Adult <b>₦<?php echo $_SESSION['amt']; ?></b></td>
</tr>
</tbody>
</table>
</div>
<div class="col-lg-12">
<div class="col-lg-12 mbody"> <label style="margin-left: 3%; font-weight:bolder; font-size:20px; color:#000;"><img id = "seatimg" src="../images/seatsLayout/av.gif" class="img-responsive"> Select Seat</label> </div>
<div class="row detail">
<!--Grid column-->
<div class="col-lg-7 animation slideUp" >
<div class="well" id="bus_seats_layout" >
<table class="table table-bordered" cellspacing = "1" id="seatstable">
<tr>
<td><img id = "driverimg" src="../images/seatsLayout/steering.png" class="img-responsive" width="25" height="25"></td>
<td colspan="2" rowspan="3">
<?php
for ($i = 1; $i <= $_SESSION['seat_no']; $i++) {
if(in_array($i,$mseat)){
echo "
<div class='checkbox_wrapper_pick'>
<label>".$i."</label>
</div>
";
}else{
echo "
<div class='checkbox_wrapper'>
<input type='checkbox' value=".$i." name='seat_book[]' />
<label>".$i."</label>
</div>
";
}
}
?>
</td>
</tr>
</table>
</div>
</div>
<div class="col-lg-5">
<ul class="bt">
<li><img src="../images/seatsLayout/seat_available.png" class="img-responsive"> Available</li>
<li><img src="../images/seatsLayout/picked.png" class="img-responsive"> Selected</li>
<li><img src="../images/seatsLayout/seat_booked.png" class="img-responsive"> Booked</li>
</ul>
</div>
</div>
<div class="col-lg-12">
<input type="hidden" name="bus_no" value="<?php echo $bno; ?>">
<input type="hidden" name="to" value="<?php echo $to; ?>">
<input type="hidden" name="from" value="<?php echo $from; ?>">
<input type="hidden" name="amt" value="<?php echo $nop*$a; ?>">
<input type="hidden" name="nop" value="<?php echo $nop; ?>">
<div class="form-group">
<div align="right">
<input type="submit" name="submit" class="bme" value="Continue">
</div>
</div>
</div>
</div>
</div>
</form>
</main>
<?php include("footer.php"); ?>
I'm creating a booking site for meeting rooms.
I have done the sql query to search for free rooms according to the time and date chosen.
This is working. I display the free rooms (in a while loop) in cards with datas from the query.
<?php
if (isset($_POST['submit'])) {
echo '<main role="main">
<div class="card-columns">';
require_once 'connexion_BD.php';
$res_date = $_POST['res_date'];
$res_date = date("Y-m-d", strtotime($res_date));
$res_horaire_id = $_POST['res_horaire'];
$_SESSION['res_date'] = $_POST['res_date'];
$_SESSION['res_horaire'] = $_POST['res_horaire'];
$sql = "SELECT sal_nom, sal_nb_place, sal_notes
FROM salle
WHERE sal_id NOT IN (SELECT res_sal_id FROM reservation WHERE res_date = :res_date AND res_horaire_id = :res_horaire_id)";
$requete = $db->prepare($sql);
$requete->bindValue(':res_date', $res_date);
$requete->bindValue(':res_horaire_id', $res_horaire_id);
$requete->execute();
$i=0;
while ($row = $requete->fetch()) {
$tab_sal_nom[0+$i] = $row['sal_nom'];
$tab_sal_nb_place[0+$i] = $row['sal_nb_place'];
$tab_sal_notes[0+$i] = $row['sal_notes'];
?>
<div class="card bg-light">
<img class="card-img-top" <?php echo 'src="img/salle_reunion_'. rand(1, 8) .'.jpg"' ?> alt="Salle de réunion">
<div class="card-body">
<h5 class="card-title">Salle <?php echo $tab_sal_nom[0+$i]; ?></h5>
<p class="card-text">Salle disposant de <?php echo $tab_sal_nb_place[0+$i]; ?> places.</p>
<p class="card-text"><small class="text-muted">Informations de salle : <?php echo $tab_sal_notes[0+$i]; ?></small></p>
<form action="confirm_resa.php" method="POST">
<button class="btn btn-outline-primary float-right" style="margin-bottom: 15px;" name=<?php echo '"reserver_'.$tab_sal_nom[0+$i].'"'?> type="submit">Réserver</button>
</form>
</div>
</div>
<?php
$i = $i + 1;
}
}
?>
Now here's my problem, I want to know which room name the user choose to store the info in a $_SESSION['sal_choix'], so, I look at the submit button named <?php echo '"reserver_'.$tab_sal_nom[0+$i].'"'?> (equals to reserver_Daum, reserver_Majorelle, reserver_Galle, reserver_Corbin etc...)
My idea was to look with some if:
if (isset($_POST['reserver_Daum'])) $_SESSION['sal_choix'] = "Daum";
elseif (isset($_POST['reserver_Galle'])) $_SESSION['sal_choix'] = "Galle";
etc...
But that's not working, cause in the confirm_resa.php, $_SESSION['sal_choix'] is: undefined index
It's not a session problem because two other : $_SESSION['res_date'] and $_SESSION['res_horaire'] are sets.
I'm pretty sure the problem is in the if(isset($_POST[])) but I can't see it...
help pls!
I'm building php mysql app for job interviews, and I want to have for admin filer with bootstrap panels which are sorted by date in the same color column.
$db = connectPDO();
$query = ("SELECT razgovori.*, djelatnik.ime, djelatnik.prezime
FROM razgovori INNER JOIN djelatnik
ON djelatnik.id = razgovori.insert_by
ORDER BY datum_raz ASC");
$stmt = $db->prepare($query);
$stmt->execute();
$count = $stmt->rowCount();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$date = strtotime($row['datum_raz']);
$twoDaysAgoStart = strtotime('-2 day 00:00:00');
$yesterdayEnd = strtotime('yesterday 23:59:59');
$todayStart = strtotime('today 00:00:00');
$todayEnd = strtotime('today 23:59:59');
$tomorrowStart = strtotime('tomorrow 00:00:00');
$twoDaysAheadEnd = strtotime('+2 day 23:59:59');
<div class="container">
<div class="row">
<?php while ($row = $stmt->fetch(PDO::FETCH_ASSOC)): ?>
<?php $date = strtotime($row['datum_raz']); ?>
<?php if ($twoDaysAgoStart < $date && $yesterdayEnd > $date): ?>
<!--Panel info if past time Job interviews-->
<div class="col-md-4 pull-left">
<div class="panel panel-info">
<div class="panel-heading"><h3 class="panel-title"><?php echo
datumVrijemeSQLuHR($row['datum_raz']); ?></h3></div>
<div class="panel-body">
<div class="col-md-9">
<h5><a href="editRazgovori.php?id=<?php echo $row['id']; ?>"><?php
echo $row['rime'].' '.$row['rprezime']; ?></a></h5>
<?php echo $row['kontakt_br']; ?>
</div>
<div class="col-md-3">
<span class="label label-default pull-right"></h5><?php echo
$row['ime'].' '.$row['prezime']; ?></span>
</div>
</div>
</div>
</div>
<!--//Panel-->
</tr>
<tr>
<!--Panel primary if Job interview is today-->
<?php elseif ($todayStart <= $date && $todayEnd >= $date): ?>
<div class="col-md-4">
<div class="panel panel-primary">
<div class="panel-heading"><h3 class="panel-title"><?php echo
datumVrijemeSQLuHR($row['datum_raz']); ?></h3></div>
<div class="panel-body">
<div class="col-md-9">
<h5><a href="editRazgovori.php?id=<?php echo $row['id']; ?>"><?php echo
$row['rime'].' '.$row['rprezime']; ?></a></h5>
<?php echo $row['kontakt_br']; ?>
</div>
<div class="col-md-3">
<span class="label label-default pull-right"></h5><?php echo
$row['ime'].' '.$row['prezime']; ?></span>
</div>
</div>
</div>
</div>
</tr>
<tr>
<!--Panel warning if Job interview is tomorrow-->
<?php elseif ($tomorrowStart <= $date && $twoDaysAheadEnd >= $date): ?>
<div class="col-md-4 pull-right">
<div class="panel panel-warning">
<div class="panel-heading"><h3 class="panel-title"><?php echo
datumVrijemeSQLuHR($row['datum_raz']); ?></h3></div>
<div class="panel-body">
<div class="col-md-9">
<h5><a href="editRazgovori.php?id=<?php echo $row['id']; ?>"><?php
echo $row['rime'].' '.$row['rprezime']; ?></a></h5>
<?php echo $row['kontakt_br']; ?>
</div>
<div class="col-md-3">
<span class="label label-default pull-right"></h5><?php echo
$row['ime'].' '.$row['prezime']; ?></span>
</div>
</div>
</div>
</div>
<?php endif; ?>
<?php endwhile; ?>
</div><!--/row-->
</div><!--/container-->
I want to have sorted like thiswith Main Panal or without
I get this:enter image description here
Because stackoverflow red message constantly asking me for more details, i can't put my all php code
You can do this in your MySQL query.
Example:
SELECT * FROM t1
ORDER BY key_part1, key_part2;
SELECT * FROM t1
WHERE key_part1 = constant
ORDER BY key_part2;
SELECT * FROM t1
ORDER BY key_part1 DESC, key_part2 DESC;
SELECT * FROM t1
WHERE key_part1 = 1
ORDER BY key_part1 DESC, key_part2 DESC;
SELECT * FROM t1
WHERE key_part1 > constant
ORDER BY key_part1 ASC;
SELECT * FROM t1
WHERE key_part1 < constant
ORDER BY key_part1 DESC;
SELECT * FROM t1
WHERE key_part1 = constant1 AND key_part2 > constant2
ORDER BY key_part2;
More information can be found here: https://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html or https://www.w3schools.com/sql/sql_orderby.asp
If you want to do this inside PHP you can use sort:
<?php
$fruits = array("lemon", "orange", "banana", "apple");
sort($fruits);
foreach ($fruits as $key => $val) {
echo "fruits[" . $key . "] = " . $val . "\n";
}
?>
The above example will output:
fruits[0] = apple fruits[1] = banana fruits[2] = lemon fruits[3] =
orange
More information about PHP sort():
http://php.net/manual/en/function.sort.php
I am currently still learning PHP and I have been working on this project for a little over a week. I am pulling my hair out. So, we have a Lead Management System, users can enter comments for leads assigned to them. We want those comments to be hidden if the the lead is discarded or assigned to another user.
Here is the current code:
<?php $lead_id = $row['id'];?>
<?php $getcommentscount_stmt = "SELECT COUNT(*) FROM comments WHERE comment_by_user_id = $_SESSION[user_id] AND lead_id = $lead_id ORDER BY comment_created_on DESC";?>
<?php $result_commentscount = mysqli_query($mysqli, $getcommentscount_stmt);?>
<?php $comment_count = mysqli_fetch_row($result_commentscount);?>
<?php $num_comments = $comment_count[0];?>
<div class="panel-group" id="accordion2" style="margin-bottom: 0px;">
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
<a data-toggle="collapse" data-parent="#accordion2" href="#collapseTwo<?php echo $row['id'];?>">Comments<span class="caret"></span> <span class="badge pull-right"><?php echo $num_comments;?></span></a>
</h4>
</div>
<div id="collapseTwo<?php echo $row['id'];?>" class="panel-collapse collapse">
<div class="panel-body">
<table class="table table-bordered">
<tr>
<td width="25%"><strong>Time</strong></td>
<td width="75%"><strong>Comment</strong></td>
</tr>
<?php $lead_id = $row['id'];?>
<?php $getcomments_stmt = "SELECT * FROM comments WHERE comment_by_user_id = $_SESSION[user_id] AND lead_id = $lead_id ORDER BY comment_created_on DESC";?>
<?php $result_comments = mysqli_query($mysqli, $getcomments_stmt);?>
<?php while($row2 = mysqli_fetch_array($result_comments)) { ?>
<tr>
<td width="25%"><?php echo $row2['comment_created_on'];?></td>
<td width="75%"><?php echo nl2br($row2['comment_text']);?></td>
</tr>
<?php } ?>
</table>
This is the last thing I tried:
<?php $getcomments_stmt = "SELECT * FROM comments WHERE comment_by_user_id = $_SESSION[user_id] AND lead_id = $lead_id AND times_assigned <> 1 OR times_assigned IS NULL ORDER BY comment_created_on DESC";?>
I am not sure what else to show, but any help is appreciated.
EDIT: I am getting this
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in /var/www/html/html/showleads.html on line 884
Line 884:
<?php while($row2 = mysqli_fetch_array($result_comments)) { ?>