Equals returns all the values in php - php

In this code I tried to filter some data records from the database using CategoryId but it returns all the category Id's. In my database Category Id's are INT field.
If I echo $data['Category']; then it shows all the categoryId's But after the variable comparison it not work.
I mean if($cat == 1) is Not working(It's not filter/Show data)
//Some coding here
<section id="section-1">
<div class="vs-content">
<div class="widgets-container">
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
$sql = "SELECT Id,Title,description,Image,Category from News ";
$query = mysql_query($sql);
?>
<div class="blocks">
<?php while($data = mysql_fetch_array($query)){
$cat = $data['Category'];
if($cat == 1){
?>
<h3 style="margin-left: 10px;"><?php echo $data['Title'] ?></h3>
<div style="width: 50%; margin-right: auto; margin-left: auto;">
<img src="images/drink2.jpg" /></div>
<img src="data:image/jpeg;base64,<?php base64_encode( $data['Image'] )?>"/>
<p style="color: white; font-size: 0.6em;"><?php echo $data['Description'] ?></p>
<?php
}
}
?>
</div>
<div class="blocks">
<?php while($data = mysql_fetch_array($query)){
$cat = $data['Category'];
if($cat == 2){
?>
<h3 style="margin-left: 10px;"><?php echo $data['Title'] ?></h3>
<div style="width: 50%; margin-right: auto; margin-left: auto;">
<img src="images/drink2.jpg" /></div>
<img src="data:image/jpeg;base64,<?php base64_encode( $data['Image'] )?>"/>
<p style="color: white; font-size: 0.6em;"><?php echo $data['Description'] ?></p>
<?php
}
}
?>
</div>
<div class="blocks">
<?php while($data = mysql_fetch_array($query)){
$cat = $data['Category'];
if($cat == 3){
?>
<h3 style="margin-left: 10px;"><?php echo $data['Title'] ?></h3>
<div style="width: 50%; margin-right: auto; margin-left: auto;">
<img src="images/drink2.jpg" /></div>
<img src="data:image/jpeg;base64,<?php base64_encode( $data['Image'] )?>"/> -->
<p style="color: white; font-size: 0.6em;"><?php echo $data['Description'] ?></p>
<?php
}
}
?>
</div>
</div>
</div>
// Some coding here

Why not filter the records in your database query? This would mean changing your database query as follows:
$sql = "SELECT Id,Title,description,Image,Category from News WHERE Category = 1";
By taking this approach less data will be returned to PHP and the database call will execute a little faster :)
Update: You only really need the three different <div class="blocks"> sections if the contents within them is going to be different. Otherwise you could simply use a single while loop and output the content for all categories in sequence using the data as ordered by the SQL statement.
//Some coding here
<section id="section-1">
<div class="vs-content">
<div class="widgets-container">
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
$sql = "SELECT Id,Title,description,Image,Category from News ORDER BY Category";
$query = mysql_query($sql);
?>
<div class="blocks">
<?php while($data = mysql_fetch_array($query)){
?>
<h3 style="margin-left: 10px;"><?php echo $data['Title'] ?></h3>
<div style="width: 50%; margin-right: auto; margin-left: auto;">
<img src="images/drink2.jpg" /></div>
<img src="data:image/jpeg;base64,<?php base64_encode( $data['Image'] )?>"/>
<p style="color: white; font-size: 0.6em;"><?php echo $data['Description'] ?></p>
<?php
}
?>
</div>
</div>
</div>
</section>
// Some coding here
If you only need data rendered for a single category then use the WHERE clause in SQL (See first example) to filter the data you require to reduce the SQL call and improve performance.

Why cant you check the condition in select query, Try this,
$sql = "SELECT Id,Title,description,Image,Category from News where Category='1'";
Update:
<div class="blocks">
<?php
while($data = mysql_fetch_array($query)){
$cat = $data['Category'];
if($cat == 1){ ?>
//Your code
<?php }else if($cat == 2){ ?>
// Your code
<?php }else{ ?>
<?php }?>
<?php }?>
</div>

Related

How to display 2 images per slide in carousel using php while loop?

I have a problem with displaying images in carousel. I want to display 2 images per carousel slide. I took images from database using while loop to create slides. The problem is that with my code it only displays one image per slide.
This is how it looks now:
Check the image
<?php
$brojacPoStrani = 0;
$sqlIzvestaji = mysqli_query($con, "SELECT operacije.nazivEng, izvestaji.operacija, izvestaji.ucinak, izvestaji.id FROM izvestaji INNER JOIN operacije ON izvestaji.operacijaId=operacije.id WHERE projekatId='$projekatId' AND datum='$datum'");
while ($row = mysqli_fetch_array($sqlIzvestaji)) {
$id = $row['id'];
$sqlSlike = mysqli_query($con, "SELECT img_name FROM slike WHERE izvestajId='$id' AND datum='$datum'");
$brojacDuplikata = false;
while ($row2 = mysqli_fetch_array($sqlSlike)) {
if ($brojacPoStrani % 2 == 0) {
?>
<div class="carousel-cell" style="background-image: url('img/izvestaji.jpg'); background-repeat: no-repeat; background-size: 100% 350px;">
<h1 style="color: #fff; text-align: left; padding-left: 15px; font-weight: bold;"><?php echo $row['nazivEng']; ?></h1>
<?php
if ($brojacDuplikata === false) {
$brojacDuplikata = true;
?>
<p style="text-align: left; padding-left: 45px; padding-top: 20px; padding-bottom: 10px;"><?php echo $row['operacija'] . " - " . $row['ucinak']; ?></p>
<?php
} else {
?>
<p style="text-align: left; padding-left: 45px; padding-top: 40px; padding-bottom: 10px;"></p>
<?php
}
?>
<div class="row">
<?php
if ($brojacPoStrani % 2 == 0) {
?>
<div class="col-lg-6">
<img src="../files/izvestaji/<?php echo $project; ?>/<?php echo $datum; ?>/<?php echo $row['nazivEng']; ?>/<?php echo $row2['img_name']; ?>" style="width: 350px; height: 350px; padding-left: 10px;" class="float-right" />
</div>
<?php
} else {
?>
<div class="col-lg-6">
<img src="../files/izvestaji/<?php echo $project; ?>/<?php echo $datum; ?>/<?php echo $row['nazivEng']; ?>/<?php echo $row2['img_name']; ?>" style="width: 350px; height: 350px; padding-right: 10px;" class="float-left" />
</div>
<?php
}
?>
</div>
<br />
</div>
<?php
}
$brojacPoStrani++;
}
$brojacPoStrani = 0;
}
As mentioned it looks like you should be able to use a single query rather than having nested queries - and to display 2 images per carousel slide you effectively want to select data from the current and next rows. One easy way to do that would be to assign the entire recordset to a variable and then process that array using a for loop. The following is a simplified, semi-pseudo code version that attempts to combine the sql queries and assign recordset to an array. It is not tested as such but it might? be of use.
$sql="select
o.naziveng,
i.operacija,
i.ucinak,
i.id,
s.img_name
from izvestaji i
inner join operacije o on i.operacijaid=o.id
inner join slike s on s.izvestajId=i.id
where projekatid='$projekatid' and datum='$datum'";
$res = mysqli_query( $con, $sql );
if( $res ){
$arr = mysqli_fetch_all( $res, MYSQLI_BOTH );
for( $i=0; $i < count( $arr ); $i+=2 ){
try{
$r1=array_key_exists( $i+0, $arr ) ? $arr[ $i+0 ] : false;
$r2=array_key_exists( $i+1, $arr ) ? $arr[ $i+1 ] : false;
/*
generate the HTML structure and add two images
*/
echo '<div class="carousel-cell">'; # simplified version
if( $r1 )echo 'row 1: '.$r1['img_name'];
if( $r2 )echo 'row 2: '.$r2['img_name'];
echo '</div>';
}catch( Exception $e ){
continue;
}
}
}

PHP - Show each product from table

I have a products table where I have products being listed into. I want to create a peice of code that will show the same style but different price, name, description, picture for each product. I have create a peice of code that sort of does this. My code displays only the first in the row. I need to list all of them. My code is :
function grabProducts($con) {
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="col-md-12" id="please_wait">
<div class="panel panel-warning">
<div class="panel-heading">
<h3 class="panel-title"><i>Loading, Please Wait...</i></h3>
</div>
<div class="panel-body">
</div>
</div>
</div>
<script>
$(document).ready(function() {
$('#please_wait').fadeOut(7000);
$('#content_purchase').hide(0).delay(5000).fadeIn("slow");
});
</script>
<?php
$users = $this->grabUserInfos($con);
foreach ($users as $user) {
$username = $user[1];
$email = $user[3];
}
$site_config = new site_config();
$member_config = new member_config();
$result = mysqli_query($con, "SELECT * FROM products");
$count = mysqli_num_rows($result);
// See if there are any products in the database
if ($count > 0) {
// While loop for each product element
while ($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$name = $row['name'];
$description = $row['description'];
$picture = $row['picture_location'];
$price = $row['price'];
$stock_monitering = $row['stock_monitering'];
$stock = $row['stock'];
$new_stock = $stock - 1;
$url_path = 'http' . (empty($_SERVER['HTTPS']) ? '' : 's') . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$url_path_naked = parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH).'/pizza/products.php';
$getValidatedCheck_ = mysqli_query($con, "SELECT txn_id, hasValidated, item_name, amount, currency, payment_date FROM payment_logs WHERE userId = '$username' ORDER BY id DESC LIMIT 1");
$count_success_payment = mysqli_num_rows($getValidatedCheck_);
// While loop for our successful payment_logs for each user
while ($row = mysqli_fetch_array($getValidatedCheck_)) {
$txn_id = $row['txn_id'];
$validated_check = $row['hasValidated'];
$item_name = $row['item_name'];
$item_price = $row['amount'];
$item_currency = $row['currency'];
$payment_date = $row['payment_date'];
$now = strtotime("-10 minutes");
// If there is not enough stock, show out of stock
if($stock <= 0) {
$display = 'out_of_stock';
} else if($stock > 0 && $now > strtotime($payment_date)) {
$display = 'show_products';
}
// If there are no transactions for that user show the products like normal
if($count_success_payment == 0) {
// If they've not already seen the success message, show them it now and update their hasValidated from 0 to 1 so they don't see it again
if ($validated_check == '0') {
// If stock monitering is on, update our stock to 1 less than we had before the purchase
if($stock_monitering == '1') {
mysqli_query($con, "UPDATE products SET stock = '$new_stock' WHERE name = '$name'");
}
$display = 'show_success';
}
}
}
switch($display) {
case "show_products":
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<form name="paypal_form" action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business"
value="<?php $site_config->grabSiteSettings($con, 'paypal_address'); ?>">
<input type="hidden" name="item_name" value="<?php echo $name; ?>">
<input type="hidden" name="item_number" value="<?php echo $id; ?>">
<input type="hidden" name="amount" value="<?php echo $price; ?>">
<input type="hidden" name="quantity" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="custom" value="username=<? echo $username; ?>&status=<? echo $checkout_status; ?>&product=<? echo $name; ?>">
<input type="hidden" name="notify_url" value="https://benzaofficial.com/pizza/includes/checkout.php">
<input type="hidden" name="return"
value="<?php $site_config->grabSiteSettings($con, 'site_url'); ?>/pizza/products.php?status=complete">
<input type="hidden" name="cancel_return"
value="<?php $site_config->grabSiteSettings($con, 'site_url'); ?>/pizza/products.php?status=canceled">
<button type="submit" class="btn btn-danger"
style="vertical-align : bottom; margin-bottom: 15px; display: block; width: 85%;">
<i class="fa fa-paypal"></i>aypal
</button>
<form>
</div>
</center>
</div>
</div>
<?php
break;
case "show_success":
?>
<div class="col-md-12" id="content_purchase" style="display: none;">
<div class="panel panel-success">
<div class="panel-heading">
<h3 class="panel-title"><i>PAYMENT SUCCESS!</i></h3>
</div>
<div class="panel-body">
<p>You've successfully purchased <i><?php echo $item_name; ?></i> for <i><?php echo $item_price; ?> <i><?php echo $item_currency; ?></i></i> We have emailed you your receipt to <?php echo $email; ?>. You can click here to download your purchased files.<br>Click here to purchase again.</p>
</div>
</div>
</div>
<?php
mysqli_query($con, "UPDATE payment_logs SET hasValidated = '1' WHERE userId = '$username' ORDER BY id DESC LIMIT 1");
break;
case "no_products":
?>
<div class="col-md-12" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title"><i>Currently No Products For Sale</i></h3>
</div>
<div class="panel-body">
<p>There are currently no products up for sale.</p>
</div>
</div>
</div>
<?php
break;
case "out_of_stock":
?>
<div class="col-md-3" id="content_purchase" style="display: none;">
<div class="panel panel-danger">
<div class="panel-heading">
<h3 class="panel-title">Price: <i>$<?php echo $price; ?></i>
<div class="fRight" style="float: right;"><i><?php echo $name; ?></i> Stock
(<?php echo $stock; ?>)
</div>
</h3>
</div>
<center>
<div class="panel-body">
<img src="<?php echo $picture; ?>"
style="width: 85%; height: 100px; margin: 15px 0px 15px 0px; border-radius: 5px; border: 2px solid #ED4949;">
<p><i><?php echo $name; ?></i> is currently out of stock. Please come back later and try again.</p>
</div>
</center>
</div>
</div>
<?php
break;
}
}
} else {
$display = 'no_products';
}
}
first you need a function dat select all of your products like this one
function showproducts($conn,$id){
$req="SELECT * FROM products ";
$liste=$conn->query($req);
return $liste->fetchAll();
}
than you should call this function :
$list=$cc->showproducts($cc->conn);
and foreach row you can show all columns
<?php
foreach ($list as $l){ ?>
<tr>
<td><?php echo $l[0] ;?> </td>
<td><?php echo $l[1] ;?> </td>
<td><?php echo $l[2] ;?> </td>
<td><?php echo $l[3] ;?> </td>
<td><?php echo $l[7] ;?> </td>
</tr>
<?php } ?>

PHP Won't echo same code in different div

This part of the code works fine:
<div id="Vraag">
<?php
while($row = mysqli_fetch_assoc($rows))
{
echo $row["vraag"];
}
?>
</div>
But this part does not work:
<div id="antAA">
<?php
while($row = mysqli_fetch_assoc($rows))
{
echo $row["AntwA"];
}
?>
<!-- Antwoord A -->
</div>
And I have no idea why it is not working. It is the same code. The database works fine because if I run this code all the way in the the top of my code it echoes all of them fine:
while($row = mysqli_fetch_assoc($rows))
{
echo $row["id"];
echo $row["vraag"];
echo $row["AntwA"];
echo $row["AntwB"];
echo $row["AntwC"];
echo $row["AntwD"];
}
But in the div it just does not work.
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="se.css">
<title>Lotto</title>
</head>
<body>
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "lotto";
$db = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$query = "SELECT id, vraag, AntwA, AntwB, AntwC, AntwD,id FROM vraag1";
$rows = mysqli_query($db, $query);
// while($row = mysqli_fetch_assoc($rows))
// {
// echo $row["id"];
// echo $row["vraag"];
// echo $row["AntwA"];
// echo $row["AntwB"];
// echo $row["AntwC"];
// echo $row["AntwD"];
// }
?>
<div id="headerbg"></div>
<center>
<h1>Vraag 1</h1>
</center>
<center>
<div>
<img src="antw.png" id="img6">
</div>
<div id="Vraag">
<?php
while($row = mysqli_fetch_assoc($rows))
{
echo $row["vraag"];
}
?>
</div>
<div id="plaatje">
<img id="img1" src="wip.jpg">
</div>
<div id="BGantA">
<img id="img2" src="antw.png">
</div>
<div id="antAA">
<?php
while($row = mysqli_fetch_assoc($rows))
{
echo $row["vraag"];
}
?>
<!-- Antwoord A -->
</div>
<div>
<img src="antw.png" id="img3">
</div>
<div>
Antwoord B
</div>
<div>
<img src="antw.png" id="img4">
</div>
<div>
Antwoord C
</div>
<div>
<img src="antw.png" id="img5">
</div>
<div>
Antwoord D
</div>
</center>
</body>
</html>
CSS Code if needed:
body{
background-color: white;
overflow: hidden;
/*#ECECEC;*/
}
#headerbg{
display: block;
margin-top:-10px;
margin-left: -10px;
margin-right: -10px;
width: 102%;
height: 118px;
background-color: #333333;
/*#232323;*/
}
h1{
font-family: times;
display: block;
margin-left: -800px;
margin-top:-76px;
color: #979797;
}
#img2, #img3, #img4, #img5{
width:300px;
height:100px;
display: block;
}
img{
border:1px solid lightgray;
padding: 5px;
}
#img1{
margin-top: 50px;
}
#img2{
margin-top: -370px;
margin-left: -800px;
}
#img3{
margin-top:-67px;
margin-left:800px;
}
#img4{
margin-left:-800px;
margin-top: 150px;
}
#img5{
margin-left: 800px;
margin-top: -67px;
}
#img6{
display: block;
width: 800px;
height: 60px;
margin-top: 55px;
margin-left: ;
}
#antAA, #antBB, #antCC, #antDD{
display: block;
/*color: #979797;*/
color:red;
text-decoration:none;
}
#antAA, #antCC{
margin-top: -65px;
margin-right: 800px;
}
#antBB{
margin-top: -65px;
margin-left: 800px;
}
#antDD{
margin-left: 800px;
margin-top:-65px;
}
#Vraag{
display:block;
color: red;
margin-top: -44px;
}
#antAA:hover, #antBB:hover, #antCC:hover, #antDD:hover{
color:white;
}
Once you execute mysqli_fetch_assoc then it return false as last value has been fetched and has no further value.
If you want to use this for multiple times you can save its value in array and then use this array
<?php
$vraag_array=array();
while($row = mysqli_fetch_assoc($rows))
{
$vraag_array[] = $row["vraag"];
}
//to echo
// close
?>
<div id="Vraag">
<?php
foreach ($vraag_array as $vraag_value) {
echo vraag_value;
}
?>
</div>
<div id="plaatje">
<img id="img1" src="wip.jpg">
</div>
<div id="BGantA">
<img id="img2" src="antw.png">
</div>
<div id="antAA">
<?php
foreach ($vraag_array as $vraag_value) {
echo vraag_value;
}
?>
<!-- Antwoord A -->
</div>
Use:
mysqli_data_seek($rows, 0);
After every while loop.
This sets the counter back to 0
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="se.css">
<title>Lotto</title>
</head>
<body>
<?php
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "lotto";
$db = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$query = "SELECT id, vraag, AntwA, AntwB, AntwC, AntwD,id FROM vraag1";
$rows = mysqli_query($db, $query);
// while($row = mysqli_fetch_assoc($rows))
// {
// echo $row["id"];
// echo $row["vraag"];
// echo $row["AntwA"];
// echo $row["AntwB"];
// echo $row["AntwC"];
// echo $row["AntwD"];
// }
?>
<div id="headerbg"></div>
<center>
<h1>Vraag 1</h1>
</center>
<center>
<div>
<img src="antw.png" id="img6">
</div>
<div id="Vraag">
<?php
while($row = mysqli_fetch_assoc($rows))
{
echo $row["vraag"];
}
mysqli_data_seek($rows, 0);
?>
</div>
<div id="plaatje">
<img id="img1" src="wip.jpg">
</div>
<div id="BGantA">
<img id="img2" src="antw.png">
</div>
<div id="antAA">
<?php
while($row = mysqli_fetch_assoc($rows))
{
echo $row["vraag"];
}
mysqli_data_seek($rows, 0);
?>
<!-- Antwoord A -->
</div>
<div>
<img src="antw.png" id="img3">
</div>
<div>
Antwoord B
</div>
<div>
<img src="antw.png" id="img4">
</div>
<div>
Antwoord C
</div>
<div>
<img src="antw.png" id="img5">
</div>
<div>
Antwoord D
</div>
</center>
</body>
</html>
It looks like you're iterating through and fetching all the rows, but only reading out the one that matches "vraag". When you execute a second time, you have already iterated through and exhausted all the rows.
That's why this bit works:
while($row = mysqli_fetch_assoc($rows))
{
echo $row["id"];
echo $row["vraag"];
echo $row["AntwA"];
echo $row["AntwB"];
echo $row["AntwC"];
echo $row["AntwD"];
}
Because you're using each row as it is being processed over.
I can't really understand why you're executing such code, which iterates over entire collections and reads out the same singular value each time, but if you want the second attempt to work, you will have to execute this line again:
$rows = mysqli_query($db, $query);
Definitely consider rethinking the entire structure though.
I'm not totally sure. But I think this is because in the first while loop it takes out the "vraag".
So in the second while loop, it may think its the same loop so there is no more data to display there. Try to put in the query again right above the second loop. With other variable names
$query2 = "SELECT id, vraag, AntwA, AntwB, AntwC, AntwD,id FROM vraag1";
$rows2 = mysqli_query($db, $query2);
while($row2 = mysqli_fetch_assoc($rows2))
Please try to use different variables for different values. Please try different variable name in next code which is not working, just like this:
<div id="antAA">
<?php
while($row_new = mysqli_fetch_assoc($rows))
{
echo $row_new["AntwA"];
}
?>
<!-- Antwoord A -->
</div>
I hope, this will solve your issue.

why products url is repeating in magento

I'm using Magento 1.7.0. I want to show latest ordered products on homepage sidebar. Almost everything is ready and working properly except its URL.
I don't know why products URL is repeating again and again. Products' images, it's name and price is showing correct only it's URL gets repeated for each product.
Each product have the same first product URL.
Here is the code
<style>
.productList { float:left; width:720px; }
.productList .product { background:#fff; border:1px solid #eedfa6; padding:3px; float:left; text-align:center; width: 182px; margin-bottom: 7px; height: 200px; }
.productList .product .cl { padding:0 0 0 0px; text-align:center;}
.productList .product .prodDetails {font-weight: bold;font-size: 12px; color: #2a2a28;text-align:center; padding:0 0 0 0px; }
.productList .product .prodDetails a{color: #d77932;}
.productList .product .prodDetails a:hover{color: #3d4d68 ;}
.productList .product .addCompare { text-align:center; clear:both; }
.productList .product .addWishlist {clear:both; text-align:center; }
}
</style>
<?php
$result = $this->getBestsellerProduct();
$itemPerRow = ($this->getItemsPerRow()) ? $this->getItemsPerRow() : 2 ;
//getting product model
$model = Mage::getModel('catalog/product');
$products_price = Mage::getStoreConfig('bestseller/general/products_price');
$review = Mage::getStoreConfig('bestseller/general/review');
?>
<div style="width:200px;float:right;">
<div class="sectionHead" style=""><h2><?php echo $this->getHeader(); ?></h2><div style="height: 25px;border-bottom: 2px solid #eedfa6 /*#DBDBDB;*/" class="hrline"></div></div>
<table border="0" cellpadding="0" cellspacing="0" class="productList" style="width:100px;">
<?php $i=0;
for($cnt = 0; $cnt<5; $cnt++){
$_product = $model->load($result[$cnt]); //getting product object for particular product id
?>
<tr>
<td class="product">
<div class="prodimage">
<!-- code added by Saurabh-->
<?php echo $_product->getProductUrl() ?>
<?php if ($_product->getExt_image_url()!=''){$srcImage=$_product->getExt_image_url();} else{$srcImage=$this->helper('catalog/image')->init($_product, 'small_image');} ?>
<!--saurabh code ended here-->
<a href="<?php echo $_product->getProductUrl() ; ?>" title="<?php echo $this->htmlEscape($_product->getName()) ?>">
<img src="<?php echo $srcImage; ?>" width="150" height="145" alt="<?php echo $this->htmlEscape($_product->getName()) ?>"/>
</a>
</div>
<div align="center">
<div class="prodDetails" align="center" style="width:175px;" >
<?php $_product_name= $_product->getName(); ?>
<?php $_short_product_name = substr($_product_name, 0, 40); ?>
<?php $_dot_product_name=$_short_product_name.'...' ; ?>
<?php echo $_dot_product_name ;?>
<?php if($review == 1)
{
$_product = Mage::getModel('catalog/product')->load($_product->getId());
echo $this->getReviewsSummaryHtml($_product, 'short');
}
if($products_price == 1)
{
$_product = Mage::getModel('catalog/product')->load($_product->getId());
echo $this->getPriceHtml($_product, true);
}
?>
</div>
<?php $addtocartval = $this->getAddToCart();
if($addtocartval == 1){
if($_product->isSaleable()): ?>
<button class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><?php echo $this->__('Add to Cart') ?></span></button>
<?php else: ?>
<span class="out-of-stock"><?php echo $this->__('Out of stock') ?></span>
<?php endif; }?>
</div>
<div class="cl">
<?php $wishlists = $this->getActive();
if($wishlists == 1){
if ($this->helper('wishlist')->isAllow()) : ?>
<?php echo $this->__('Add to Wishlist') ?>
<?php endif; }?>
</div>
<div class="cl">
<?php $addtocompare = $this->getAddToCompare();
if($addtocompare==1){
if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
<?php echo $this->__('Add to Compare') ?>
<?php endif; }?>
</div>
</td>
</tr>
<?php
}
?>
</table>
</div>
First ,check $result[$cnt] is same for every time??
for($cnt = 0; $cnt<5; $cnt++){
// change code here
$_product = Mage::getModel('catalog/product')->load($result[$cnt]);
$my_product_url = $product->getProductUrl();
//or
$my_product_url=Mage::getResourceSingleton('catalog/product')
->getAttributeRawValue($result[$cnt], 'url_key', Mage::app()->getStore());
//or
$my_product_url=Mage::getUrl()''.$_product->getData('url_key').'.html';

CSS li inline & jquery sortable

having an issue with the jquery sortable code - it's not so much the jquery but how my list of images is showing. Prior to adding the sortable code it displayed the images in my wrapper in a grid like formation perfectly - now I have added a little style from the jquery it seems to have thrown it but im not sure why...
here is the Jquery style:
<style>
#sortable { list-style-type: none; margin: 0; padding: 0; width: 450px; }
#sortable li {float: left; }
</style>
Here is my list of images that worked perfectly ok before:
<div id="images">
<hr style="margin-top: 10px" />
<ul id="sortable">
<?php
// get folio for user
if(isset($_GET['userid'])) {
$query = 'SELECT * FROM folio WHERE userid=\'' . $_GET['userid'] . '\' ORDER BY ord';
}
else {
$query = 'SELECT * FROM folio WHERE userid=\'' . $_SESSION['userid'] . '\' ORDER BY ord';
}
$result = mysqli_query($connection, $query);
if(!$result) {
// error with MYSQL
die('Failed to retrieve images! - ' . mysqli_error($connection));
}
// list images
$numRows = mysqli_num_rows($result);
if($numRows < 1) {
echo '';
}
else {
$filepath = 'uploads/folio/';
while($imagerow = mysqli_fetch_assoc($result)) {
?>
<li>
<div class="outimgbox"> <a class="fancybox fancybox.ajax" rel="gallery1" style="text-decoration: none;" data-fancybox-type="ajax" href="profile_image_fancybox.php?imgid=<?php echo $imagerow['imgid']; ?>">
<div id="mainwrapper">
<div id="box-3" class="box"> <img class="uploads" src="<?php echo $filepath . $imagerow['filename']; ?>" alt="<?php echo $imagerow['description']; ?>"/> <span class="caption fade-caption">
<h3 ><?php echo $imagerow['title']; ?></h3>
</span> </div>
</div>
</a> </div>
</li>
<!-- class outingbox -->
<?php }} ?>
</ul>
For some odd reason:
<style>
#sortable { list-style-type: none; }
#sortable li {float: left; }
</style>
This resolved the issue....

Categories