I would like to display three images from the database in one row. At the moment, all the images are in a vertical line and I do not know how to fix it. Any help would be appreciated. I am only learning PHP, have checked other questions and they have been no help.
I have tried using Bootstrap however that has not worked either. The way I have it does display 3 in a row however, shoes the same product in each row and only if I have the query $show_men="SELECT model, id, price,image FROM products WHERE id='id' "
<div class="col-xs-12 col-sm-4">
<!--selecting products from database and displaying. when user clicks on more info button, information is stored in array and displayed on item.php-->
<?php
include 'mysql.php';
$show_men="SELECT model, id, price,image FROM products WHERE cat='men' ";
$query_men=mysqli_query($conn,$show_men);
while($row=mysqli_fetch_array($query_men,MYSQLI_ASSOC)){
echo '<br><br><table class="table"><tbody>
<tr>
<div><center><img class="img-responsive" src="../images/'.$row['image'].'" width="200" height="200"></center><br>
<center><strong>'.$row['model'].'</strong><br><br><strong>Price:£ '.$row['price'].'</strong><br><br>
More Info<br><br><strong></center></div><hr>
</tr>
</tbody>
</table>';
}?>
</div>
You need to iterate the column instead of the table..
<div class="row">
<?php
include 'mysql.php';
$show_men="SELECT model, id, price,image FROM products WHERE cat='men' ";
$query_men=mysqli_query($conn,$show_men);
while($row=mysqli_fetch_array($query_men,MYSQLI_ASSOC)){
echo '<div class="col-xs-12 col-sm-4"><br><br><table class="table"><tbody>
<tr>
<div><center><img class="img-responsive" src="../images/'.$row['image'].'" width="200" height="200"></center><br>
<center><strong>'.$row['model'].'</strong><br><br><strong>Price:£ '.$row['price'].'</strong><br><br>
More Info<br><br><strong></center></div><hr>
</tr>
</tbody>
</table></div>';
}
?>
</div>
Related
trying to make this code render images in rows all to no avail. I initially tried to use boostrap's row and column classes and it didn't work. Then I tried the table element still no result. could you spot the problrm?
// Get images from the database
$query = $db->query("SELECT * FROM images ORDER BY id DESC LIMIT 5");
if($query->num_rows > 0){
while($row = $query->fetch_assoc()){
$imageURL = 'uploads/'.$row["file_name"];
?>
<!-- begin post -->
<div class="container recent-posts">
<table>
<tr>
<td class="card" style="width: 18rem;">
<img src="<?php echo $imageURL; ?>" alt="" />
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</td>
<?php }
}
else{ ?>
<p>No image(s) found...</p>
<?php } ?>
</tr>
</table>
</div>
I've swapped in your db code for an array and foreach, but it is in the same spirit.
Use indentation, to help you get your loops and tags in order.
<?php
$images = [
['file_name' => 'foo.jpg'],
['file_name' => 'bar.jpg'],
['file_name' => 'baz.jpg'],
]
?>
<html>
<?php if(!empty($images)) { ?>
<table>
<tr>
<?php foreach($images as $row) { $imageURL = 'uploads/'.$row["file_name"]; ?>
<td class="card" style="width: 18rem;">
<img src="<?php echo $imageURL; ?>" alt="" />
<div class="card-body">
<h5 class="card-title">Card title</h5>
<p class="card-text">Some quick example text to build on the card title and make up the bulk of the card's content.</p>
Go somewhere
</div>
</td>
<?php } ?>
</tr>
</table>
<?php } else { ?>
<p>No image(s) found...</p>
<?php } ?>
</html>
As others have said, there isn't anything really to be gained here by using a table.
Does it show you the rest of the html elements or does it show you the message that there is no picture?
Check with the inspect tool what location the src attribute of the img element is.
You can add a backslash in the $imageURL variable
$imageURL = '/uploads/' . $row["file_name"];
Show us the structure and a record of the images table.
Give us more details about what happens when the page is loaded. Like what it loading in your page.
I suggest you ditch the tables and use boostrap instead.
Example here: https://getbootstrap.com/docs/4.0/components/card/
I have a simple ticket sale registration system with 6 types of tickets and 3 different "physical" sales locations. Each order is inserted as a row in the database and stores the amount of each type of ticket along with the sale location, total cost and a datetime timestamp.
I want to display the total amount of each ticket type, that was sold within a given time frame along with the total cost of those tickets. I also want to filter the results based on sale location.
This is my db query:
"SELECT SUM(ticketType1), SUM(ticketType2), SUM(ticketType3),
SUM(ticketType4), SUM(ticketType5), SUM(ticketType6),
SUM(cost), saleLocation
FROM `orders`
WHERE time BETWEEN '2018-07-10 07:00:01'
AND '2018-07-11 07:00:00'"
Then I display it in a HTML table row:
<?php
while ($row = $result->fetch_assoc()) {
if($row["saleLocation"] == 'location1') { ?>
<div class="cell">
<?php echo $row["SUM(ticketType1)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType2)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType3)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType4)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType5)"] ?>
</div>
<div class="cell">
<?php echo $row["SUM(ticketType6)"] ?>
</div>
<div class="cell">
<?php echo number_format($row["SUM(cost)"], 0, "", "."); ?>
</div>
<?php } //end if
} // end while
?>
It works, but I'm trying to use an IF statement inside the WHILE loop to filter the result based on location, but the IF statement doesn't appear to have any effect and instead it displays the results from all 3 locations.
I know I can easily modify the query to achieve this, but I would rather not do that in this specific case.
I'm guessing that the problem still lies within the query, though?
Some help would be greatly appreciated.
I'm working on page which consists from database of products.
On the front page you can see every product but with only limited information.
I would like to create secondary page by clicking on Learn more of a product with all information.
Really something widely used in eshops where there is no need to create new page for every product but rather one template which will get information from PHP.
The problem is that I don't know how is this principle working.
I don't even know how it is called so I can search for some tutorial.
Maybe fetching array through products' ID?
For showing products I use:
`
<?php
$db = new PDO("mysql:host=localhost;dbname=cars", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Query
$cars = $db->prepare("SELECT car_id, name, price, availability, description FROM cars
");
$cars->execute();
$cars = $cars->fetchAll(PDO::FETCH_ASSOC);
?>
`
And then:
<?php foreach($cars as $car): ?>
<td>
<div><img src="<?php echo $car['image'];?>"
</div>
</td>
<td>
<a href="#">
<div id="textTable"><strong><?php echo $car['name'];?></strong></a>
Learn More..
</div>
</td>
<td>
<?php echo $car['availability'];?>
</td>
<td>
<strong><?php echo $car['price'];?>€</strong>
</td>
</tr>
<?php endforeach;?>
You can send you send your product id like this
View
And fetch each record from product id in database with only one php page
This code is for mfetch record in you second page.
$id = $_GET['product_id'];
$cars = $db->prepare("SELECT car_id, name, price, availability, description FROM cars WHERE cae_id='$id'");
$cars->execute();
$cars = $cars->fetchAll(PDO::FETCH_ASSOC);
One possible solution :
Learn More..
(I removed the id="learnMore" because an id must appear only once in an HTML page)
I'm very new to PHP and database queries.
I have a WordPress site with the Genesis framework installed and I'm creating a child theme from it and adding some template pages to insert data from my database. I'm creating a category page and a product page.
I'm having issues on some of the queried data on the category page, if there is anyone out there that can point me in the right direction, I'd be extremely grateful.
I have all the database rows outputting individually in a table format, which is exactly how I want it, but I can't get a heading to output above the displayed products, I've tried lots of solutions but none so far have done the job. Here is my code:
function child_product_data_loop() {
global $wpdb;
$category = $wpdb->get_results("SELECT * FROM product_data WHERE prod_cat_1='Retractable Plastic Pens';");
echo "<main class='content'>
<article class='page type-page status-publish entry' itemscope='' itemtype='http://schema.org/CreativeWork'>
<header class='entry-header'>
<h1 class='entry-title' itemprop='headline'>".$category->prod_cat_1."</h1>
</header>
<div class='entry-content' itemprop='text'>
<p>For more information on any product within our ".$category->prod_cat_1." range please click on "details and prices".</p>";
foreach($category as $product){
echo "<table width='100%' border='0' cellpadding='2' cellspacing='0'>
<tbody>
<tr valign='top'>
<td><h3><a href='' style='color: rgb(51, 102, 153); text-decoration: none;'>".$product->prod_name."</a></h3></td>
<td style='color: #ff0000; text-align: right;'>From: £".$product->prod_price_5."</td>
</tr>
<tr valign='top'>
<td colspan='2'><a href='' style='color: #CC6600; text-decoration: none;'>Click here for details and prices</a></td>
</tr>
<tr align='center' valign='middle'>
<td height='75' colspan='2'><a href='' title='".$product->prod_name."'><img width='100%' height='auto' src='http://thepensite.co.uk/wp-content/uploads/media-clic.jpg' class='prod-image' alt='".$product->prod_name."' srcset='http://thepensite.co.uk/wp-content/uploads/media-clic-300x33.jpg 300w, http://thepensite.co.uk/wp-content/uploads/media-clic.jpg 420w' sizes='(max-width: 420px) 100vw, 420px' /></a></td>
</tr>
</tbody>
</table>";
}
echo "</div>
</article>
</main>";
}
My issue is within these lines of code:
echo "<main class='content'>
<article class='page type-page status-publish entry' itemscope='' itemtype='http://schema.org/CreativeWork'>
<header class='entry-header'>
<h1 class='entry-title' itemprop='headline'>".$category->prod_cat_1."</h1>
</header>
<div class='entry-content' itemprop='text'>
<p>For more information on any product within our ".$category->prod_cat_1." range please click on "details and prices".</p>";
For some reason the category name is not been outputted, as I said before I have tried quite a few solutions I've found but they haven't worked, so I'm obviously doing some thing totally wrong.
Can any of you out there help?
Many thanks in advance.
Use $category[0]->prod_cat_1 you are not accessing the array value correctly. [0] is key here
EDIT:
Do print("<pre>".print_r($category,true)."</pre>"); after your query and look how are you getting the results.
In all likelihood, you are not accessing what you got back from the query properly. I have to guess a bit because you have not posted enough information to be certain.
Suggestion #1:
Add your table definition to the question so I can see what columns you have.
Suggestion #2: dump the data
foreach($category as $product){
var_dump($category); // <--- add this
Edit your question and post the output.
I am assuming that you are looking for html structure that is a table with all your rows inside the table. The way you have made your loop, you will end up with a table for each product.
Is this what you want?
table
product
product
product
This is what your code will produce:
table
product
table
product
table
product
i have bellow code which display 10 items and each item in each of table
<div class="baner_main shadow">
<div id="adds">
<div class="latest_ads">
<table border="0" cellspacing="0" style="width:800px">
<tbody>
<tr class="">
<?php
for($i=;$i<=10;$i++)
{
?>
<td class="even">
<img src="images/photo.gif" alt="" title=""><br>
<h3>Item Name</h3>
<p><strong>Price: 70.00 USD <br> () <br> December 3, 2011</strong></p>
</td>
<?php
}
?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
in 800 width of table it only show 5 items on screen one time.
what i need is
Move the first item and bring the next five items automatically after 10 sec using Jquery.
A small dot under table to move items next and previous with jquery.
this is common in image slide shows but i can't find any idea how to do with table.
if available give me any example link and i will it myself.
Thanks
You can use jQuery cycle plugin http://malsup.com/jquery/cycle/ and check http://malsup.com/jquery/cycle/div.html for grouping set of items together. Most of the examples provided are Div based layouts. However, You can achieve the same effect using TD's as well. Let me know if you still need help