I want to make some kind of booking system. I am displaying all data about cars from the database with buttons(which is a link that directs to the booking page) in "boxes", each box is for one car. I want to get id of the car for which the user pressed the button in box where the car is.
Here is my code
<!-- Fetching data from rows -->
<?php
while($rows = $result->fetch_assoc())
{
?>
<div class="car_box">
<div class="car_title">
<p><b><?php echo $rows['Brand'],' ', $rows['Model'];?></b></p>
</div>
<div class="car_description">
<div class="car_details">
<!-- ENGINE CAPACITY -->
<p>
<b>Engine capacity: </b> <?php echo $rows['Engine_capacity']; ?> cm3
</p>
(...)
<!-- BOOKING -->
<div class="booking">
Book now
</div>
</div>
You could try adding a parameter to your link.
Book now
and retrieve it in your Bookings.php by using $_GET['id'].
Currently when using the below code, I get website that looks like this:
Image here (Had to paint out some info due to GDPR)
This is the code used:
<div class="page group">
<div class="section">
<div class="col span_1_of_3">
<div id="outer_wrapper">
<div id="inner_wrapper">
<?php
$query = "SELECT * FROM sales WHERE ident ='".$currentName."' AND status ='Venter' ORDER BY STR_TO_DATE(date, '%d.%m.%Y') DESC";
if ($result = $mysqli->query($query)) {
$num_rows = 0;
while ($row = $result->fetch_assoc()) {
$num_rows++;
if ($num_rows > 0) {
echo '<div class="box">';
echo '<div class="Nwrapper">';
echo '<div id="NformContent">';
echo
"<tr><br>
<td><b>{$row['date']}</b></td><br>
<td> {$row['name']} </td> <b>/</b>
<td>{$row['gsm']} </td><br>
<td> {$row['email']} </td><br><br>
<td> <b>Info</b> <br> {$row['pp']} </td><br>
<td>Portering: {$row['transfer']}</td><br>
<td><a href='delete.php?id={$row['id']};' class='aRS'>Oppdater status</a><a onClick=\"javascript: return confirm('Ønsker du å angre salget?');\" href='delete.php?id={$row['id']};' class='aR'>Slett salg</a></td><br><br>
</tr>";
echo '</div>';
echo '</div>';
echo '</div>';
} else {
echo "No appointments";
break;
}
}
/*freeresultset*/
$result->free();
}
?>
</div> <!-- inner_wrapper -->
</div> <!-- outer_wrapper -->
</div> <!-- col span_1_of_3 -->
</div> <!-- section -->
</div> <!-- page group -->
<div class="lineWrapper"></div><br>
What I want to do is to hide the top horizontal boxes if the query return no value(0 number of rows(?) num_rows). I have tried doing it like this, and put my whole code inside the PHP query:
<?php
$query = "SELECT * FROM sales WHERE ident ='".$currentName."' AND status ='Venter' ORDER BY STR_TO_DATE(date, '%d.%m.%Y') DESC";
if ($result = $mysqli->query($query)) {
$num_rows = 0;
while ($row = $result->fetch_assoc()) {
$num_rows++;
if ($num_rows > 0) {
?>
<div class="page group">
<div class="section">
<div class="col span_1_of_3">
<div id="outer_wrapper">
<div id="inner_wrapper">
<?php
echo '<div class="box">';
echo '<div class="Nwrapper">';
echo '<div id="NformContent">';
echo
"<tr><br>
<td><b>{$row['date']}</b></td><br>
<td> {$row['name']} </td> <b>/</b>
<td>{$row['gsm']} </td><br>
<td> {$row['email']} </td><br><br>
<td> <b>Info</b> <br> {$row['pp']} </td><br>
<td>Portering: {$row['transfer']}</td><br>
<td><a href='delete.php?id={$row['id']};' class='aRS'>Oppdater status</a><a onClick=\"javascript: return confirm('Ønsker du å angre salget?');\" href='delete.php?id={$row['id']};' class='aR'>Slett salg</a></td><br><br>
</tr>";
echo '</div>';
echo '</div>';
echo '</div>';
?>
</div> <!-- inner_wrapper -->
</div> <!-- outer_wrapper -->
</div> <!-- col span_1_of_3 -->
</div> <!-- section -->
</div> <!-- page group -->
<div class="lineWrapper"></div><br>
<?php
} else {
break;
}
}
/*freeresultset*/
$result->free();
}
?>
When I save, it all looks good, the top boxes are all gone, but now if the number of rows is higher then 0, and there are some value to show, it looks like this(each displays in a vertical order):
Image here
Any suggestions on how I can get this to work like I want it to?
There is while loop. Inside loop you open table row put chunk as $num_rows and close row, than goes another chunk in it's own row.
While loop works as loop - chunk after chunk - end of loop;
I'm not sure - you want them all horizontally? In one row?
Actually, you don't need any table for this, this isn't tabular content, more appropriate would be section or div or something similar.
Whatever you pick, for now it would be a 'box';
this is how it should go:
open a box,
query, fetch - if is empty do nothing {}
if isn't empty - write down chunk after chunk,
close box;
With no chunks it will be empty box - you can hide it with .css (or not...)
Other solution is to assign all chunks to variable $x.= chunk
and then - if (x) is not empty - open a box - write it (x) down - close box;
If the output (x) is big, may cause problem.
Next one solution - workaround :
$box = '<div>'; // echoing $box will open a box
query, fetch, if empty do nothing;
if not empty output - echo $box write first chunk, unset $box - following chunks won't echoing $box,
after loop, if $num_rows > 0 close box (if 0 rows there is no open box)
some explenation
http://koopjesidee.nl/images/6755185029021696.jpg
in my database i have a column named new_label
when its a new product its set as new
when no new product the colums is empty
i want the class="main-label new-label" to be disabled when there nothing in that column
now as you see from the image, there is always a orange cirkel (as set in class main-label) even when column is empty
This is my code
<!-- select products from database -->
<?php
$query = "select * from contentwhere cat = 4 order by rand() LIMIT 18";
$result = $db->query($query);
while($row = $result->fetch_array())
{
$url =detail($row);
<!-- content on main page -->
echo '
<div class="item">
<div class="product-item">
<div class="main-label new-label"><span>'.$row['new_label'].'</span></div>
<div class="product-image"><img src="'.$row['picture_big'].'" alt="'.$row['name'].'"></div>
<div class="product-item-details">
<div class="product-item-name"> '.$row['name'].' </div>
<div class="price-box"> <span class="price">€'.$row['price'].'</span> <del class="price old-price">'.$row['from_price'].'</del> </div>
</div>
</div>
</div>';
}?>
I want add if isset like this so when there is no text in class=new-label class main-label new-label is disabled column in my database is new_label
<div class="item">
<div class="product-item">
<!-- ISSUE -->
if (isset($_row['new_label']!='')) {
<div class="main-label new-label"><span>'.$row['new_label'].'</span></div>;
} else {
<div class="main-label new-label"><span></span></div>;
}
<!-- HTTP ERROR 500 -->
<div class="product-image"><img src="'.$row['picture_big'].'" alt="'.$row['name'].'">
You cannot use isset() on the result of an expression, it can only be a variable. In fact, it will result in a fatal error if you try (which is probably why you received a 500 server error).
So you can probably change this line:
if (isset($_row['new_label']!='')) {
To this:
if (isset($_row['new_label'])) {
isset() returns a boolean anyway, so it doesn't make sense to compare it to a string.
Read more: http://php.net/manual/en/function.isset.php
SOLVED MYSELF GUYS
'.$row['new_label'].'';} ?>
thanks anyway
I am trying to execute the following MySQL query:
SELECT event.event_id, venue.venue_name, venue.alt_venue_name, venue.venue_address1, venue.cross_street, dictionary_city.city_name, venue.zip, dictionary_filter.filter_name, venue.capacity, event.start_date, event.end_date, dictionary_barType.is_ob, dictionary_barType.barType_name, event.barType_time, event.is_food, event.food_type, event.food_time, dictionary_age.age_name, dictionary_age.age_description, event.ticketCo_id, event.ticket_locator, event.ticket_left, event_description.description, event_highlight.highlight, event.event_tag, event.image_flyer, event.image_flyer_310x425, event.image_2, event.image_2_310x208, event.image_3, event.image_3_310x208
FROM event
LEFT JOIN venue
ON venue.venue_id=event.venue_id
LEFT JOIN dictionary_city
ON venue.city_id=dictionary_city.city_id
LEFT JOIN dictionary_filter
ON venue.venueType_id=dictionary_filter.filter_id
LEFT JOIN dictionary_barType
ON event.barType_id=dictionary_barType.barType_id
LEFT JOIN dictionary_age
ON event.event_age_id=dictionary_age.age_id
LEFT JOIN event_highlight
ON event_highlight.event_id=event.event_id
LEFT JOIN event_description
ON event_description.event_id=event.event_id
WHERE event.event_id="".$event_id."";
When I run the query in PhP Admin it works fine, but when I add the code to my site, I get the following error
"Warning: mysql_fetch_array() expects parameter 1 to be resource,
boolean given in
/home/nye/public_html/theballdrop.com/templates/template.event.php on
line 29 - See more at:
http://theballdrop.com/new-years-eve-madame-tussauds/#sthash.880jgbaa.dpuf"
The query it refers to is "if ($row = mysql_fetch_array($result)){"
I am not sure where to go from here. This is supposed to display information from multiple tables on a single page. $event_id is the variable and a specific event ID would determine the info to display for that specific event page.
please help.
===========================
Here is the entire code for the page:
<?php
// FUNCTION: CONVERT DATE
include (PATH . DIR_INCLUDE . "convert-time.php");
// CONNECT TO NYE DATABASE
include (PATH . DIR_TEMPLATE . "mysql-connect.php");
$sql = "SELECT event.event_id, venue.venue_name, venue.alt_venue_name, venue.venue_address1, venue.cross_street, dictionary_city.city_name, venue.zip, dictionary_filter.filter_name, venue.capacity, event.start_date, event.end_date, dictionary_barType.is_ob, dictionary_barType.barType_name, event.barType_time, event.is_food, event.food_type, event.food_time, dictionary_age.age_name, dictionary_age.age_description, event.ticketCo_id, event.ticket_locator, event.ticket_left, event_description.description, event_highlight.highlight, event.event_tag, event.image_flyer, event.image_flyer_310x425, event.image_2, event.image_2_310x208, event.image_3, event.image_3_310x208 FROM nye_newyears.event LEFT JOIN venue ON venue.venue_id=event.venue_id LEFT JOIN dictionary_city ON venue.city_id=dictionary_city.city_id LEFT JOIN dictionary_filter ON venue.venueType_id=dictionary_filter.filter_id LEFT JOIN dictionary_barType ON event.barType_id=dictionary_barType.barType_id LEFT JOIN dictionary_age ON event.event_age_id=dictionary_age.age_id LEFT JOIN event_highlight ON event_highlight.event_id=event.event_id LEFT JOIN event_description ON event_description.event_id=event.event_id WHERE event.event_id=".$event_id."";
$result = mysql_query($sql, $con);
// START MYSQL QUERY
if ($row = mysql_fetch_array($result)){
// VENUE INFORMATION
$venueName = $row['venue_name']; // OFFICIAL VENUE NAME
$venueName2 = $row['alt_venue_name']; // NAME YOU WANT TO DISPLAY AT TOP OF EVENT PAGE
$venueAddress = $row['venue_address1']; // ADDRESS OF VENUE
$venueCrossStreet = $row['cross_street']; // CROSS STREETS
$venueCity = $row['city_name']; // VENUE CITY
$venueState = $row['state_abb']; // VENUE STATE
$venueZip = $row['zip']; // VENUE ZIP
$venueType = $row['filter_name']; // TYPE OF VENUE
$venueCapacity = $row['capacity']; // CAPACITY OF VENUE
// EVENT INFORMATION
$start = $row['start_date'];
$startDate = convertDate ($start); // START DATE OF EVENT
$startTime = convertTime ($start); // START TIME OF EVENT
$end = $row['end_date'];
$endDate = convertDate ($end); // END DATE OF EVENT
$endTime = convertTime ($end); // END TIME OF EVENT
$ob = $row['is_ob']; // IS THERE OPEN BAR? "YES" OR "NO"
$obType = $row['barType_name']; // TYPE OF OPEN BAR
$obTimes = $row['barType_time']; // OPEN BAR TIMES (START AND END)
$food = $row['is_food']; // IS THERE FOOD? "YES" OR "NO"
$foodType = $row['food_type']; // TYPE OF FOOD SERVED
$foodTimes = $row['food_time']; // TIMES FOOD BEING SERVED (START AND END)
$eventAge = $row['age_name']; // AGE RESTRICTION (IF ANY)
$eventAge_descrip = $row['age_description'];
$ticketCompany = $row['ticketCo_id'];
$ticketID = $row['ticket_locator']; // WIDGET ID
$ticketsLeft = $row['ticket_left']; // TOTAL TICKETS LEFT
$eventDescription = $row['description']; // EVENT DESCRIPTION
$eventHighlight = $row['highlight']; // EVENT HIGHLIGHT
$eventTag = $row['event_tag']; // EVENT LISTING DESCRIPTION
// EVENT IMAGES
$flyer = $row['image_flyer']; // FULL SIZE EVENT FLYER IMAGE
$flyer_310x425 = $row['image_flyer_310x425']; // FLYER IMAGE - 310x425
$image2 = $row['image_2']; // FULL SIZE IMAGE 2
$image2_310x208 = $row['image_2_310x208']; // IMAGE 2 - 310x208
$image3 = $row['image_3']; // FULL SIZE IMAGE 3
$image3_310x208 = $row['image_3_310x208']; // IMAGE 3 - 310x208
}
// VENUE MAP
$venueMap ="$venueAddress+$venueCity+$venueState+$venueZip" ;
// CLOSE DATABASE
mysql_close($con);
// INCLUDE GLOBAL HEADER
include (PATH . DIR_INCLUDE . "site-header.php");
?>
<body>
<?php include_once(PATH . "analyticstracking.php") ?>
<div id="wrapper">
<?php include (PATH . DIR_INCLUDE . "header.php"); ?>
<div class="row">
<div class="middle">
<div class="wrapper event-header">
<div class="left twoThird slogan"> <br />
<h1>
<?=$venueName2?>
</h1>
<h5>
<?=$eventTag?>
</h5>
</div>
<div class="left oneThird last"> <a class="buy-now" href="#tickets" ><span>Buy Now</span></a> Ask a Question </div>
<!-- End: button -->
</div>
</div>
<!--End .middle -->
<div class="wrapper">
<div class="twoThird left columns">
<div class="roundCorner">
<div class="widget data flier-section">
<div class="flier left"> <img src="<?=DIR_IMAGES?><?=$flyer_310x425?>" alt="<?=$venueName2?> New Years Eve 2014" width="310" height="425" /> </div>
<!-- End # left-->
<div class="photos right"> <img src="<?=DIR_IMAGES?><?=$image2_310x208?>" alt="<?=$venueName?> Times Square New Years Eve 2014" /> <img src="<?=DIR_IMAGES?><?=$image3_310x208?>" alt="<?=$venueName?> Times Square New Years Eve" /> </div>
<!-- End # right slider-->
</div>
<!-- End # widget-->
<div class="center detail">
<div class="widget lightgray-base">
<h3 class="widget-heading">Why We Recommend</h3>
<ul class="blist">
<?=$eventHighlight?>
</ul>
</div>
<div class="widget">
<h3 class="headingbar">Overview</h3>
<?=$eventDescription?>
<p><strong>About your Tickets: </strong> (1) Show up early and help reduce the wait time, (2) Make sure to have your physical ticket on hand because you will need to show it to NYPD and security upon request, (3) You accept the risks and agree to adhere to the NYPD rules and regulations for the evening, (4) If you select shipping as your delivery method, tickets will not be sent out until December, (5) A LIVE VIEW of The Ball Drop is not guaranteed. Large crowds should be expected</p>
</div>
</div>
</div>
<!-- End of main-->
<div class="roundCorner"> <a name="tickets" ></a>
<h3 class="widget-heading">Purchase Tickets
<div class="info">Have a Question? Call 212.201.0735 or email info#balldrop.com </div>
</h3>
<div class="widget data">
<p>
<?php
if ($ticketCompany == 1){
// START: CRAVE TICKETS WIDGET -->
echo "<iframe scrolling='auto' frameborder='0' width='99.5%' height='600' src='http://cravetickets.com/widgets/iframe/qU4owWdNmYt/".$ticketID."' ></iframe>";
// END: CRAVE TICKETS WIDGET -->
} else if ($ticketCompany == 2){
// START: LAUGHSTUB TICKET WIDGET -->
echo "<script type='text/javascript' src='http://www.laughstub.com/embed/cart/index.cfm?showTimingID=".$ticketID."&bgcolor=E53D23&fontcolor=ffffff&&brand=ticketmob&displayTitle=no&affiliate=1087&checkout=pmtix'></script>";
// END: LAUGHSTUB TICKET WIDGET -->
}
?>
</p>
<p><strong> Price increase warning:</strong> New Year's Eve ticket prices often go up significantly (100% +) the closer you get to New Years Eve. Also note that many NYE Events will sell out well in advance of New Years Eve. </p>
</div>
</div>
</div>
<!-- End # twoThird-->
<div class="oneThird sidebar last">
<div class="roundCorner lightgray-base">
<h3 class="widget-heading">What to know</h3>
<div class="box data">
<h4>Share This Event</h4>
<p> <span class='st_facebook_large' displayText='Facebook'></span> <span class='st_twitter_large' displayText='Tweet'></span> <span class='st_plusone_large' displayText='Google +1'></span> <span class='st_linkedin_large' displayText='LinkedIn'></span> <span class='st_pinterest_large' displayText='Pinterest'></span> <span class='st_email_large' displayText='Email'></span> </p>
<ul class="know-list">
<li>
<h5>START TIME</h5>
<h4>
<?=$startDate?>
at
<?=$startTime?>
</h4>
</li>
<li>
<h5>END TIME</h5>
<h4>
<?=$endDate?>
at
<?=$endTime?>
</h4>
</li>
<li>
<h5>ADDRESS</h5>
<h4>
<?=$venueAddress?>
<br>
<?=$venueCrossStreet?>
</h4>
</li>
<li>
<h5>VENUE TYPE</h5>
<h4>
<?=$venueType?>
</h4>
</li>
<li>
<h5>AGE REQUIREMENT</h5>
<h4>
<?=$eventAge?>
<br />
<?=$eventAge_descrip?>
</h4>
</li>
<li>
<h5>CAPACITY</h5>
<h4>
<?=$venueCapacity?>
</h4>
</li>
<li>
<h5>OPEN BAR</h5>
<h4>
<?=$ob?>
|
<?=$obType?>
<br />
from
<?=$obTimes?>
</h4>
</li>
<li>
<h5>FOOD SERVED</h5>
<h4>
<?=$food?>
|
<?=$foodType?>
<br />
from
<?=$foodTimes?>
</h4>
</li>
</ul>
</div>
</div>
<!-- End of roundCorner -->
<div class="roundCorner lightgray-base">
<h3 class="widget-heading">Map</h3>
<div class="box"> <img src="http://maps.googleapis.com/maps/api/staticmap?center=<?=$venueMap?>&zoom=16&size=295x245&markers=size:mid%7Ccolor:red%7C<?=$venueMap?>&sensor=false">
<div class="address"> <br />
<h3>
<?=$venueName?>
</h3>
<h5>
<?=$venueAddress?>
<br />
<?=$venueCrossStreet?>
<br />
<?=$venueCity?>
,
<?=$venueState?>
<?=$venueZip?>
</h5>
</div>
</div>
</div>
<!-- End of roundCorner -->
<div class="banner-300"> <img class="fullWidth" src="<?=DIR_IMAGES?>banner-300.jpg"> </div>
<!-- End # Banner-->
</div>
<!-- End of onethird-->
</div>
<!-- End # wrapper-->
<div id="footer-top">
<!-- START: SIMILAR PARTIES -->
<div class="listing-wrapper">
<h2 class="subHeading">We Recommend More NYE Parties <strong>›</strong> </h2>
<ul class="columns">
<?php include (PATH . DIR_INCLUDE . "similar-parties.php"); ?>
</ul>
</div>
<!-- END: SIMILAR PARTIES -->
</div>
<!-- End # footer-top -->
<?php include (PATH . DIR_INCLUDE . "footer.php"); ?>
</div>
<!-- End # row-->
</div>
<!-- End # wrapper-->
</body>
</html>
Add database selection to your connect script, like so:
<?php
$hostname = "localhost";
$username = "{username]";
$password = "[pass]";
$dbname = "nye_newyears";
$con = mysql_connect("$hostname", "$username", "$password");
if (!$con) {
die('Could not connect: ' . mysql_error());
}
if(!mysql_select_db($dbname)) {
die('Could not find or access database ' . $dbname);
}
?>
event is a keyword in mysql. so wrap it inside quotes (`) and try.
echo your $sql in browser copy it and paste it in phpmyadmin and execute, you will get the particular error if any.
At first, check your MySql Table name in server. Sometimes some hosts add a prefix on table name.
You should check $result object first like
if(!$result){
exit(mysql_error());
}else{
if ($row = mysql_fetch_array($result)){
// ....
// ...
}
}
Thank you all for your help. Knittl you were RIGHT!!!
I added the following code to mysql-connect file:
if(!mysql_select_db($dbname)) {
die('Could not find database ' . $dbname);
}
everything works now.
Thank you so much.
I've spent all afternoon trying to figure this out with no success, I wondered if anyone could help?
I have a dropdown menu on my site which is working perfectly. I've duplicated one of the menu options and after I did this it still worked fine, it had a php / SQL query inside but once duplicate it still did what it should.
What I did then was change the SQL and although the query is correct (checked in myphpadmin) all of my results appear out side of the div tag for some reason, its as if the div tag is closing itself.
Here's my code:
'
<li>Brand<!-- Begin 4 columns Item -->
<div class="dropdown_5columns"> <!-- Begin 4 columns container -->
<div id="top"></div>
<div class="col_4">
<h2 style="width:98%;">Choose from the following Brands:</h2>
</div>
<div class="col_1" style="width:190px;">
<?php
$databrand = mysql_query("SELECT DISTINCT(brand), COUNT(*) as Total from `pt_products` where `brand` <>'' group by `brand` limit 5")
or die(mysql_error());
while($infobrand = mysqlfetch_array( $databrand ))
{
print "<li style='width:190px;'>";
print "<a href='/brand'>".$infobrand['brand']." (".$infobrand['Total'].")</a></li>";
}
print "</div>";
?>
<div id="bottom"></div>
</div><!-- End 4 columns container -->
</li>`
I can't seem to figure this one out. All I did was change the SQL Query.
I've tried deleting the duplicate content and starting again, but get the same outcome.
Any help would really be appreciated.
here's the view source data on of my site:
<li>Brand<!-- Begin 4 columns Item -->
<div class="dropdown_5columns" style="position:absolute;"> <!-- Begin 4 columns container -->
<div id="top"></div>
<div class="col_4">
<h2 style="width:98%;">Choose from the following Brands:</h2>
</div>
<div class="col_1" style="width:190px;">
<li style='width:190px;'><a href='/brand'>Balterio (50)</a></li>
<li style='width:190px;'><a href='/brand'>Dale Hardware (24)</a></li>
<li style='width:190px;'><a href='/brand'>EuroSpec Hardware (2)</a></li>
<li style='width:190px;'><a href='/brand'>Everbuild (35)</a></li>
<li style='width:190px;'><a href='/brand'>Jeld Wen (4)</a></li>
</div>
<div id="bottom"></div>
</div><!-- End 4 columns container -->
</li>
You can't tell from below but the first <li style='width:190px;'> and the </div> after the li list are higlighted in red (error) and also the last </li>
Thanks in advance for your help.
You're using <li>, which should be inside a <ul> or <ol>, which you can then put inside a <div> if you need. Alternatively, you can change the <li> to something else, such as another <div>.
Your problem is like when you put a <p> directly inside a table without nesting in <tr><td>.