I have a products page with full of product pictures with unique id from database for every product. When i click the product, it directs me to another page with unique id for each product. I need the page to show pictures based on the unique id of the product.
The page to click the product CODE:
<a href="productdetails.php?id=<?php echo $row['id']; ?>">
<img src="images/<?php echo $row["image"]; ?>" class="img-responsive" />
</a>
I need the clicked product page to show pictures based on the unique id.
CODE:
<?php
$getimagefrom = "SELECT image FROM product_details_image WHERE imagecode = 1 ORDER BY id";
$result = mysqli_query($connect, $getimagefrom);
while($row = mysqli_fetch_array($result))
{
?>
<img class="imgStyle" src="images/<?php echo $row["image"]; ?>" />
<?php
}
?>
The ORDER BY id is unique code that should be called when the product with the unique code is clicked.However, whenever i click the product, it goes to the page with unique id but the product shown is the same id always.
May ask question if not clear of it.
Related
Making a car rental reservation system for a school project, project is in html/php & SQL. So far the user picks location date/time and car category on page 1, user then searches available cars on page 2. on page 2 the cars are listed and user picks the car they want to rent, the cars are listed in while loop from
the database. there is a reserve button attached to each car so that the user can pick.
Heres my issue how do i pass over the cars details as variables(make, model, class, dailyrate) for what the user picks onto the next php page prompting page. im using $_sessions.
<?php
$sql= "SELECT * FROM vehicles WHERE class='$class'";
$result = mysqli_query($db,$sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
while ($row = mysqli_fetch_assoc($result)) { //beginning of while loop
$_SESSION['make']=$row['make'];
$_SESSION['model']=$row['model'];
$_SESSION['class']=$row['class'];
$_SESSION['dailyrate']=$row['daily_rate'];
?>
<div class="card">
<div class="img">
<img src='../../images/defaultcar.png' width='100' height='100'>
</div>
<div>
Make: <?php echo $row['make']; ?><br>
Model: <?php echo $row['model']; ?><br>
<b>Class: <?php echo $row['class']; ?></b><br>
<div class="price"> <b>$ <?php echo $row['daily_rate']; ?></b>/Per day</div>
</div>
<button class='reserve-btn'>Reserve</button>
</div>;
<?php } //ending bracket of while loop
}
else {
echo "0 results";
}
?>
</div>
I will try to help you through google translate, the easiest way to do it is by adding the car ID in the value of the reserve button, then declare a name for the button and send that ID to the next page, getting there only from another SELECT * FROM CARS WHERE ID =? and get the information
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 have products displayed on my index page, I have a links which add id of product and title both from products table but I can also display category id from the products table but it's a int,
So can anyone advise how I grab the category name from category table and add to <a href> url,
<a href="products.php?category=
so when I click on the link it takes me to the product but the breadcrumbs are populated as well!
My theory is to use a $_get category or something but given its my index page there's no <a> link to populate the url with the category id or something!
index.php
<?php while($product = mysqli_fetch_assoc($top_components)) : ?>
<div class="trendingproductsdiv">
<div class="trendingproducts-img">
<?php $photos = explode(',',$product['image']); ?>
<a href="product_details.php?id=<?=$product['id'];?>&category=Components&title=<?=$product['title'];?>">
<img src="<?= $photos[0]; ?>" alt="<?php echo $product['title']; ?>" class="group list-group-image" style="wdith:100px; height: 200px;">
</a>
</div>
</div>
where it says &category=Components, I want that to represent the image I am clicking, i.e the images are generate dynamically based on the Top_components selected as 1 in my db,
so if the product is Cat 6 (cases) and prod id = 1. the next page that loads will be for a Case product with id of 1.
I can get the product title and id to display but not the category, so that when the next page is view the breadcrumbs need to say Home>Cases> Product name.
UPDATE:
I got it working by doing this:
<a href="product_details.php?id=<?=$product['id'];?>&cat=<?=$product['categories'];?>&title=<?=$product['title'];?>">
then my product_details.php page breadcrumb like this:
<?=$breadcrumbs_cat['category']; ?>
so it now looks like:
HOME>Cat ID> Product Name which is what I wanted,
some button
The url will be your-domain.com/products.php?category=sales
<?php $catagory=$_REQUEST['category']; ?>
Here REQUEST must be in uppercase.
Okay so my code below echoes out two URLs from the database but I want to have the ability to separate the two and update the row where the image is clicked. Example: Two images are output, users clicks image on the left, MySQL knows which row to update depending on which image they clicked. Depending on the image they click it will update the image's votes in MySQL. Ideally I want the "vote-ups" to show in place of the 112 and 156 accordingly from the database.
Let me rephrase to clarify: my code echoes out two images selected from the database. The code should tell you that if you read it. From there, I want to be able to separate the two images so I can do a query to update the specific row with that image and update the total votes that image has from votes to votes+1. I tried doing this but it would update both row's votes by 1.
How can I do this?
<?php
include_once('db.php');
$selectURLSQL = "SELECT * FROM `urls` ORDER BY RAND() LIMIT 3";
$selectURLQuery = mysql_query($selectURLSQL);
$URL_Row = mysql_fetch_array($selectURLQuery);
?>
<?php
while($URL_Row = mysql_fetch_array($selectURLQuery)) {
?>
<img class="img" name="img" src="<?php echo $URL_Row['url']; ?>" style="height:400px;width: 260px;">
<?php
}
?>
<br /><br />
<span style="font-size:18px;font-family:trebuchet ms;">156 Vote-Ups</span>
<small>Vs.</small>
<span style="font-size: 18px; font-family: trebuchet ms;">112 Vote-Ups</span><br /><br />
Say your table urls is structured like this:
id | url | rank
you have to increment the rank column for each click on the image corresponding to the url.
my idea is to create a link around the image, and this link will contain the id of the image so it can be passed in the URL like this ?id=xxx
if you want to show the votes outside the loop, you can save them temporarily in an array
Your Code:
<?php
include_once('db.php');
$selectURLSQL = "select * from urls ORDER BY RAND() LIMIT 2";
$selectURLQuery = mysql_query($selectURLSQL);
if (isset($_GET['id'])){
$id = $_GET['id'];
$sql = "UPDATE urls set rank = rank+1 WHERE id = $id";
mysql_query($sql);
}
$i = 0;
$votes = array();
while ($URL_Row = mysql_fetch_array($selectURLQuery)):
$votes[$i++] = $URL_Row['rank'];
?>
<a href="?id=<?php echo $URL_Row['id']; ?>">
<img class="img" name="img" src="<?php echo $URL_Row['url']; ?>" style="height:400px;width: 260px;">
</a>
<?php endwhile; ?>
<br /><br />
<span style="font-size:18px;font-family:trebuchet ms;"><?php echo $votes[0]; ?> Vote-Ups</span>
<small>Vs.</small>
<span style="font-size: 18px; font-family: trebuchet ms;"><?php echo $votes[1]; ?> Vote-Ups</span><br /><br />
I am trying to show image thumbnail of products in order view page (sales_order/view) area of Magento. Adding preview image of the product as a column.
I have my line as the below:
load($_item->getProductId()); ?>init($_product, 'thumbnail')->resize(75, 75); ?>"
alt="<?php echo $this->htmlEscape($_product['name']); ?>" border="0" width="75" />
But this just pulls through a blank box with no image at all in it, not even the Magento default image.
It will likely just be name of field or attribute slightly off? Or maybe even casing? But can't really see what I'm doing wrong.
If I replace:
load($_item->getProductId());
with:
load($_item['product_id'])->getData('image')
I can pull in the location of the image which shows on the page. But can't get it to work to actually display the image.
Can pull thumbnail of product in fine on the product grid page, but can't locate page to replicate code from.
Any help to polish off above would be appreciated.
Final code was the below. To get this working add it to /app/design/adminhtml/default/default/template/sales/order/view/items/renderer/default.phtml
<td class="a-center">
<?php $product = Mage::getModel('catalog/product')->setStoreId($_item->getOrder()->getStoreId())->load($_item->getProductId());?>
<p align="center">
<img src="<?php echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(75); ?>" width="75" height="75" />
</p>
</td>
You can show ordered item image with below code
$order = Mage::getModel('sales/order')->load($orderId);
foreach($order->getAllItems() as $item){
$product=Mage::getModel('catalog/product')->load($item->getProductId());
echo Mage::helper('catalog/image')->init($product, 'small_image')->resize(50,50);
}
this can be helpful for you i think you just need to place your attribute value
http://magentocodes.blogspot.in/2013/01/get-custom-attribute-value-in-magento.html