i need to select data from table named booked from a given range of data and display data form a variable and then used it to select from another table and display the data that is selected but when the data that is selected from table booked is multiple only the first data is displayed in the variable here's my code:
$res1=mysqli_query($bd,"select * from booked where datefrom between '$from' and '$to' or dateto>='$from' and dateto='$to'");
$num1=mysqli_num_rows($res1);
if($num1>0)
{
for($y=0;$y<$row1=mysqli_fetch_assoc($res1);$y++)
{
$res=mysqli_query($bd,"select * from rooms where capacity>='$newcap' and room_number!='".$row1['roomnumber']."'");
while($row=mysqli_fetch_assoc($res))
{
echo'<div class="col-lg-4 col-md-4 col-sm-12">';
echo'<div class="newsBox">
<div class="thumbnail">
<figure><img src="reservation/img/rooms/'.$row['img'].'" width="230" height="150"></figure>
<div class="caption maxheight2">
<div class="box_inner">
<div class="box">
<a class="title"><strong>'.$row['name'].'</strong></p>
<b>'.$row['description'].'</b>
<p>'.$row['price'].'</p>
</div>
<a class="btn btn-default" href="info_pay.php?roomnumber='.$row['room_number'].'&roomtype='.$row['name'].'&from='.$_POST['from'].'&adult='.$_POST['adult'].'&child='.$_POST['child'].'&to='.$_POST['to'].'&roomprice='.$row['price'].'"><span class="glyphicon glyphicon-plus">Select this Room</span></a>
</div>
</div>
</div>
</div>';
echo'</div>';
}
}
}
You may want to to try a different approach using heredoc as it is less prone to quoting errors, here's a complete example to loop a mysqli query using heredoc.
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="select * from booked where datefrom between '$from' and '$to' or dateto>='$from' and dateto='$to'";
if ($result=mysqli_query($con,$sql))
{
while ($row=mysqli_fetch_row($result))
{
echo <<< LOL
<div class="col-lg-4 col-md-4 col-sm-12">
<div class="newsBox">
<div class="thumbnail">
<figure><img src="reservation/img/rooms/{$row['img']}" width="230" height="150"></figure>
<div class="caption maxheight2">
<div class="box_inner">
<div class="box">
<a class="title"><strong>{$row['name']}</strong></p>
<b>{$row['description']}</b>
<p>{$row['price']}</p>
</div>
<a class="btn btn-default" href="info_pay.php?roomnumber={$row['room_number']}&roomtype={$row['name']}&from={$_POST['from']}&adult={$_POST['adult']}&child={$_POST['child']}&to={$_POST['to']}&roomprice={$row['price']}"><span class="glyphicon glyphicon-plus">Select this Room</span></a>
</div>
</div>
</div>
</div>
</div>
LOL;
// Free result set
mysqli_free_result($result);
}
}
//close mysqli connection
mysqli_close($con);
?>
Related
What I need to do is display those returned events that fall between an open and a close date (between a two-week period for example 2022 08 15 to 2022 08 30) and if they do, I want to show and Register button that takes user to a registration page and if it is not true is show the user a Registration button that is not active that says "Registration Not Open". Right now, if one event is true and the rest are false, it will still return all are open for registration by showing the "Register" button for all returned events. The SQL is supposed to return the EventOpenDate (date event registration open) and EventCloseDate (date event registration is closed) and evaluated each returned event separately and show register button if the date falls between when the registration opens and when it is closed.
'''
enter code here
<div class="upcomming-events-area off-white ptb100">
<div class="container">
<div class="row">
<div class="col-xs-12">
<h1 class="section-title">Available Sporting Events for Registration
</div>
<div class="total-upcomming-event col-md-12 col-sm-12 col-xs-12">
<?php
// Fetching Upcoming events user has NOT signed up for (all-events.php line 69 - Updated 6/25/2021)
$isactive=1;
$sql = "SELECT
EventName,
EventLocation,
EventStartDate,
EventEndDate,
EventOpenDate,
EventCloseDate,
EventImage,
id
FROM tblevents
WHERE NOT EXISTS (SELECT
tblbookings.EventId,
tblbookings.UserId
FROM tblbookings
WHERE tblbookings.EventId = tblevents.id
AND tblbookings.UserId = $_SESSION[usrid])
AND IsActive=:isactive
ORDER BY EventOpenDate DESC";
$query = $dbh -> prepare($sql);
$query->bindParam(':isactive',$isactive,PDO::PARAM_STR);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $row)
{
?>
<div class="single-upcomming shadow-box">
<div class="col-md-4 hidden-sm col-xs-12">
<div class="sue-pic">
<img src="admin/eventimages/<?php echo htmlentities($row->EventImage);?>" alt="<?php echo htmlentities($row->EventName);?>" style="border:#000 1px solid">
</div>
<div class="sue-date-time text-center">
<span><?php echo htmlentities($row->EventStartDate);?></span>To
<span><?php echo htmlentities($row->EventEndDate);?></span>
</div>
</div>
<div class="col-md-3 col-sm-5 col-xs-12">
<div class="uc-event-title">
<div class="uc-icon"><i class="zmdi zmdi-globe-alt"></i></div>
<?php echo htmlentities($row->EventName);?><br>
<?php if($row > 1) echo ('Pending'); else echo htmlentities($row->BookingStatus);?>
</div>
</div>
<div class="col-md-2 col-sm-3 col-xs-12">
<div class="venu-no">
<p>Location : <?php echo htmlentities($row->EventLocation);?></p>
</div>
</div>
<?php
if (($currentDate >= $EventOpenDate) && ($EventCloseDate <= $currentDate)){?>
<div class="col-md-3 col-sm-4 col-xs-12">
<div class="upcomming-ticket text-center">
Registration
</div>
</div>
<?php }else{ ?>
<div class="col-md-3 col-sm-4 col-xs-12"><?php $eod; ?>
<div class="upcomming-ticket text-center">
<a class="btn-def bnt-2 small">Registration not Open</a>
</div>
</div>
<?php } ?>
</div>
<?php } } else { ?>
<p>No Record Found - (Make sure you are logged in to see the events)</p>
<?php } ?>
<hr />
</div>
</div>
</div>
</div>
'''
I have table "POST_DATA" and consists of total (13) fields. like userID, user_name,pass, cam_name,cam_model etc.. whenever a user registers on my website some fields get updated like (userid,user_name,pass) and other fields are empty.
But the problem is when I retrieve data from another PHP file using rowcount() on specific columns it returns "1" every time, I want to "0" if no data found on that specific fields like(cam_img,cam_name,cam_model etc..) still it not get updated.
what is the problem...
here is my code:
$stmt = $index_home->getDetails();
if($stmt->rowCount() > 0)
{
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
extract($row);
?>
<div class="row">
<div class="span9" style="float:right;">
<ul class="thumbnails list row" style="display:block;" >
<li>
<div class="thumbnail">
<div class="row">
<div class="span3"> <span class="sale tooltip-test"> <i class="icon-gift font24"></i> <br>
New</span> <img alt="" src="user_images/<?php echo $row['cam_img']; ?>">
</div>
<div class="span6"> <span class="prdocutname" style="font-size:20px;" ><?php echo ucfirst($cam_name) ." " .$cam_model?></span></div>
<div class="span6"> <span class="prdocutname" ><?php echo "Rent: " . $cam_rent . "/- (per day)"?></span></div>
<div class="span6"> <span class="prdocutname" ><?php echo "Mobile: " . $mobile ?></span></div>
<div class="span6">
<button data-original-title="Cart" class="btn btn-orange tooltip-test"> <i class="icon-shopping-cart icon-white"></i> </button>
<button data-original-title="Wishlist" class="btn btn-orange btn-small tooltip-test"> <i class="icon-heart icon-white"></i> </button>
<button data-original-title="Compare" class="btn btn-orange btn-small tooltip-test"> <i class="icon-refresh icon-white"></i> </button>
</div>
Detail view </div>
</div>
</div>
</li>
</ul>
</div>
<?php
}
}
else
{
?>
<div class="col-xs-12">
<div class="alert alert-warning">
<span class="glyphicon glyphicon-info-sign"></span> No Data Found ...
</div>
</div>
<?php
}
?>
And getDetails() implementation in USER class
public function getDetails()
{
try
{
$stmt = $this->conn->prepare('SELECT userID, user_name, cam_name, cam_model, cam_rent, cam_img, mobile FROM post_data ORDER BY userID DESC');
$stmt->execute();
return $stmt;
}
catch(PDOException $ex)
{
echo $ex->getMessage();
}
}
I want to restrict rowCount() to return "1" if no data found in that particular columns.
I have a question:
In PHP, HTML and MySQL I have made an overview of products (data from database)
Now each product in this list has a more info button. I want, when I click more info, that a new page is opened and that page should show more info about that product.
How do I make it work that it only shows the info of that particular product?
This is the current code of the table with the overview:
<div class="col-xs-2">
</div>
<div class="col-xs-4">
<h4 class="product-name"><strong> Producten</strong></h4><h4><small></small></h4>
</div>
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<h6><strong>Datum binnenkomst</strong></h6>
</div>
<div class="col-xs-4">
<h6><strong>Datum uitgave</strong></h6>
</div>
<div class="col-xs-2">
</div>
</div>
</div>
<hr>
<?php
include("connection.php");
$sql = "SELECT * FROM bedrijven";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo'
<div class="row">
<div class="col-xs-2"><img class="img-responsive" style="max-height:80px;" src="' . $row["KVK"] . '">
</div>
<div class="col-xs-4">
<h4 class="product-name"><strong> '. $row["Bedrijfsnaam"] .' </strong></h4><h4><small>'. $row["Klantnummer"] .'</small></h4>
</div>
<div class="col-xs-6">
<div class="col-xs-6 text-right">
<h6><strong>'. $row["BStraatnaam"] .'</strong></h6>
</div>
<div class="col-xs-4">
<h6><strong>'. $row["BHuisnummer"] .'</strong></h6>
</div>
<div class="col-xs-2">
<a href="Moreinfo.php"> <button type="button" class="btn btn-link btn-xs">
More info
</button></a>
</div>
</div>
</div>
<hr>';
}
} else {
echo "0 results";
}
$conn->close();?>
I hope someone would help me.
It would be nice to learn more and new things;)
If you want to split up results only print out what you want to show. You can do selective queries with LIMIT (for a range) or just make sure you only get one result usually done by using a unique identifier (an auto-incremented ID field) and WHERE id = 1.
And in PHP we can use $_GET['page'], to get the page parameter from an url like:
domain.com/somepage?page=2
However remember that this is easily edited by the end user in the location bar and thus should be properly handled in PHP before using it in a SQL query to avoid SQL injection. It be checking with PHP's is_number or using something like prepared statements
I have this carousel that I want to make dynamic. To operate, the carousel must begin with a class
<div class="item active">
and must stay out of the while loop. After the fourth record extract, the class must become simply
<div class="item">
In summary:
0 to 4 -> <div class="item active">
5 to 8 --><div class="item">
9 to 12 --> <div class="item"> ....so on
How do I count the records extracted?
Thanks
<?php
$banner = "SELECT * FROM tbl_banner";
$result_b = dbQuery($banner);
// here --> <div class="item active"> or <div class="item">
while($row_b = dbFetchAssoc($result_b)) {
extract($row_b);
?>
<div class="col-md-3">
<div class="w-box inverse">
<div class="figure">
<img alt="" src="banner/<?php echo $img; ?>" class="img-responsive">
<div class="figcaption bg-2"></div>
<div class="figcaption-btn">
<i class="fa fa-plus-circle"></i> Zoom
<i class="fa fa-link"></i> View
</div>
</div>
<div class="row">
<div class="col-xs-9">
<h2><?php echo $img_title; ?></h2>
<small><?php echo $img_desc; ?></small>
</div>
</div>
</div>
</div>
<?php
}
?>
You can use num_rows to see how many rows were returned. Unfortunately from your question I can't tell whether you're using MySQL, MySQLi or PDO as it seems you pass all your queries into a class.
For MySQLi use the following:
$num = $result_b->num_rows;
SELECT COUNT(*) AS cnt FROM tbl_banner
OR
count( $res ); # in php
Also see: Which is fastest? SELECT SQL_CALC_FOUND_ROWS FROM `table`, or SELECT COUNT(*)
I don't understand....
I would like a result like this, explained in this way:
$query ="SELECT .....
<div class="row">
<div class="item active">
while {
<div1>...</div>
<div2>...</div>
<div3>...</div>
<div4>...</div>
} //end while
</div>
</div>
<div class="row">
<div class="item">
while {
<div4>...</div>
<div6>...</div>
<div7>...</div>
<div8>...</div>
} //end while
etc etc
I am trying to build an if statement that will find a boolean value inside an array that was built using an inner join and mysqli_fetch_array inside a while loop, if that value is found display a message, if that value is not found it will display another message. The value I am searching for is 1.
It keeps either displaying 1 alert or two alerts stacked on top of each other, what am I doing wrong here?
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query6 = "SELECT user_register.lawyer_client
FROM `user_register` INNER JOIN `case_relationship`
ON user_register.user_id=case_relationship.user_id
WHERE case_relationship.case_id = '$thecaseid'";
$addclient = mysqli_query($dbc, $query6);
<?php
while ($row6 = mysqli_fetch_array($addclient)) {
if (in_array("2", $row6)) {
?>
<div class="container add_client_alert alert">
<div class="col-md-10 col-md-offset-1">
<a href="new_client.php" class="client_alert">
<div class="" style="text-align:center;">
<span class="glyphicon glyphicon-plus"></span>
we
<span class="glyphicon glyphicon-plus"></span>
</div>
</a>
</div>
</div>
<?php
}
else {
?>
<div class="container add_client_alert alert">
<div class="col-md-10 col-md-offset-1">
<a href="new_client.php" class="client_alert">
<div class="" style="text-align:center;">
<span class="glyphicon glyphicon-plus"></span>
Looks Like Your Client Can't Access This, Click Here To Experience True Client Control
<span class="glyphicon glyphicon-plus"></span>
</div>
</a>
</div>
</div>
<?php
}
};
?>