I'd like to use the dynamic value of my li tag in an sql query. I added an id to it, but I guess my code is wrong. I'm new here so help me please, thank you.
Here is my code for my li tag:
<?php
$catque = "SELECT * FROM category_tb WHERE account_id_fk={$_SESSION['account_id']}";
$catresult = mysqli_query($connect,$catque);
$catid="";
?>
<ul name="catnav" id="catbarr">
<li class="lii aactive" onclick="filterSelection('all')">All Products</li>
<?php
while($row = mysqli_fetch_array($catresult))
{
?>
<!-- <li><button class="btn" onclick="filterSelection('category')"> <?php echo $row["category_name"]; ?> </button></li>
-->
<li class="catname lii" id="catid" onclick="filterSelection('category')"> <?php echo $row["category_name"]; ?> </li>
<?php
}
?>
</ul>
Here is my code for my sql query where I want to use the li id:
<div class="tab-content products filterDiv category">
<?php
$catquer = "SELECT * FROM product_tb WHERE (category_id_fk IN (SELECT category_id FROM category_tb WHERE category_name = 'catid' ) AND account_id_fk = {$_SESSION['account_id']}) ORDER BY product_id ASC";
$queresult = mysqli_query($connect,$catquer);
while($row = mysqli_fetch_array($queresult))
{
?>
<div class="col-md-4" style="margin-top:12px;">
<div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px; height:350px;" align="center">
<div class='imgborder'>
<img src="images-products/<?php echo $row["product_image"]; ?>" class="img-responsive"/><br />
</div>
<h4 class="text-info"><?php echo $row["product_name"]; ?></h4>
<h4 class="text-danger">₱ <?php echo $row["price"]; ?></h4>
<input type="number" name="quantity" id="quantity<?php echo $row["product_id"]; ?>" class="form-control" value="1" min="1" max="100" />
<input type="hidden" name="hidden_name" id="name<?php echo $row["product_id"]; ?>" value="<?php echo $row["product_name"]; ?>" />
<input type="hidden" name="hidden_price" id="price<?php echo $row["product_id"]; ?>" value="<?php echo $row["price"]; ?>" />
<input type="button" name="add_to_cart" id="<?php echo $row["product_id"]; ?>" style="margin-top:5px;" class="btn btn-warning form-control add_to_cart btnStyle" value="Add to Cart" />
</div>
</div>
OK. As far as I understood, you are trying to use some value from HTML li tag in your SQL, and you said it is dynamic.
If you want to use li tag value in server side, just keep your li tag value in an variable and later use it anywhere.
If you are trying to get it from client side, you need to use Javascript to get value from any specific li. Then you can send AJAX request.
It might be better to answer if you can specify exactly what problem you are facing. It is hard to go throw line by line searching for unknown errors.
Related
I have a PhP shopping cart for autoparts and I need to be able to enlarge the retrieved image upon clicking on it. The problem is I can't manually assign an ID to every picture because I'm echoing them from the database.
I've tried assigning one ID/class to all the pictures that get retrieved and enlarge them on click using the JS function but can't get it working.
$items_array = $db_controller->runQuery("SELECT * FROM mystuff ORDER BY ID ASC");
if (!empty($items_array)) {
foreach($items_array as $key=>$value){
?>
<div class="DisplayCartItems">
<form method="post" action="?action=add&mscode=<?php echo $product_array[$key]["mscode"]; ?>">
<img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/> /* Right here I need some help */
<div class="lif"><strong>Category:</strong> <?php echo $product_array[$key]["mscategory"]; ?></div>
<div class="lif"><strong>Category №:</strong> <?php echo $product_array[$key]["mscatnum"]; ?></div>
<div class="lif"><strong>Stock №:</strong> <?php echo $product_array[$key]["msnomer"]; ?></div>
<div class="lif"><strong>Mark:</strong> <?php echo $product_array[$key]["msmark"]; ?></div>
<div class="lif"><strong>Model:</strong> <?php echo $product_array[$key]["msmodel"]; ?></div>
<div class="lif"><strong>Year:</strong> <?php echo $product_array[$key]["msyear"]; ?></div>
<div class="lif"><strong>Price:</strong> <?php echo "$".$product_array[$key]["msprice"]; ?></div>
<div style="text-align:center"><input type="number" name="oap" placeholder="Offer a price:"></div>
<br class="">
<div class="cartan">
Quantity: <input type="text" class="product-quantity" name="quantity" value="1" size="2" />
<br class="">
<input type="submit" onclick="AddCartAlert()" value="Add to cart" /></div>
</form>
</div>
<?php
}
}
?>```
I think if I can somehow assign an ID or class name for every picture that get displayed from the MySql and onclick change it's width/height, that'd do the job.
If I have correctly understood:
you should replace this:
<img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/> /* Right here I need some help */
with:
<a target="_blank" href="<?php echo $product_array[$key]["msimage"]; ?>"><img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/></a>
for opening the image in another tab.
Or... if you mean something like this https://lokeshdhakar.com/projects/lightbox2/#examples you have to use javascript (for example: Image #1)
In your case something like this: (of course you need to add lightbox script: https://lokeshdhakar.com/projects/lightbox2/#getting-started)
<a data-lightbox="image-1" data-title="My caption" href="<?php echo $product_array[$key]["msimage"]; ?>"><img src="<?php echo $product_array[$key]["msimage"]; ?>" class="imgcartdisplay" align="alignnone"/></a>
the checkbox is not working.. I could not insert new data into the table
there is nothing happen when I click the "add to cart" button.
<div class="carousel-inner">
<div class="item">
<ul class="thumbnails">
<?php
$query = mysql_query("SELECT * FROM product where pro_category='3' LIMIT 0,4 ");
while ($data = mysql_fetch_assoc($query)):
?>
<li class="span3">
<div class="product-box">
<span class="sale_tag"></span>
<?php echo '<p><img src="admin/pro_image/'.$data['image'].'" /></p>'; ?>
<?php echo ''.$data['name_nl'].''; ?>
<br/>
<td><input class='minuman' type='checkbox' name='add[]' value='<?php echo '<a class="btn btn-success" href="cart.php?add='.$data['code'].'" class="category">
</a>'; ?>'></td>
<p class="price"><?php echo 'RM '.$data['price']; ?></p>
</div>
</li>
<?php endwhile; ?>
</ul>
</div>
</div>
<ul class="thumbnails" align="center">
<div id="single_product" align="center">
<?php echo '<a class="btn btn-success" href="cart.php?add='.$data['code'].'" class="category">Add to Cart</a>'; ?>
</div>
</ul>
this is my code for insert cart:
if(isset($_GET['add'])){
$id = $_GET['add'];
$qt = mysql_query("SELECT code, quantity FROM product WHERE code='$id'");
while($qt_row = mysql_fetch_assoc($qt)){
if($qt_row['quantity'] != $_SESSION['cart_'.$_GET['add']] && $qt_row['quantity'] > 0){
$_SESSION['cart_'.$_GET['add']]+='1';
header("Location: keranjang.php");
} else {
echo '<script language="javascript">alert("Stok produk tidak mencukupi!"); document.location="index.php";</script>';
}
}
}
According to PHP Documentation, mysql_query is deprecated since PHP 5.5.0, and removed in PHP 7.0.0. You may use mysqli or PDO instead.
This row might cause problems, because it's not escaped:
<td><input class='minuman' type='checkbox' name='add[]' value='<?php echo '<a class="btn btn-success" href="cart.php?add='.$data['code'].'" class="category">
</a>'; ?>'></td>
and this is one of the ways to escape:
<td>
<input class="minuman" type="checkbox" name="add[]" value="<?php echo '<a class="btn btn-success" href="cart.php?add=' . $data['code'] . '" class="category"></a>'; ?>" />
</td>
About "add to cart" - You can store the products in the session or in a cookie (I think cookies can be a better option), and then show them in the cart.
I'm having this comment form. this comment form works but not correctly whenever I post comment it works on 1 post and on another it refreshes the page and data is also not inserted all the post are fetch by while loop
JS:
< script type = "text/javascript" >
$(function() {
$("#submit").click(function() {
var mcomment = $("input#mcomment").val(); // define the name variable
var mesgid = $("input#mesgid").val();
if (mcomment == '') // if name field is empty
{
alert("Write Comment Please."); // alert an error mesaage
} else {
$.ajax({ // JQuery ajax function
type: "POST", // ajax submit method
url: "status/savecomment.php",
data: 'mcomment=' + mcomment + '&mesgid=' + mesgid, // data sent to php file
cache: false,
success: function(html) { // if the result returns success
$("#comment_display").after(html);
}
});
}
return false;
});
});
< /script>
HTML:
<form method="POST" id="commentform">
<div class="panel-footer p15">
<div class="admin-form">
<img src="image.png">
<label for="reply1" >
<input name="mesgid" id="mesgid" type="hidden" value="
<?php echo $id ?>">
<input name="mcomment" id="mcomment" placeholder="Respond with a
comment." type="text" style="width:130%;">
</label>
<button type="submit" id="submit" class="button
btn-primary submit-btn" name="" style="width:90px; margin-
left:50px;">Comment</button>
</div>
</div>
</form>
here is all new edited code
<?php
$msql=mysql_query("SELECT * from `messages` ORDER BY `msg_id` DESC LIMIT
$post_limit");
while($messagecount=mysql_fetch_array($msql))
{
$id=$messagecount['msg_id'];
$msgcontent=$messagecount['message'];
$usermsg=$messagecount['username'];
$userimg=$messagecount['image'];
$userimg1=$messagecount['user_img'];
$usertime=$messagecount['time'];
?>
<i class="pointer" id="pagination-<?php echo $id;?>"></i>
<div style="display: block;" class="timeline-item" id="clone-3">
<div class="panel">
<div class="panel-heading">
<span class="panel-title" style="color:#000;"><?php echo
ucfirst($usermsg); ?> Updated a </span><a href="post.php?id=<?php echo
$id;?>">Post</a>
<span class="panel-date pull-right mr10 text-muted fs12">
<?php echo timeAgo($messagecount['time']);?> via Web</span>
</div>
<div class="panel-body">
<p><img src="image.php/<?php echo $userimg1;?>?width=60&
height=70&nocache&quality=100&image=http://localhost/niftians/profile
/upload/<?php echo $userimg1;?>" /> <?php echo
parse_smileys(make_clickable(nl2br(stripslashes($msgcontent))),
$smiley_folder); ?><br><br><?php if(!empty($messagecount['image'])) { ?>
<img src="status/image.php/<?php echo
$messagecount['image'];?>?width=350&nocache&quality=100&
image=http://localhost/niftians/profile/upload/<?php echo
$messagecount['image'];?>" style="margin-left:10%;">
<?php } ?></p>
</div>
</div>
</div>
<?php
$sql=mysql_query("select * from comments where msg_id_fk='$id' order by
com_id");
$comment_count=mysql_num_rows($sql);
if($comment_count>2)
{
$second_count=$comment_count-2;
?><div class="comment_ui" id="view<?php echo $id; ?>">
<div>
<a href="#" class="view_comments" id="<?php echo $id; ?>">View all <?php
echo $comment_count; ?> comments</a>
</div>
</div>
<?php
}
else
{
$second_count=0;
}
?>
<div id="view_comments<?php echo $id; ?>"></div>
<div id="two_comments<?php echo $id; ?>">
<?php
$listsql=mysql_query("select * from comments where msg_id_fk='$id' order
by com_id limit $second_count,2 ");
while($rowsmall=mysql_fetch_array($listsql))
{
$c_id=$rowsmall['com_id'];
$comment=$rowsmall['comments'];
$userid3=$rowsmall['username'];
$userimg5=$rowsmall['user_img'];
$usercom=$rowsmall['time'];
?> <div id="comment_display"></div>
<div class="media mt15" id="aniket">
<a class="pull-left" href="#"> <img class="media-
object thumbnail thumbnail-sm rounded mw40" src="image.php/<?php echo
$userimg5;?>?width=60&height=60&nocache&quality=100&
image=http://localhost
/niftians/profile/upload/<?php echo $userimg5;?>" alt="..."> </a>
<div class="media-body mb5">
<h5 class="media-heading mbn"><a href="<?php echo
$userid3; ?>"><?php echo ucfirst($userid3); ?></a>
<small> -<?php echo timeAgo($rowsmall['time']);?>
</small>
</h5>
<p><?php echo
parse_smileys(make_clickable(nl2br(stripslashes($comment))),
$smiley_folder); ?></p>
</div>
</div>
<?php } ?>
</div>
<form method="POST" id="commentform">
<div class="panel-footer p15">
<div class="admin-form">
<img src="image.php/<?php echo $info->img;?>?width=45&nocache&
quality=100&image=http://localhost/niftians/profile/upload/<?php echo
$info->img;?>">
<label for="reply1" >
<input name="mesgid" id="mesgid" type="hidden" value="<?php echo $id ?>">
<input name="mcomment" id="mcomment" placeholder="Respond with a
comment." type="text" style="width:130%;">
</label>
<button type="submit" id="submit" class="button
btn-primary submit-btn" name="" style="width:90px; margin-
left:50px;">Comment</button>
</div>
</div>
</form>
<br>
<?php
}
?>
What you need to do is
Remove Submit Button and add <input type="button">
2nd create a div in your page named as <div id="comment_display"></div>
And if this does not solve problem, post your While loop.
Replace this line
$("#submit").click(function() {
with
$("#submit").on('.submit','click',function(e) {
e.preventDefault();
Note: Your submit can work too, but you would have to stop its default behavior using jquery
Rephrased Question:
I'm updating a web app from a stand alone PHP page to something that is database driven and has admin controls (old page: uoflclimbingclub.com/everestchallenge/elevationcounter/).
I'm using a form on two different pages: an admin page, and a display page. The form sends the value of a hidden input into a variable on the display page that defines a field name in an sql statement.
The returned row of data is used on the display page with a combination of CSS and PHP to display a graph. The display page is also where the data is meant to be updated.
The code executes and displays the page successfully when executed from the admin page, but fails to display the page when executed from the same page, even though the data is successfully updated in the database. Can anyone tell me what I'm doing wrong? I've searched everything I can think of and read PHP documentation to find a solution but no luck so far, I'm still looking for a solution, any help would be much appreciated.
My Code
The admin page that links to the display page: http://shemsimmons.com/uoflclimbingclub/everestchallenge/admin
Here is the code for the display page: setteam.php
<?php
ob_start();
include $_SERVER["DOCUMENT_ROOT"].'/uoflclimbingclub/everestchallenge/inc/conn/ulcc_user.php';
$team = mysqli_real_escape_string($con, $_POST['teamname']);
$increment = "/uoflclimbingclub/images/icons/favicon.png";
$getElevation = "SELECT * FROM everest2014 WHERE team= '$team'";
$result = mysqli_query($con, $getElevation);
echo "The Team Name is:";
echo $team;
while($climbs = mysqli_fetch_assoc($result)){
if(isset($_POST['update'])){
foreach ($_POST as $key => $value){
$$key=$value;
}
$updateElevation = "UPDATE everest2014
SET
rope1=$rope1Climbs,
rope2=$rope2Climbs,
rope3=$rope3Climbs,
rope4=$rope4Climbs,
rope5=$rope5Climbs,
rope6=$rope6Climbs,
rope7=$rope7Climbs,
rope8=$rope8Climbs,
rope9=$rope9Climbs,
rope10=$rope10Climbs,
rope11=$rope11Climbs,
rope12=$rope12Climbs,
rope13=$rope13Climbs
WHERE team='$team'";
$retval = mysqli_query($con, $updateElevation);
if(! $retval ){
die('Could not update data: ' . mysqli_error());
}
header('Location: '.$_SERVER['PHP_SELF']);
mysqli_close($conn);
} else {
?>
<!DOCTYPE html>
<html>
<head>
<title>TEAM <?php echo $team; ?> Counter</title>
<link rel="icon" type="image/png" href="/uoflclimbingclub/images/icons/favicon.png">
<link rel="stylesheet" type="text/css" href="/uoflclimbingclub/everestchallenge/css/elevationstyle.php" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="/uoflclimbingclub/everestchallenge/js/adder.js"></script>
<script type="text/javascript" src="/uoflclimbingclub/everestchallenge/js/jscolor/jscolor.js"></script>
<style>
.point {
border-bottom: 25px solid <?php echo $climbs["colour"]; ?>;
}
.shaft, #teambg{
background: <?php echo $climbs["colour"]; ?>;
}
</style>
</head>
<body>
<?php
include $_SERVER["DOCUMENT_ROOT"].'/uoflclimbingclub/everestchallenge/inc/everestVar.php';
include $_SERVER["DOCUMENT_ROOT"].'/uoflclimbingclub/everestchallenge/inc/set_elevation_inc.php';
?>
</body>
</html>
<?php
}
}
mysqli_free_result($result);
?>
The everestVar.php include is just a bunch of simple arithmetic that makes the styles look pretty (div heights, convert number of rope climbs into total metres climbed, etc...)
The other include is the body html:
<!-- Graphic of Everest -->
<img src="/uoflclimbingclub/everestchallenge/img/summit.png">
<div id="everestwrapper"><div id="everestwrap">
<div id="everest"><img src="/uoflclimbingclub/everestchallenge/img/elevationmetre.png"><div id="metres" style="bottom:<?php echo $elevation; ?>%;"><span id="elevation"><?php echo $elevationClimbed; ?></span><img src="/uoflclimbingclub/everestchallenge/img/metres.png"></div></div>
<div id="lightbg"></div>
<div id="teambg" class="everestfill" style="height:<?php echo $elevation; ?>%;"></div>
</div></div>
<img src="/uoflclimbingclub/everestchallenge/img/eventname.png">
<!-- Growing Rope Arrows -->
<div id="ACC">
<form id="climbsInput" action="/uoflclimbingclub/everestchallenge/setteam.php" method="post">
<div id="medWall" class="medWall">
<div id="rope1" style="height:<?php echo $rope1Up; ?>%;">
<div class="point"><?php echo $rope1 ?>m</div>
<div class="shaft">1</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope1Climbs" value="<?php echo $climbs["rope1"]; ?>" /></div></div>
<div id="rope2" style="height:<?php echo $rope2Up; ?>%;">
<div class="point"><?php echo $rope2 ?>m</div>
<div class="shaft">2</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope2Climbs" value="<?php echo $climbs["rope2"]; ?>" /></div></div>
<div id="rope3" style="height:<?php echo $rope3Up; ?>%;">
<div class="point"><?php echo $rope3 ?>m</div>
<div class="shaft">3</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope3Climbs" value="<?php echo $climbs["rope3"]; ?>" /></div></div>
<div id="rope4" style="height:<?php echo $rope4Up; ?>%;">
<div class="point"><?php echo $rope4 ?>m</div>
<div class="shaft">4</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope4Climbs" value="<?php echo $climbs["rope4"]; ?>" /></div></div>
<div id="rope5" style="height:<?php echo $rope5Up; ?>%;">
<div class="point"><?php echo $rope5 ?>m</div>
<div class="shaft">5</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope5Climbs" value="<?php echo $climbs["rope5"]; ?>" /></div></div>
</div>
<div id="longWall" class="tallWall">
<div id="rope6" style="height:<?php echo $rope6Up; ?>%;">
<div class="point"><?php echo $rope6 ?>m</div>
<div class="shaft">6</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope6Climbs" value="<?php echo $climbs["rope6"]; ?>" /></div></div>
<div id="rope7" style="height:<?php echo $rope7Up; ?>%;">
<div class="point"><?php echo $rope7 ?>m</div>
<div class="shaft">7</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope7Climbs" value="<?php echo $climbs["rope7"]; ?>" /></div></div>
<div id="rope8" style="height:<?php echo $rope8Up; ?>%;">
<div class="point"><?php echo $rope8 ?>m</div>
<div class="shaft">8</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope8Climbs" value="<?php echo $climbs["rope8"]; ?>" /></div></div>
</div>
<div id="shortWall" class="shortWall">
<div id="rope9" style="height:<?php echo $rope9Up; ?>%;">
<div class="point"><?php echo $rope9 ?>m</div>
<div class="shaft">9</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope9Climbs" value="<?php echo $climbs["rope9"]; ?>" /></div></div>
<div id="rope10" style="height:<?php echo $rope10Up; ?>%;">
<div class="point"><?php echo $rope10 ?>m</div>
<div class="shaft">10</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope10Climbs" value="<?php echo $climbs["rope10"]; ?>" /></div></div>
<div id="rope11" style="height:<?php echo $rope11Up; ?>%;">
<div class="point"><?php echo $rope11 ?>m</div>
<div class="shaft">11</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope11Climbs" value="<?php echo $climbs["rope11"]; ?>" /></div></div>
<div id="rope12" style="height:<?php echo $rope12Up; ?>%;">
<div class="point"><?php echo $rope12 ?>m</div>
<div class="shaft">12</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope12Climbs" value="<?php echo $climbs["rope12"]; ?>" /></div></div>
<div id="rope13" style="height:<?php echo $rope13Up; ?>%;">
<div class="point"><?php echo $rope13 ?>m</div>
<div class="shaft">13</div>
<div class="climbCounter ropeInput"><img src="<?php echo $increment; ?>" class="addClimb" /><input type="text" class="climbs" name="rope13Climbs" value="<?php echo $climbs["rope13"]; ?>" /></div></div>
</div>
<?php echo "<input type='hidden' name='teamname' value='" . $climbs['team'] . "' />"; ?>
<div style="clear:both;padding-top:80px;"><input name="update" type="submit" value="Update Elevation"/></div>
</form>
</div><!-- End ACC -->
Original Question:
I have some code that works and doesn't work. It works when executed from an external page, but doesn't work when executed from the same page.
<input type='hidden' name='name' value='value' />
The input above is passing a value to a PHP page that loads data from an SQL database. The value is stored in a variable that is used in a couple SQL statements.
$name = mysqli_real_escape_string($con, $_POST['name']);
$select = "SELECT * FROM table WHERE `name`= '$name'";
$update = "UPDATE table SET (multiple fields) WHERE `name`='$name'";
It works perfect from the external page, but when I try to update the data from the same page, using the same input field then strange things happen. The value does not appear to be being passed, but somehow the database is successfully updating.
When I say it doesn't appear to be being passed I mean I've put echo statements all over my code to find where it's breaking and no where does that variable have a value, the page loads blank as if the variable had no value, the page is not displaying (content and styles depend on the database), but for some reason the data is successfully being sent. I can hit the back button on my browser and refresh the page and the data refreshes to show the updates.
I can't wrap my head around why the variable would work for the outgoing data, but not for the incoming data, and show no value. Does anyone have any initial clues as to what might be going on?
If the page refreshes to show the updates when you hit the back button, then refreshing the page would be the solution.
To refresh the page, the following PHP code should work:
header('Location: currentURL');
Check the action atributte in the form element. Make sure it is set to the name of the file you are working on.
The page is blank because there is an internal error with your php script. Until you fix the problem, nothing is going to be displayed.
Try this..
if ($_POST['submit']){
... code to update database here...
}
Is there a way to echo the short description foreach related product?
I've tried to use this code but it doesn't display the description of each product:
<?php echo nl2br($this->getProduct()->getDescription()) ?>
also
<?php echo $_helper->productAttribute($_item, nl2br($_item->getShortDescription()), 'short_description') ?>
Is there a way to do this for related products? If anyone knows please point me in the right direction.
<?php if($this->getItems()->getSize()): ?>
<div class="block block-related">
<div class="block-title">
<strong><span><?php echo $this->__('Related Products') ?></span></strong>
</div>
<div class="block-content">
<p class="block-subtitle"><?php echo $this->__('Check items to add to the cart or add to your wishlist') ?> <br /></p>
<div class="form-horizontal">
<?php foreach($this->getItems() as $_item): ?>
<div class="control-group">
<label for="related-checkbox<?php echo $_item->getId() ?>" class="control-label">
<a class="fancybox static-thumbs pull-left" href="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(500, 450); ?>" title="<?php echo $this->htmlEscape($_item->getName()) ?>" ><img src="<?php echo $this->helper('catalog/image')->init($_item, 'small_image')->resize(135, 135) ?>" width="135" height="135" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" /></a>
</label>
<div class="controls">
<label class="checkbox">
<?php if(!$_item->isComposite() && $_item->isSaleable()): ?>
<?php if (!$_item->getRequiredOptions()): ?>
<input type="checkbox" class="checkbox related-checkbox" id="related-checkbox<?php echo $_item->getId() ?>" name="related_products[]" value="<?php echo $_item->getId() ?>" />
<?php endif; ?>
<?php endif; ?>
<?php if ($this->helper('wishlist')->isAllow()) : ?>
<span class="icon-check"></span>
<p class="product-name span6">
<?php echo $this->htmlEscape($_item->getName()) ?>
<br />
<?php echo nl2br($this->getProduct($_item)->getDescription()) ?>
</p>
<form action="<?php echo $this->getAddToCartUrl($_item) ?>" method="post">
<fieldset>
<label class="product-name"><?php echo $this->__('Quantity:'); ?></label>
<select name="qty" class="span1">
<?php $i = 1 ?>
<?php do { ?>
<option value="<?php echo $i?>">
<?php echo $i?>
<?php $i++ ?>
</option>
<?php } while ($i <= (int)Mage::getModel('cataloginventory/stock_item')->loadByProduct($_item)->getMaxSaleQty()) ?>
</select>
<div class="clearfix"></div>
<button class="btn btn-danger" data-loading-text="PLease wait..."><span><?php echo $this->__('Add to Cart') ?></span></button>
<span id='ajax_loader' style='display:none'><img src='<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif')?>'/></span>
</fieldset>
</form>
<?php endif; ?>
<?php echo $this->getPriceHtml($_item, true, '-related') ?>
</label>
</div>
</div>
<hr />
<?php endforeach ?>
</div>
</div>
Have you tried nl2br($this->getProduct($_item)->getShortDescription()) ?
It might be that the value for short description isn't loaded for related products by default. You could try to do a $_item->load($_item->getId()) and then use $_item->getShortDescription().
after TRYING $_item->load($_item->getId()) and echoing the shortDescription, you should look for the Collection where the related products are loaded. In this collection the attribute short_description is not loaded with.
If you load every product, you make a lot of queries to the database which will cost a lot of performance. This is not needed. The alternative is:
$relatedProductCollection->addAttributeToSelect('short_description');
The question is to find the $relatedProductCollection.
UPDATE:
I dug into the code (Reference is v. 1.7.0.2):
// app/code/core/Mage/Catalog/Block/Product/List/Related.php:61
$this->_addProductAttributesAndPrices($this->_itemCollection);
// app/code/core/Mage/Catalog/Block/Product/Abstract.php:410
$collection
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes())
// app/code/core/Mage/Catalog/Model/Config.php:260
$this->getAttributesUsedInProductListing()
This should be interpreted as: When the "related products" are loaded, all attributes are loaded, which are used in the product listing as well. The problem might be: short_desciption is loaded by default. So remove the load() call and check, wether the attribute short_description is "Used in Product Listing". If this is set to yes, My interpretation is wrong.
None the less, the solution by loading every product is crap.
EDIT:
I have added the following line to Related.php
$this->_itemCollection = $product->getRelatedProductCollection()
->addAttributeToSelect('required_options')
->addAttributeToSelect('short_description')
->setPositionOrder()
->addStoreFilter()
And using this line does echo a descrtiption foreach product but it is the Same description getProduct()->getDescription()) ?>
You need to <?php echo ($this->getProduct()->getShortDescription()) ?>
But editing the core code is a bad way to change the magento behaviour as well. Here is described how to rewrite a block, but I don't think this is necessary. http://prattski.com/2010/06/24/magento-overriding-core-files-blocks-models-resources-controllers/