I'm trying to create a system wherein the users can view records in the database, and its corresponding image. My problem is how to present the table in a fashion similar to that of ebay:
Here's my code:
<?php
require_once('header.php');
?>
<?php $list_items = $db->get_results("SELECT * FROM tbl_products"); ?>
<table border="1">
<?php foreach($list_items as $k=>$li){ ?>
<tr>
<td>
<p>
<img src="../img/items/<?php echo $li->str_filename; ?>" width="150px" height="150px">
</p>
<p>
Product Name: <?php echo $li->str_productName; ?>
</p>
<p>
Category: <?php echo $li->str_category; ?>
</p>
<p>
Quantity: <?php echo $li->dbl_qty; ?>
</p>
<p>
Price: <?php echo $li->dbl_price; ?>
</p>
</td>
</tr>
<?php } ?>
</table>
The current code is outputting the records in list view. Wherein, there's only one record per row. What I want is 4-6 records per row. How do I do that?
try this
<table border="1">
<?php
$intMaxColumn=4;
$intCountColumn=1;
foreach($list_items as $k=>$li){
if($intCountColumn==1){
?>
<tr>
<?php
}
?>
<td>
<p>
<img src="../img/items/<?php echo $li->str_filename; ?>" width="150px" height="150px">
</p>
<p>
Product Name: <?php echo $li->str_productName; ?>
</p>
<p>
Category: <?php echo $li->str_category; ?>
</p>
<p>
Quantity: <?php echo $li->dbl_qty; ?>
</p>
<p>
Price: <?php echo $li->dbl_price; ?>
</p>
</td>
<?php
if($intCountColumn==$intMaxColumn){
$intCountColumn=1;
?>
</tr>
<?php
}else{
$intCountColumn++;
}
}
?>
</table>
add CSS to these tables:
float:left;
and it will be the same
and do not include one table, but new table for each item. Try this
<?php
require_once('header.php');
$list_items = $db->get_results("SELECT * FROM tbl_products");
foreach($list_items as $k=>$li){
?>
<table border="1" style="float:left;">
<tr>
<td>
<p>
<img src="../img/items/<?php echo $li->str_filename; ?>" width="150px" height="150px">
</p>
<p>
Product Name: <?php echo $li->str_productName; ?>
</p>
<p>
Category: <?php echo $li->str_category; ?>
</p>
<p>
Quantity: <?php echo $li->dbl_qty; ?>
</p>
<p>
Price: <?php echo $li->dbl_price; ?>
</p>
</td>
</tr>
</table>
<?php } ?>
demo
Related
Just to start off, I am new to php so i might have missed something obvious so please bear with me.
I have hyperlinks (planes, ships trains etc) and when I click the hyperlink "planes" i want all of the planes records to be displayed in a table. When I click a different vehicle i want it to refresh the table with new data.
The problem is, when i click the link "trains" it does not refresh the table and display relevant data, it keeps the same data. How do i tell php when i click the link "planes" i want to display all the records with that productLine.
Thanks for any help
As you can see in the pic, i clicked train but it still displays vintage cars
Here is my code:
<?php
require_once('dbconfig.php');
//get productLine
if (!isset($productLine)) {
$productLine = filter_input(INPUT_GET, 'productLine', FILTER_VALIDATE_INT);
if ($productLine == null || $productLine == FALSE) {
$productLine = 'Trains';
}
}
//get all product lines
$query = 'SELECT * FROM productlines';
$statement = $db->prepare($query);
$statement->execute();
$productLines = $statement->fetchAll();
$statement->closeCursor();
//Get products for product line
$queryProducts = 'SELECT * FROM products WHERE productLine = :productLine ORDER BY productCode';
$statement1 = $db->prepare($queryProducts);
$statement1->bindValue(':productLine', $productLine);
$statement1->execute();
$products = $statement1->fetchAll();
$statement1->closeCursor();
?>
<!DOCTYPE html>
<html>
<head>
<title>Classic Models Online</title>
<link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
<header><h1>ClassicModels Online</h1>
<p>Classic models for all automobile enthusiasts</p>
</header>
<main>
<h1>Classic Models Product List</h1>
<aside>
<!--Display list of product lines-->
<h2>Product Lines</h2>
<nav>
<ul>
<?php foreach ($productLines as $productLine) : ?>
<li>
<a href=".?productLine=<?php echo $productLine['productLine']; ?>">
<?php echo $productLine['productLine']; ?>
</a>
</li>
<?php endforeach; ?>
</ul>
</nav>
</aside>
<br>
<section>
<!--Display a table of products for product line-->
<h2><?php echo $productLine['productLine']; ?></h2>
<table>
<tr>
<th>Code</th>
<th>Name</th>
<th>Scale</th>
<th>Price</th>
<th>Total Sold</th>
<th> </th>
</tr>
<?php foreach ($products as $product) :?>
<tr>
<td> <?php echo $product['productCode']; ?> </td>
<td> <?php echo $product['productName']; ?> </td>
<td> <?php echo $product['productScale']; ?> </td>
<td> <?php echo $product['MSRP']; ?> </td>
<td> <?php echo $product['quantityInStock']; ?> </td>
<td> <form action="update_product.php" method="post">
<input type="hidden" name="productCode" value="<?php echo $product['productCode']; ?>">
<input type ="hidden" name="productLine" value="<?php echo $product['productLine']; ?>">
<input type="submit" value="Update">
</form> </td>
</tr>
<?php endforeach; ?>
</table>
<p>Add Product</p>
</section>
</main>
<footer>
<p>© <?php echo date("Y"); ?> Classic Models Online.</p>
</footer>
</body>
</html>
You need to get the productLine variable from the query string you have in the url. You need to add something like
if(isset($_GET['productLine'])){
$productLine = $_GET['productLine'];
}
Just do if(isset($_GET["productLine"])){//do your stuff}
I'm pulling content from MySQL database and I would like to display such content in 3 columns. I have managed to achieve it, but not all the content gets pulled. Even when I change it to 4 columns, it displays more content but still not all of them.
There must be a way to check how much content it is and display it correctly. Any help would be much appreciated.
This is what I have so far:
(I'm supposed to display 52 items from database, but only 38 or so get displayed)
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<div id="wrapper">
<div id="page">
<div id="content">
<div id="report_content">
<div id="top_bar">
<h1 class="report_title"></h1>
<h2 class="report_subtitle"></h2>
<div id="criteria"></div>
</div>
<div>
<div>
<div id="t1" class="results resultList">
<?php if ($row_detail_vendors) { $temp_name='' ; ?>
<table>
<?php $cols=4 ; do { ?>
<tr>
<?php for($i=1;$i<=$cols;$i++){ // All the rows will have $cols columns even if // the records are less than $cols $row_detail_vendors=m ysql_fetch_assoc($detail_vendors) ?>
<td> <a href="partner_info.php?idu=<?php echo $row_detail_vendors['shortcut']; ?>">
<?php echo ucfirst(strtoupper($row_detail_vendors['hotel_name'])); ?></a>
<br> <span><?php echo $row_detail_vendors['city']; ?>, <?php echo ucfirst($row_detail_vendors['country']); ?></span>
<br/>
<br/>
</a>
</td>
<?php } ?>
</tr>
</div>
<!--marketing-->
<?php } while ($row_detail_vendors=m ysql_fetch_assoc($detail_vendors)); ?>
<?php }?>
</div>
</div>
</div>
<!--marketing partners-->
</div>
<!--content-->
</div>
<!--page-->
</body>
Would advise:
<div id="t1" class="results resultList">
<table>
<?php
$cols=4;
$i = 1;
while($row_detail_vendors=mysql_fetch_assoc($detail_vendors)) {
if($i % $cols == 1){
echo "<tr>"; // start column wrapper
} ?>
<td><?php echo strtoupper($row_detail_vendors['hotel_name'])); ?>
<br /><span><?php echo $row_detail_vendors['city']; ?>, <?php echo ucfirst($row_detail_vendors['country']); ?></span>
<br/>
<br/>
</td>
<?php
if( $i % $cols == 0){
echo "</tr>"; // End column wrapper
}
$i++;
} ?>
</table>
</div>
<!--marketing-->
I'm a newbie in web development, and i want to modify an existing project.I want to display rows including a null value,a default value of zero or the empty one.This is the code in action..
public function executeDetails(sfWebRequest $r) {
if($this->getUser()->hasAttribute('extend_term_ch')) {
$this->getUser()->getAttributeHolder()->remove('extend_term_ch');
}
$this->loan = Doctrine_Core::getTable('Loans')->findOneById($r->getParameter('id'));
$this->debits = Doctrine_Core::getTable('CreditLogs')->getByLoanId($r->getParameter('id'));
}
and in templates
<?php $totalAmount = 0 ?>
<?php foreach($loan->Collections as $i=>$c): ?>
<?php $totalAmount += $c->amount ?>
<tr class="<?php echo ($i%2==0)?'even':'odd' ?>">
<td>
<?php echo $c->mode_of_payment ?>
<?php if($c->mode_of_payment == 'Cheque'): ?>
<?php $cReferencedObj = $c->Cheques ?>
<div class="small_detail info">
<span class="bold">(<?php echo $cReferencedObj->bank ?>, <?php echo $cReferencedObj->branch ?>) <?php echo $cReferencedObj->reference_number ?></span>
</div><br />
<?php endif; ?>
<?php $replaced = $c->getReplacedCheque() ?>
<?php if(!empty($replaced)): ?>
<div class="small_detail info">
Payment for <span class="bold">(<?php echo $replaced->bank ?>, <?php echo $replaced->branch ?>) <?php echo $replaced->reference_number ?></span>
</div><br />
<?php endif; ?>
</td>
<td><?php echo $c->batch_no ?></td>
<td>
PHP <?php echo number_format($c->amount, 2) ?>
<?php if($c->mode_of_payment == 'Cheque' && !empty($c->Cheques->replaced_with)): ?>
<?php $replaced = $c->Cheques->Replaced ?>
<div class="small_detail info">
Replaced with <span class="bold">(<?php echo $replaced->bank ?>, <?php echo $replaced->branch ?>) <?php echo $replaced->reference_number ?></span>
</div>
<?php endif; ?>
</td>
<td><?php echo date('F d, Y', strtotime($c->date_created)) ?></td>
<td><?php echo $c->created_by ?></td>
<td><?php echo $c->date_created ?></td>
<td>
<?php if(in_array($c->mode_of_payment, array('Cheque', 'ATM', 'Direct Bank Transfer'))): ?>
<span class="info">
View Details
</span>
<?php else: ?>
<div class="small_detail info">
Collector: <span class="bold"><?php echo $c->Collectors->lastname.', '.$c->Collectors->firstname ?></span>
</div>
<?php endif; ?>
<?php if(in_array($loan->mode_of_payment, array('Cash', 'ATM')) && $sf_user->hasCredential('COLLECTIONS_ROLLBACK')): ?>
<div class="small_detail bullet_go">
Rollback Collection
</div>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
<tr>
<td colspan="6">Total Paid</td>
<td>PHP <?php echo number_format($totalAmount, 2) ?></td>
</tr>
This will only display rows with data..how about displaying the empty row?For example a person has to pay his debts in 40 days from April 1, 2014 up to March 10,2014, then for some reason, he did not pay April 4, 6, 8 and so on.I want to display those dates 4, and 6 and 8 and display some errors for every date he failed to pay it like "No payment for this date".
I have a query that selects all the information from a database table and puts it into an array. I then use a PHP foreach statement to display all that in a uniform manner. It's the left table here to get a sense of what I'm talking about.
What I want to do is to make one of the divs (it normally just appears repeatedly under the same name) to have a unique name for each sumbission row. For example, instead of the "response" divs all just being called response, they are "response1", "response2", and so on. Is there any way to do this? (code below)
Any help would be greatly appreciated.
Here's where I call the info from the query:
<?php foreach($images as $image) { ?>
<table id="front_pgs">
<tr>
<td id="front_text">
<div id="imagetitle">
<?php echo $image['name'];?>
</div>
<div id="submission_info">
submitted by <?php echo $image['submitter'];?>
</div>
<div id="ratingcontainer">
<form id="ratingform">
<input name="vote" type="button" onclick="getVote('<?php echo $image['filename'];?>')" value='Like' id="likebutton"/>
<input name="dislike" type="button" value='Disike' id="dislikebutton"/>
</form>
<div id="rate_count">
<div id="response">
<?php echo $image['rating'];?>
</div>
</div>
</div>
</td>
<td id="front_pg_img" valign="center" align="center">
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" id="front_pg_thumbnail"/></a>
</td>
</tr>
</table>
<?php } ?>
You can do this by two ways I will show you now
1- add the row id if exists to the id value or any unique column
<div id="response<?php echo $image['id']; ?>">
<?php echo $image['rating'];?>
</div>
2- make a counter
<?php
$i= 1;
foreach($images as $image) { ?>
<table id="front_pgs">
<tr>
<td id="front_text">
<div id="imagetitle">
<?php echo $image['name'];?>
</div>
<div id="submission_info">
submitted by <?php echo $image['submitter'];?>
</div>
<div id="ratingcontainer">
<form id="ratingform">
<input name="vote" type="button" onclick="getVote('<?php echo $image['filename'];?>')" value='Like' id="likebutton"/>
<input name="dislike" type="button" value='Disike' id="dislikebutton"/>
</form>
<div id="rate_count">
<div id="response<?php echo $i; ?>">
<?php echo $image['rating'];?>
</div>
</div>
</div>
</td>
<td id="front_pg_img" valign="center" align="center">
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" id="front_pg_thumbnail"/></a>
</td>
</tr>
</table>
<?php
$i++; //increment the $i each iteration
} ?>
<?php $i = 1; foreach($images as $image) { ?>
<table id="front_pgs">
<tr>
<td id="front_text">
<div id="imagetitle">
<?php echo $image['name'];?>
</div>
<div id="submission_info">
submitted by <?php echo $image['submitter'];?>
</div>
<div id="ratingcontainer">
<form id="ratingform">
<input name="vote" type="button" onclick="getVote('<?php echo $image['filename'];?>')" value='Like' id="likebutton"/>
<input name="dislike" type="button" value='Disike' id="dislikebutton"/>
</form>
<div id="rate_count">
<div id="response<?php echo $i; ?>">
<?php echo $image['rating'];?>
</div>
</div>
</div>
</td>
<td id="front_pg_img" valign="center" align="center">
<a onClick="switchImageUrl('<?php echo $image['filename']; ?>', '<?php echo $image['width']; ?>', '<?php echo $image['height']; ?>')"><img src="<?php echo $image['filename'];?>" id="front_pg_thumbnail"/></a>
</td>
</tr>
</table>
<?php $i ++; } ?>
Notice the $i = 1 before the foreach as well as the $i ++ before the closing }. Also, echo $i in the response div id.
I've been trying to pull one single customer review onto the product page.
I've no code to show as honestly i'm not sure where to start and can't find any mention of it online.
Anyone have any ideas?
I wrote a tutorial earlier on bringing all the review elements onto the product page, so you could follow this tutorial: http://www.e-commercewebdesign.co.uk/blog/magento-tutorials/product-reviews-on-product-view-page.php
All you'd have to do is rename the list block and bring it out in the same way. Then simply modify the loop which brings out the reviews in any way you see fit. E.g. limit to a certain number or only echo out review from a certain user.
EDIT:
To get the latest review is quite simple because the reviews are in date order anyway.
Go to review > product > list.phtml
Replace the code in that file with this:
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<h2><?php echo $this->__('Customer Reviews') ?></h2>
<?php echo $this->getChildHtml('toolbar') ?>
<dl>
<?php $r_count = 0; ?>
<?php foreach ($_items as $_review):?>
<?php if ($r_count == 0) { ?>
<dt>
<?php echo $this->htmlEscape($_review->getTitle()) ?> <?php echo $this->__('Review by <span>%s</span>', $this->htmlEscape($_review->getNickname())) ?>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<col width="1" />
<col />
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php echo nl2br($this->htmlEscape($_review->getDetail())) ?>
<small class="date"><?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?></small>
</dd>
<?php } ?>
<?php $r_count++; ?>
<?php endforeach; ?>
</dl>
<?php echo $this->getChildHtml('toolbar') ?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
I've simple put an interator into the loop $r_count and put a check inside the foreach which prevent it from progressing on the next loop iteration.