I would greatly enjoy knowing how to separate the results of my query based on the "season" using PHP only. The products should be placed in separate divs according to what season they are for. I would also like to do this in the most efficient way possible. I have thought about his for some time and have failed both in a solution and in finding someone else's similar results on the internet. Please ignore the jquery, it is a leftover for something I may or may not use.
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>Shop</title>
<link rel="stylesheet" type="text/css" href="style/main.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0
/jquery.min.js"></script>
<script type="text/javascript" src="script/jquery.simplyscroll.min.js"></script>
<script type="text/javascript">
(function($) {
$(function() {
$("#scroller").simplyScroll();
});
})(jQuery);
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="menu">
<ul>
<li>Home</li>
<li>About</li>
<li>Shop</li>
<li>Contact</li>
</ul>
</div>
</div>
<div id="content">
<?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode("http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
//$results = $db->query('SELECT id, name, thumb, description, price, season FROM products
BY season ASC');
foreach($db->query('SELECT id, name, thumb, description, price FROM products BY season
ASC') as $results){
if ($results) {
//output results from database
$last_season = 1;
echo '<div class="products">';
while($obj = $results->fetch_object())
{
if ($last_season != $obj->season){
echo '</div><div class="products">';
}
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="image/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">Price '.$currency.$obj->price.' <button
class="add_to_cart">Add To Cart</button></div>';
echo '</div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
$last_season = $obj->season;
}
echo '</div>';
}
}
?>
<div id="shopping-cart">
<h2>Your Shopping Cart</h2>
<?php
if(isset($_SESSION["products"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["products"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm"><a href="cart_update.php?removep='.$cart_itm["code"].'&
return_url='.$current_url.'">×</a></span>';
echo '<h3>'.$cart_itm["name"].'</h3>';
echo '<div class="p-code">P code : '.$cart_itm["code"].'</div>';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div class="p-price">Price :'.$currency.$cart_itm["price"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt"><strong>Total : '.$currency.$total.'</strong> Check-out!</span>';
echo '<span class="empty-cart"><a href="cart_update.php?emptycart=1&
return_url='.$current_url.'">Empty Cart</a></span>';
}else{
echo 'Your Cart is empty';
}
?>
</div>
</div>
<div id="footer">Footer goes here.</div>
</div>
</body>
</html>
I am getting an error on line 44, which is the start of the "foreach" statement. I am again at a loss. Thank you a ton for your help so far. If I can get this working, with help of course, I will be extremely excited and in your debt.
Here's a loop that will create a new div each time the season changes in a new row. You will need to change the query to order the results by season, e.g.
ORDER BY season ASC
Here's the loop:
if ($results) {
//output results from database
$last_season = 1; //initial value
echo '<div class="season">'; //opens first season div
while($obj = $results->fetch_object()){
if ($last_season != $obj->season){
echo '</div><div class="season">';
}
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-thumb"><img src="image/'.$obj->product_img_name.'"></div>';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-desc">'.$obj->product_desc.'</div>';
echo '<div class="product-info">Price '.$currency.$obj->price.' <button class="add_to_cart">Add To Cart</button></div>';
echo '</div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
$last_season = $obj->season;
}
echo '</div>'; //closes final season div
}
Regarding the line 44 error in the foreach, I believe what you want there instead of a foreach is simply:
$results = $db->query('SELECT id, name, thumb, description, price FROM products BY season
ASC'); //remember to remove the closing bracket of the foreach
Related
I'm not seeing what goes wrong here? I want to allow my users to up the quantity from an item in their shopping cart. when they press enter I want the quantity to change from 1 to the number the use rput in and I want that it calculates everything correctly. but right now it only wants to update the last item that the user changed the quantity from. how do I fix this? I thought of using a $_SESSION but that doesn't make any difference. this is part of the code
<body>
<!--navbar-->
<a class="back" href="index.php"> <i class="bi bi-arrow-left-circle-fill bi-5x"></i></a>
<?php
include "config.php";
?>
<div class="text-center" style="font-size: 100px;">🛍</div>
<h2 class="text-center">Winkelmandje</h2><br>
<section class="container content-section">
<!-- <h2 class="section-header">CART</h2> -->
<div class="cart-row">
<span class="cart-item cart-header cart-column">ITEM</span>
<span class="cart-item cart-header cart-column">PRICE</span>
<span class="cart-item cart-header cart-column">QUANTITY</span>
<span class="cart-item cart-header cart-column">berekening</span>
<!-- <span class="cart-item cart-header cart-column">Verwijderen</span> -->
</div>
<?php
$broodjes = $_GET['broodjes_ID'];
if (isset($_SESSION['basket'])){
if( in_array( $broodjes ,$_SESSION['basket']) )
{
}else{
$_SESSION['basket'][] = $broodjes;
}
}else{
$_SESSION['basket'][]= $broodjes;
}
$sumtotal = 0;
foreach($_SESSION['basket'] as $key => $value){
//echo "Key = $key; value = $value; <br>";
$sql = "SELECT broodjes_ID, broodnaam, prijs, voorraad FROM broodjes WHERE broodjes_ID=?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $value);
$stmt->execute();
$result = $stmt->get_result();
while($row = $result->fetch_assoc()){
echo '<div class="cart-items">';
echo '<div class="cart-row">';
echo '<div class="cart-item cart-column">';
echo $row['broodnaam'];
echo '</div>';
echo '<div class="cart-item cart-column">';
echo '€ ' . $row['prijs'];
echo '</div>';
//quantity
echo '<div class="cart-item cart-column">';
echo '<form method="POST" action"">';
echo '<div class="col-xs-4">';
echo '<input type="hidden" name="broodnaam" id="broodnaam" value="' . $row['broodnaam'] . '">';
echo '<input type="number" name="quantity" id="quantity" class="form-control input-sm" placeholder="1" min="1" max="100" value="1">';
echo '</div>';
echo '</form>';
echo '</div>';
//session for quantity???'
$_SESSION['quantity'] = $_POST['quantity'];
$quantity = 1;
if (isset($_POST['quantity']) && !empty($_POST['quantity'])){
$_SESSION['quantity'] = $_POST['quantity'];
if (isset($_POST['broodnaam']) && !empty($_POST['broodnaam'])){
if ($_POST['broodnaam'] == $row['broodnaam']){
$quantity = $_POST['quantity'];
}
}
}
echo '<div class="cart-item cart-column">';
$rowtotaal = $row['prijs'] * $quantity;
$sumtotal += $rowtotaal;
echo $rowtotaal;
echo '</div>';
echo '</div>';
echo '</div>';
}
}
?> <br />
<div class="cart-total">
<strong class="cart-total-title">Total</strong>
<span class="cart-total-price"> € <?php echo $sumtotal;?></span>
</div>
<br/>
and this is what it does
now situation:
how do I store the information in a session??
i have the following code:
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View shopping cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css"></head>
<body>
<br>
<div id="books-wrapper">
<!-- #content to center the menu -->
<div id="content">
<!-- This is the actual menu -->
<ul id="darkmenu">
<li>Home</li>
<li>Catalogue</li>
<li>Search</li>
<li>Cart</li>
<li>Orders</li>
</ul>
<div id = "welcome" >
Welcome, <?=$_SESSION['login_user']?>! <br> Logout
</div>
</div>
<br><br>
<h1 id = "mainHeader" >View Cart</h1>
<br>
<div class="view-cart">
<?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["books"]))
{
$total = 0;
echo '<form method="post" action="">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["books"] as $cart_itm){
$ISBN = $cart_itm["ISBN"];
$results = $mysqli->query("SELECT Title,BookDesc,Price FROM books WHERE ISBN='$ISBN'");
$obj = $results->fetch_object();
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<div class="p-Price">'.$currency.$obj->Price.'</div>';
echo '<div class="book-info">';
echo '<h3>'.$obj->Title.' (ISBN :'.$ISBN.')</h3> ';
echo '<div class="p-quantity">Quantity : '.$cart_itm["quantity"].'</div>';
echo '<div>'.$obj->BookDesc.'</div>';
echo '</div>';
echo '</li>';
$subtotal = ($cart_itm["Price"]*$cart_itm["quantity"]);
$total = ($total + $subtotal);
echo '<input type="hidden" name="item_name['.$cart_items.']" value="'.$obj->Title.'" />';
echo '<input type="hidden" name="item_code['.$cart_items.']" value="'.$ISBN.'" />';
echo '<input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj->BookDesc.'" />';
echo '<input type="hidden" name="item_quantity['.$cart_items.']" value="'.$cart_itm["quantity"].'" />';
$cart_items ++;
}
echo '</ul>';
echo '<span class="check-out-txt">';
echo '<strong>Total : '.$currency.$total.'</strong> ';
echo '</span>';
echo '<button name="submit_btn" class="save_order">Save Order</button>';
echo '</form>';
if(isset($_POST['submit_btn']) ){
$insquery = "INSERT INTO `pending_orders` (`OrderNo`,`BookName`,`Quantity`,`TotalPrice`,`ISBN`,`StudentID`) VALUES (NULL, '" . $obj->Title . "', '" . $cart_itm['quantity'] . "', '" . $total . "', '" . $ISBN . "', '" . $_SESSION['login_user'] . "');";
$stmt = $mysqli->prepare($insquery);
$stmt->execute();
}
}
?>
</div>
</div>
</body>
</html>
The code is supposed to save a customers book order into a database, It works perfectly fine for ONE book. Line 76 to 81 has the insert statement.
however if the person has purchased two books then only the last book gets added to the database. Screenshots added:
This is what it looks like on my website. As you can see the person has selected two books to be purchased:
http://postimg.org/image/3kj1gvytx/
However this is what i get in my phpmyadmin site:
http://postimg.org/image/k85hs56xj/
We can see that only the second book (biology) gets stored in the database. as well as the total of the two books
Any ideas how i could fix the issue and store both books.
Thanks
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>View shopping cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css"></head>
<body>
<br>
<div id="books-wrapper">
<!-- #content to center the menu -->
<div id="content">
<!-- This is the actual menu -->
<ul id="darkmenu">
<li>Home</li>
<li>Catalogue</li>
<li>Search</li>
<li>Cart</li>
<li>Orders</li>
</ul>
<div id = "welcome" >
Welcome, <?=$_SESSION['login_user']?>! <br> Logout
</div>
</div>
<br><br>
<h1 id = "mainHeader" >View Cart</h1>
<br>
<div class="view-cart">
<?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["books"]))
{
$total = 0;
echo '<form method="post" action="">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["books"] as $cart_itm){
$ISBN = $cart_itm["ISBN"];
$results = $mysqli->query("SELECT Title,BookDesc,Price FROM books WHERE ISBN='$ISBN'");
$obj = $results->fetch_object();
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<div class="p-Price">'.$currency.$obj->Price.'</div>';
echo '<div class="book-info">';
echo '<h3>'.$obj->Title.' (ISBN :'.$ISBN.')</h3> ';
echo '<div class="p-quantity">Quantity : '.$cart_itm["quantity"].'</div>';
echo '<div>'.$obj->BookDesc.'</div>';
echo '</div>';
echo '</li>';
$subtotal = ($cart_itm["Price"]*$cart_itm["quantity"]);
$total = ($total + $subtotal);
echo '<input type="hidden" name="itemname_['.$cart_items.']" value="'.$obj->Title.'" />';
echo '<input type="hidden" name="itemcode_['.$cart_items.']" value="'.$ISBN.'" />';
echo '<input type="hidden" name="itemdesc_['.$cart_items.']" value="'.$obj->BookDesc.'" />';
echo '<input type="hidden" name="itemquantity_['.$cart_items.']" value="'.$cart_itm["quantity"].'" />';
echo '<input type="hidden" name="total_['.$cart_items.']" value="'.$total.'" />';
$cart_items ++;
}
echo '</ul>';
echo '<span class="check-out-txt">';
echo '<strong>Total : '.$currency.$total.'</strong> ';
echo '</span>';
echo '<button name="submit_btn" class="save_order">Save Order</button>';
echo '</form>';
if(isset($_POST['submit_btn']) ){
$item_array = array();
foreach($_POST as $key => $value) {
// echo "POST parameter '$key' has '$value';
$pieces = explode("_",$key)
if(strstr($pieces[0] == 'itemname')
{
$item_array[$pieces[1]]['BookName'] = $value;
}
if(strstr($pieces[0] == 'itemcode')
{
$item_array[$pieces[1]]['ISBN'] = $value;
}
if(strstr($pieces[0] == 'itemquantity')
{
$item_array[$pieces[1]]['Quantity'] = $value;
}
if(strstr($pieces[0] == 'total')
{
$item_array[$pieces[1]]['TotalPrice'] = $value;
}
}
$insquery = "INSERT INTO `pending_orders` (`OrderNo`,`BookName`,`Quantity`,`TotalPrice`,`ISBN`,`StudentID`) VALUES ";
foreach($item_array as $row)
{
$insquery .= "(NULL, '" . $row['BookName'] . "', '" . $row['Quantity'] . "', '" .$row['TotalPrice']. "', '" . $row['ISBN'] . "', '" . $_SESSION['login_user'] . "'),";
}
$insquery = substr($insquery, 0, -1);
$stmt = $mysqli->prepare($insquery);
$stmt->execute();
foreach($_POST as $row)
$insquery = "INSERT INTO `pending_orders` (`OrderNo`,`BookName`,`Quantity`,`TotalPrice`,`ISBN`,`StudentID`) VALUES (NULL, '" . $obj->Title . "', '" . $cart_itm['quantity'] . "', '" . $total . "', '" . $ISBN . "', '" . $_SESSION['login_user'] . "');";
$stmt = $mysqli->prepare($insquery);
$stmt->execute();
}
}
?>
</div>
</div>
</body>
</html>
you form the insert statement like above
As you don't know Ajax, you can do something like this:
1) Reset $result array, to select items again for MySQL query.
2) With while loop insert each selected value into DB.
reset($result);
while($row=mysqli_fetch_array($result))
{
$ins = mysqli_query($con, "Here goes insert statement for each");
}
EDIT
$ISBN = $cart_itm["ISBN"];
$con = mysqli_connect("localhost","root","","yourbasename");
$result = mysqli_query($con, "SELECT Title,BookDesc, Price FROM books
WHERE ISBN='$ISBN'");
while($row=mysqli_fetch_array($result)
{
$insert = mysqli_query($con, "INSERT.....");
}
HI I wanted to know how to restart a session in php. When I use the code given below in one of my pages it would work for the 1st time. When I refresh the page the previous session continues. So how can I start a new session when the page reloads?Thanks for the quick response.INCLUDED WHOLE CODE TO MAKE THINGS CLEAR
<?php
session_start();
include_once("config.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Shopping Cart</title>
<link href="style/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="products-wrapper">
<h1>Products</h1>
<div class="products">
<?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$results = $mysqli->query("SELECT * FROM shop ORDER BY product_code ASC");
if ($results) {
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
echo '<div class="product">';
echo '<form method="post" action="cart_update.php">';
echo '<div class="product-content"><h3>'.$obj->product_name.'</h3>';
echo '<div class="product-info">';
echo 'Price '.$currency.$obj->price.' | ';
echo 'Qty <input type="text" name="product_qty" value="0" size="3" />';
echo '<button class="add_to_cart">Add To Cart</button>';
echo '</div></div>';
echo '<input type="hidden" name="product_code" value="'.$obj->product_code.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
}
}
?>
</div>
<div class="shopping-cart">
<h2>Your Shopping Cart</h2>
<?php
if(isset($_SESSION["shop"]))
{
$total = 0;
echo '<ol>';
foreach ($_SESSION["shop"] as $cart_itm)
{
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<h3>'.$cart_itm["name"].'</h3>';
echo '<div class="p-code"></div>';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div class="p-price">Price :'.$currency.$cart_itm["price"].'</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '</ol>';
echo '<span class="check-out-txt"><strong>Total : '.$currency.$total.'</strong> Check-out!</span>';
echo '<span class="empty-cart">Empty Cart</span>';
}else{
echo 'Your Cart is empty';
}
?>
</div>
</div>
</body>
</html>
You may use session_destroy function in the end of your file.
<?php
session_start();
include_once("config.php");
/*your code*/
session_destroy();
?>
session_destroy — Destroys all data registered to a session
bool session_destroy ( void )
http://php.net/manual/en/function.session-destroy.php
You need to use session_destroy(); to destry a session and then you can start a new one
try to remove session first and start again
if(session_id() != '' || isset($_SESSION)) {
session_destroy();
session_start();
}
else {
session_start();
}
You have to destroy the session after your event.
<?php
session_start();
include_once("config.php");
//after doing your task with the session variable destroy session
session_destroy();
?>
<?php
#session_destroy(); // destroy session if exists
session_start();
include_once("config.php");
?>
UPDATE 2 :
<?php
if(isset($_SESSION))
{
session_destroy(); // destroy session if exists
}
session_start();
include_once("config.php");
?>
UPDATE 3 :
If you want to unset only $_SESSION['shop'] after using it
if(isset($_SESSION["shop"]))
{
// your code
unset($_SESSION['shop']); // unset your session after using it
}else{
echo 'Your Cart is empty';
}
I am trying to paginate my PHP page by ten results per page. Currently the page shows all results at once. I did look up some tutorials on pagination but I cannot seem to figure out how to implement them into the current PHP page. The PHP page is called view_cart.php and it essentially retrieves the cached products that were added by the user via a shopping cart page and displays them on this page. I am just looking for a few hints to point me in the right direction, not for someone to do my work for me.
This is the view_cart.php page code:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
session_start();
include_once("config.php");
if(isset($_SESSION["products"]))
{
$total = 0;
echo '<form method="post" action="PAYMENT-GATEWAY">';
echo '<ul>';
$cart_items = 0;
foreach ($_SESSION["products"] as $cart_itm)
{
$product_code = $cart_itm["code"];
$queryy = "SELECT TOP 1 product_name,product_desc, price FROM products WHERE product_code='$product_code'";
$results = mssql_query($queryy, $mysqli);
$obj = mssql_fetch_object($results);
echo '<li class="cart-itm">';
echo '<span class="remove-itm">×</span>';
echo '<div class="p-price">'.$currency.$obj->price.'</div>';
echo '<div class="product-info">';
echo '<h3>'.$obj->product_name.' (Code :'.$product_code.')</h3> ';
echo '<div class="p-qty">Qty : '.$cart_itm["qty"].'</div>';
echo '<div>'.$obj->product_desc.'</div>';
echo '</div>';
echo '</li>';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
echo '<input type="hidden" name="item_name['.$cart_items.']" value="'.$obj->product_name.'" />';
echo '<input type="hidden" name="item_code['.$cart_items.']" value="'.$product_code.'" />';
echo '<input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj->product_desc.'" />';
echo '<input type="hidden" name="item_qty['.$cart_items.']" value="'.$cart_itm["qty"].'" />';
$cart_items ++;
}
echo '</ul>';
echo '<span class="check-out-txt">';
echo '<strong>Total : '.$currency.$total.'</strong> ';
echo '</span>';
echo '</form>';
echo 'Checkout';
}else{
echo 'Your Cart is empty';
}
?>
<?php
date_default_timezone_set('America/Edmonton');
?>
<?php echo date("D M d, Y G:i a"); ?>
</body>
</html>
This is the config.php page code:
<?php
$mysqli = mssql_connect('gd','Gad','Rdgaf!');
$objConnectee = mssql_select_db('Gdaddf',$mysqli );
?>
Thank you for any help. All help is appreciated.
You will have url parameters: start and count.
Use them in the sql query, like LIMIT $_GET['start'], $_GET['count']
The last thing is to render links to the "Next" and "Previous" page. (and to "First", "Last", 1,2,3,4....). Those links will include parameters start and count.
For example, the "Next" link will contain url with parameters:
"view_cart.php?start=" . ($_GET['start'] + $_GET['count']) . "&count=" . $_GET['count']
Beware of the total record count to not overflow.
Hi I would like to order custom fields in wordpress. I've got it displaying the single project. But can't figure out how I can get it to display in order. I've created a field called project_order which works correctly on another page.
But i'm not used to this sort of php with order by. This is a project designed by someone else so i'm trying to pick up and learn how it was built.
<?php
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
?>
I'm guessing it will have something to do with.
$rows = get_field('projects', $sector [$post->post_name]);
Try below code, may be this resolve your problem.
<?php
wp_reset_query();
//associate sector to product projects page
$sector['construction'] = 131;
$sector['timber-frame'] = 235;
$sector['industrial'] = 253;
$sector['agriculture'] = 263;
//link to view all projects for product
echo '<p>View all projects</p>';
?>
</div>
<div class="span5">
<div id="latestproject">
<h2>Latest Project</h2>
<?php
//get latest projects
$rows = get_field('projects', $sector [$post->post_name] , '&order=ASC');
//display latest project
if ($rows) {
echo '<div class="row">';
if ($rows[0]['project_pageturner']) {
echo '<a href="'.$rows[0]['project_pageturner'].'" target="_blank">';
} else if ($rows[0]['project_pdf']) {
echo '<a href="'.wp_get_attachment_url($rows[0]['project_pdf']).'" target="_blank">';
} else {
echo "<a href=\"javascript:alert('No PDF uploaded for this item.')\">";
}
echo '<div class="span2">';
if ($rows[0]['project_thumbnail']) {
echo wp_get_attachment_image($rows[0]['project_thumbnail'], 'full');
} else {
echo '<img src="'.get_bloginfo('template_directory').'/images/defaultproject.jpg" alt="">';
}
echo '</div>';
echo '<div class="span3">';
echo '<p><strong>'.$rows[0]['project_title'].'</strong></p>';
echo '<p>View project »</p>';
echo '</div>';
echo '</a>';
echo '</div><!--row-->';
} else {
echo '<p>No projects to display currently.</p>';
}
wp_reset_query();
?>
Thanks.