Hello I am trying to push in an array using array_push but I am getting the value of the first index then after that all I am getting a null response, I am not getting where I have done a mistake.I am getting the values properly but in array_push there is some mistake which is in for loop.
Here is my code :
function actioncouponcsv_download() {
$this->layout = false;
foreach (Yii::app()->log->routes as $route) {
if ($route instanceof CWebLogRoute || $route instanceof CFileLogRoute || $route instanceof YiiDebugToolbarRoute) {
$route->enabled = false;
}
}
$dateRange = json_decode($_POST['dateRange'], true);
$start = $dateRange['start'];
$end = $dateRange['end'];
$validity = $_POST['validity'];
$limit = isset($_REQUEST['limit']) && trim($_REQUEST['limit']) ? $_REQUEST['limit'] : 0;
$studio_id = Yii::app()->user->studio_id;
if (isset($_GET['type']) && intval($_GET['type']) ==2) {
$couponobj = new CouponSubscription();
$getcouponobj = $couponobj->getcoupon_data($studio_id,$start,$end,$validity);
$k = 0;
$title_addon = "\t" . "Discount Cycle" . "\t" . "Extend free trail";
$data_addon = "\t" . $getcouponobj[$k]['discount_multiple_cycle'] . "\t" . $getcouponobj[$k]['extend_free_trail'];
} else {
$title_addon = "";
$data_addon = "";
$couponobj = new Coupon();
$getcouponobj = $couponobj->getcoupon_data($studio_id,$limit,1);
}
//$Coupon = Coupon::model()->find('studio_id=:studio_id', array(':studio_id' => $studio_id));
$dataCsv = '';
if ($getcouponobj) {
$headings = "Sl no" . "\t" . "Coupon" . "\t" . "Coupon Type" . "\t" . "Used by a single user" . "\t" . "Valid" . "\t" . "Used" . "\t" . "User" .$title_addon. "\t" . "Used Date". "\t" . "Content Category". "\t" . "Content"."\n";
$i = 1;
$dataCSV[] = Array();
$j = 0;
for ($k = 0; $k < count($getcouponobj); $k++) {
$userList = '-';
if ($getcouponobj[$k]['used_by'] != '0') {
if ($getcouponobj[$k]['coupon_type'] == 1) {
$userList = '';
$userIdList = explode(",", $getcouponobj[$k]['used_by']);
foreach ($userIdList as $userIdListKey => $userIdListVal) {
if ($userIdListKey == 0) {
$userList .= Yii::app()->webCommon->getuseremail($userIdListVal);
} else {
$userList .= " | " . Yii::app()->webCommon->getuseremail($userIdListVal);
}
}
} else {
$userList = Yii::app()->webCommon->getuseremail($getcouponobj[$k]['used_by']);
}
}
if($getcouponobj[$k]['is_all']!=1){
if($getcouponobj[$k]['content_category']==1){
$cont_cat = "Digital";
$content_str = Coupon::model()->getContentInfo($getcouponobj[$k]['specific_content']);
$cont_str = $content_str;
}else if($getcouponobj[$k]['content_category']==2){
$cont_cat = "Physical";
$content_str = Coupon::model()->getContentInfoPhysical($getcouponobj[$k]['specific_content']);
$cont_str = $content_str;
}else{
$cont_cat = "All";
$cont_str = "All";
}
}else{
$cont_cat = "All";
$cont_str = "All";
}
#echo $getcouponobj[$k]['coupon_code'];
array_push($dataCSV[$j],$i);
array_push($dataCSV[$j],$getcouponobj[$k]['coupon_code']);
array_push($dataCSV[$j],(($getcouponobj[$k]['coupon_type'] == 1) ? 'Multi-use' : 'Once-use'));
array_push($dataCSV[$j],(($getcouponobj[$k]['user_can_use'] == 1) ? 'Multiple times' : 'Once'));
array_push($dataCSV[$j],(($getcouponobj[$k]['used_by'] == 0) ? 'Yes' : 'No'));
array_push($dataCSV[$j],(($getcouponobj[$k]['used_by'] == 0) ? '-' : 'Yes'));
array_push($dataCSV[$j],$userList);
array_push($dataCSV[$j],$getcouponobj[$k]['discount_multiple_cycle']);
array_push($dataCSV[$j],$getcouponobj[$k]['extend_free_trail']);
array_push($dataCSV[$j],(($getcouponobj[$k]['cused_date'] == 0) ? '-' : $getcouponobj[$k]['cused_date']));
array_push($dataCSV[$j],$cont_cat);
array_push($dataCSV[$j],$cont_str);
$j++;
//$dataCsv .= $i . "\t" . $getcouponobj[$k]['coupon_code'] . "\t" . (($getcouponobj[$k]['coupon_type'] == 1) ? 'Multi-use' : 'Once-use') . "\t" . (($getcouponobj[$k]['user_can_use'] == 1) ? 'Multiple times' : 'Once') . "\t" . (($getcouponobj[$k]['used_by'] == 0) ? 'Yes' : 'No') . "\t" . (($getcouponobj[$k]['used_by'] == 0) ? '-' : 'Yes') . "\t" . $userList .$data_addon. "\t" . (($getcouponobj[$k]['cused_date'] == 0) ? '-' : $getcouponobj[$k]['cused_date'])."\t" .$cont_cat ."\t".$cont_str."\n";
$i = $i+1;
}
}
print_r(json_encode($dataCSV));
}
PS: I am getting the values. Any help will be highly appreciated.
Well, first thing i see wrong is the way you declare your array:
$dataCSV[] = Array();
$array[] = Means that you are adding a new value to an existing array. To declare your array you should use
$dataCSV = array();
Also, this code:
array_push($dataCSV[$j],$i);
means that you are adding a new value to your $dataCSV[$j] array, but this is never declared as an array, so first thing would be to do
$dataCSV[$j] = new array();
Your code is really long and complicated, those are only examples of issues i see in there.
I am getting this error:
Notice: Undefined index: REDIRECT_URL in /home/webccans/public_html/index.php
I have Tried taking out the redirect and it still works. I need help try to define the index "REDIRECT_URL" I would appreciate and pointers or advice.
The page is display, and the site works fine but this error is on the home page
This is the Code on my index page
<?
include('application.php');
$header = false;
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
if (($request = trim($_SERVER['REDIRECT_URL'])) == '') {
// Deal with direct requests
$Page = (isset($_GET['Page'])) ? $_GET['Page'] : 1;
$Page = $CMS->getPageContent($Page);
} else {
// Deal with "friendly" URL 404 pages
$pages = explode('/', $request);
array_shift($pages);
$page = array_pop($pages);
if (($pos = strpos($page, '.')) === false) {
$ext = '';
} else {
$ext = substr($page, strpos($page, '.'));
if ($pos = strpos($ext, '?')) $ext = substr($ext, 0, $pos);
}
if ($page == '') {
// have a CMS page or the home page
} else if ($ext == '.htm' || $ext == '.html' || $ext == '.php') {
$PageURL = substr($page, 0, strlen($ext) * -1);
if ($PageURL != "index") {
// Possible have a CMS page
array_push($pages, $PageURL);
}
} else if ($ext == '') {
// have a CMS page
array_push($pages, $page);
} else {
$CMS->show404Page();
$header = true;
}
if (($numPages = count($pages)) > 0) {
// Get PageID
$select = 'SELECT ';
$from = ' FROM site_content AS page0 LEFT JOIN site_content AS
page ON (page0.ParentID = page.PageID) ';
$where = ' WHERE (page0.ParentID = 0 OR page.Display = 0) ';
for ($idx = 0; $idx < $numPages; ++$idx) {
$where .= ' AND ';
if ($idx > 0) {
$select .= ', ';
$from .= ' JOIN site_content AS page' . $idx . ' ON (page'
. ($idx - 1) . '.PageID = page' . $idx . '.ParentID)';
}
$select .= 'page' . $idx . '.PageID ';
$where .= 'page' . $idx . '.PageURL = "' . $DB-
>escape(strtolower($pages[$idx])) . '"';
#$select1 = 'page' . $idx . '.PageID ';
}
$qid = $DB->query($select . $from . $where);
if ($row = $DB->fetchRow($qid)) {
$PageID = $row[$numPages - 1];
$OpenedPages = $row;
#print_r ($row);
}
else {
$CMS->show404Page();
$header = true;
}
} else {
$PageID = 1;
}
$Page = $CMS->getPageContent($PageID);
#echo '<script language="javascript">' . 'alert("' . $PageID . '")'
.
'</script>';
#echo '<script language="javascript">' . 'alert("' . $ParentId . '")'
. '</script>';
}
$TopPage = $CMS->getTopParent($Page->PageID);
if (!$header) header('HTTP/1.1 200 OK');
?>
I'm trying to change this below script that will works and save same file but inside server internal location instead of like it is doing now save file and then upload to my destination.
<?php
session_start();
include("includes/config.inc2.php");
#ini_set('display_errors','Off');
$quantity_store_query = ''; $quantity_store_query1 = '';
if(isset($_REQUEST['store_id']) && $_REQUEST['store_id'] != '')
{
$get_t = mysql_fetch_array(mysql_query("select quantity_store_id from tbl_website where `store_id` = '".$_REQUEST['store_id']."'"));
$quantity_store_query = " pq.quantity_store_id = '".$get_t['quantity_store_id']."' and ";
$quantity_store_query1 = " quantity_store_id = '".$get_t['quantity_store_id']."' and ";
$get_cur = mysql_fetch_array(mysql_query("SELECT currencies_id FROM currencies WHERE code = (SELECT currency FROM tbl_store WHERE store_id = {$_REQUEST['store_id']})"));
$currency = $get_cur['currencies_id'];
}
if(isset($_REQUEST['lowstock']) && $_REQUEST['lowstock'] != '')
{
define("MINI_ITMS_STOCK",5);
$data='';
$csv_output="";
$refundquery = mysql_query("select p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` <= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
if(mysql_num_rows($refundquery) > 0)
{
$row1 = array("Item Name", "Item Code", "Description", "Weight", "Colour", "Size", "Wholesale Price", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity");
foreach ($row1 as $value1 )
{
$data .= $value1."\t";
}
$data .= "\n";
for($p=0;$p<mysql_num_rows($refundquery);$p++)
{
$orderinfo = mysql_fetch_array($refundquery);
$prod_id = $orderinfo['id'];
$product_name = stripslashes($orderinfo['product_name']);
$product_code = stripslashes($orderinfo['product_code']);
$product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
$weight = stripslashes($orderinfo['weight']);
$was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
$colour_name = 'N/A';
$size_name = 'N/A';
$quantity = $info['quantity'];
$barcode = $info['barcode'];
$psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` <= '".MINI_ITMS_STOCK."' LIMIT 12") or die(mysql_error());
if(mysql_num_rows($psql) > 0)
{
for($k=0;$k<mysql_num_rows($psql);$k++)
{
$kinfo = mysql_fetch_array($psql);
$colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
$size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
$images = get_image_data($prod_id,$kinfo['color_id']);
$quantity = $kinfo['quantity'];
$barcode = $kinfo['barcode'];
if($quantity <= MINI_ITMS_STOCK)
{
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}
$csv_output .= "\n";
}
}
}
else
{
$p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity <= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
if(mysql_num_rows($p_sql) > 0)
{
$kinfo = mysql_fetch_array($p_sql);
$images = get_image_data($prod_id,0);
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}$csv_output .= "\n";
}
}
}
$data = str_replace("\r","",$data);
$to_date = date("d-m-y-h-i-s");
$excel_name = "Low_stock_".$to_date;
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
header("Pragma: no-cache");
header("Expires: 0");
print $data.$csv_output;
exit;
}
}
if(isset($_REQUEST['outofstock']) && $_REQUEST['outofstock'] != '')
{
define("MINI_ITMS_STOCK",0);
$data='';
$csv_output="";
$refundquery = mysql_query("select p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` <= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
if(mysql_num_rows($refundquery) > 0)
{
$row1 = array("Item Name", "Item Code", "Barcode", "Description", "Weight", "Colour", "Size", "Wholesale Price", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity");
foreach ($row1 as $value1 )
{
$data .= $value1."\t";
}
$data .= "\n";
for($p=0;$p<mysql_num_rows($refundquery);$p++)
{
$orderinfo = mysql_fetch_array($refundquery);
$prod_id = $orderinfo['id'];
$product_name = stripslashes($orderinfo['product_name']);
$product_code = stripslashes($orderinfo['product_code']);
$product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
$weight = stripslashes($orderinfo['weight']);
$was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
$colour_name = 'N/A';
$size_name = 'N/A';
$quantity = $info['quantity'];
$barcode = $info['barcode'];
$psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` <= '".MINI_ITMS_STOCK."'") or die(mysql_error());
if(mysql_num_rows($psql) > 0)
{
for($k=0;$k<mysql_num_rows($psql);$k++)
{
$kinfo = mysql_fetch_array($psql);
$colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
$size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
$images = get_image_data($prod_id,$kinfo['color_id']);
$quantity = $kinfo['quantity'];
$barcode = $kinfo['barcode'];
if($quantity <= MINI_ITMS_STOCK)
{
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}
$csv_output .= "\n";
}
}
}
else
{
$p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity <= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
if(mysql_num_rows($p_sql) > 0)
{
$kinfo = mysql_fetch_array($p_sql);
$images = get_image_data($prod_id,0);
$export=array($product_name,$product_code,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}$csv_output .= "\n";
}
}
}
$data = str_replace("\r","",$data);
$to_date = date("d-m-y-h-i-s");
$excel_name = "Out_Of_stock_".$to_date;
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
header("Pragma: no-cache");
header("Expires: 0");
print $data.$csv_output;
exit;
}
}
if(isset($_REQUEST['stock']) && $_REQUEST['stock'] != '')
{
define("MINI_ITMS_STOCK",'-1');
$data='';
$csv_output="";
$refundquery = mysql_query("select p.main_category_name,p.sub_category_name,p.item_collection,p.product_name,p.product_code,p.product_desc,p.weight,p.was_price,p.quantity,p.id,p.created_dt from product as p,product_quantity as pq where ".$quantity_store_query." p.id = pq.product_id and pq.`quantity` >= '".MINI_ITMS_STOCK."' group by pq.product_id order by p.created_dt") or die(mysql_error());
if(mysql_num_rows($refundquery) > 0)
{
$row1 = array("Main Category","Sub Category","Item Collection","Item Name", "Item Code", "Stock Code", "Barcode", "Description", "Weight", "Colour", "Size", "Wholesale Price", "RRP", "Image1", "Image2", "Image3", "Image4", "Image5", "Quantity", "Quantity Code");
foreach ($row1 as $value1 )
{
$data .= $value1."\t";
}
$data .= "\n";
for($p=0;$p<mysql_num_rows($refundquery);$p++)
{
$orderinfo = mysql_fetch_array($refundquery);
$prod_id = $orderinfo['id'];
$product_name = stripslashes($orderinfo['product_name']);
$product_code = stripslashes($orderinfo['product_code']);
$product_desc = strip_tags(stripslashes($orderinfo['product_desc']));
$item_collection = stripslashes($orderinfo['item_collection']);
$main_category_name = stripslashes($orderinfo['main_category_name']);
$sub_category_name = stripslashes($orderinfo['sub_category_name']);
$weight = stripslashes($orderinfo['weight']);
$was_price = get_table_data("product_price","price","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . " AND currencies_id = $currency");
$was_active = get_table_data("product_website","active","product_id=".$prod_id." AND store_id=".$_REQUEST['store_id'] . "");
$colour_name = 'N/A';
$size_name = 'N/A';
$quantity = $info['quantity'];
$barcode = $info['barcode'];
$psql = mysql_query("SELECT * FROM `product_quantity` where ".$quantity_store_query1." product_id = '$prod_id' and `quantity` >= '".MINI_ITMS_STOCK."'") or die(mysql_error());
$psql2 = mysql_query("SELECT * FROM `product_category` where product_id = $prod_id");
if(mysql_num_rows($psql) > 0)
if($was_active == 1)
{
for($k=0;$k<mysql_num_rows($psql);$k++)
{
$kinfo = mysql_fetch_array($psql);
$kinfo2 = mysql_fetch_array($psql2);
$category_name = get_table_data("category","cat_name","cat_id=".$kinfo2['category_id']);
$colour_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['color_id']);
$size_name = get_table_data("attributes_value","attr_value1","attribute_value_id=".$kinfo['size_id']);
$images = get_image_data($prod_id,$kinfo['color_id']);
$quantity = $kinfo['quantity'];
$barcode = $kinfo['barcode'];
$RRP = ceil($was_price * 2.5);
?>
<?php
if ($quantity > 5) {
$quantity_code = 2;
} elseif ($quantity < 5) {
$quantity_code = 1;
} elseif ($quantity = 0){
$quantity_code = 0;
?>
<?php
$export=array($main_category_name,$sub_category_name,$item_collection,$product_name,$product_code,$product_code.$colour_name.$size_name,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$RRP,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity,$quantity_code);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}
$csv_output .= "\n";
}
}
}
else
{
$p_sql = mysql_query("SELECT * FROM `product` where id = $prod_id and quantity >= ".MINI_ITMS_STOCK." and is_color = 0 and is_size = 0");
if(mysql_num_rows($p_sql) > 0)
if($was_active == 1)
{
$kinfo = mysql_fetch_array($p_sql);
$images = get_image_data($prod_id,0);
$export=array($main_category_name,$sub_category_name,$item_collection,$category_name,$product_name,$product_code,$product_code.$colour_name.$size_name,$barcode,$product_desc,$weight,$colour_name,$size_name,$was_price,$RRP,$images[0], $images[1], $images[2], $images[3], $images[4],$quantity,$quantity_code);
for($i=0; $i<count($export); $i++)
{
$line = ''; $value='';
$value=$export[$i];
if ((!isset($value)) OR ($value == "")) {
$value = "\t";
}
else
{
$value = '"' . $value . '"' . "\t";
}
$line .= stripslashes($value);
$csv_output .= trim($line)."\t";
}$csv_output .= "\n";
}
}
}
$data = str_replace("\r","",$data);
$to_date = date("d-m-y-h-i-s");
$excel_name = "BANNED_STOCK_UPDATE";
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=\"".$excel_name.".xls\"");
header("Pragma: no-cache");
header("Expires: 0");
print $data.$csv_output;
exit;
}
}
?>
This code is in php file. How I will style tag with "Select Size" and customize the drop down section. Below is one div which i want to style but ht class is created dynamically. And here div drop box are created dynamically and the data entered is also been done dynamically. HELP
$i = 0;
$attribArr = array();
$sizeArr = array();
$colorArr = array();
$colorStr = "color";
$sizeStr = "size";
$phpArray = array(
0 => 001 - 1234567,
1 => 1234567,
2 => 12345678,
3 => 12345678,
4 => 12345678
);
foreach ($order['cart_items'] as $item) {
$i++;
$cssNo = $i % 5;
if ($cssNo == 0) {
$cssNo = 5;
}
$giftcss = "gift-info gift" . $cssNo;
// Get products description
$presult = array();
$productId = $item['product_id'];
$reslt = getProductOptions($productId);
$values = $reslt['values'];
info('option type=' . $reslt['type'] . ' Name=' . $reslt['name']);
$sizeOptionValues = '<option>';
$colorOptionValues = '<option>';
if ($reslt['name'] == 'Size') {
foreach ($values as $value) {
info('vl=' . $value['options_value_name']);
$sizeOptionValues.= str_replace(' ', '', $value['options_value_name']) . '</option><option>';
}
}
if ($reslt['name'] == 'Color') {
foreach ($values as $value) {
info('vl=' . $value['options_value_name']);
$colorOptionValues.= $value['options_value_name'] . '</option><option>';
}
}
$pquery = "SELECT products_description, pr.products_image, products_name FROM "
. TABLE_PRODUCTS_DESCRIPTION . " AS pd JOIN " . TABLE_PRODUCTS . " as pr ON pr.products_id = pd.products_id WHERE pd.products_id=" . $productId;
$presult = $db->Execute($pquery);
$product_name = $presult->fields['products_name'];
$product_image = $presult->fields['products_image'];
$product_desc = $presult->fields['products_description'];
$prodImgs = explode(".", $product_image);
$prodImg0 = $prodImgs[0];
$prodImgExt = $prodImgs[1];
$prod_img_name = $prodImg0 . 'v.' . $prodImgExt;
info("getOrder", "Product Name=" . $product_name . " prod image=" . $prod_img_name);
$prod_desc_url = EL_PROD_DESC_PATH . $productId;
$prodAttrQry = "SELECT * FROM " . TABLE_ORDERS_PRODUCTS_ATTRIBUTES . " WHERE products_prid = " . $productId . " AND orders_id = " . $orderId;
$attrReslt = $db->Execute($prodAttrQry);
$color = false;
$colorValue = '';
$size = false;
$sizeValue = '';
$personalised = false;
$attr = false;
$personalisedMsg = '';
if ($attrReslt->RecordCount() > 0) {
$attr = true;
$attrArr = array();
while (!$attrReslt->EOF) {
$optName = $attrReslt->fields['products_options'];
$optValue = $attrReslt->fields['products_options_values'];
if ($optName == 'Size') {
$size = true;
$sizeValue = $optValue;
} else if ($optName == 'Color') {
$color = true;
$colorValue = $optValue;
} else if ($optName == '') {
$personalised = true;
$rslt = explode(".", $optValue);
if ((isset($rslt[1]) && $rslt[1] == 'jpg') || (isset($rslt[1]) && $rslt[1] == 'png')) {
$personalisedMsg = "<b>Uploaded Image</b> " . "<br><img style = 'width:200px; height:200px;'src = '$optValue'/>";
} else {
$personalisedMsg = '<b>Personal Message</b><br>' . $optValue;
}
}
$sizeArr[$i] = $sizeValue;
$colorArr[$i] = $colorValue;
$attribArr['personalise_val' . $i] = $personalisedMsg;
$attrReslt->MoveNext();
}
}
$colorVisibility = 'none';
$sizeVisibility = 'none';
$personalisedVisib = 'none';
$headlineVisib = 'none';
if ($color) {
$colorVisibility = 'inline';
$headlineVisib = 'inline';
}
if ($size) {
$sizeVisibility = 'inline';
$headlineVisib = 'inline';
}
if ($personalised) {
$personalisedVisib = 'inline';
}
$secondScreen .= <<
<div class="{$giftcss}">
<input type="hidden" name= "product_id{$i}" value="{$productId}"/>
<div class="gift-img"><img src="http://{$domainName}/gifts/images/{$prod_img_name}" height="250"></div>
<div class="divider"></div><div class="gift-desc"><h3>{$product_name}</h3><span>{$product_desc}</span></div>
<div style="width:100%;"><h3 style="display:{$headlineVisib}">Customize your gift</h3><br>
<p style="display:{$sizeVisibility};">Select Size<select id = "prod_size{$i}" name="prod_size{$i}" >{$sizeOptionValues}</select></p>
<p style="display:{$colorVisibility};">Select Color<select id = "prod_color{$i}" name="prod_color{$i}" >{$colorOptionValues}</select></p>
<p style="display:{$personalisedVisib};">{$personalisedMsg}</p></div>
MARKUP;
$secondScreen .= <<<MARKUP
Im not entirely sure what you mean? But if it's what I think you mean. To print out your php values into the class='' attribute you would:
<div class="<?php echo $giftcss; ?>">
<input type="hidden" name= "product_id<?php echo $i; ?>" value="{$productId}"/>
<div class="gift-img">
<img src="http://<?php echo $domainName; ?>/gifts/images/<?php echo $prod_img_name; ?>" height="250"></div>
Simply <?php echo $variable; ?> into each html attribute.
I have a follow up question on something I got help with here the other day (No Table Three Column Category Layout).
The script is as follows:
$res = mysql_query($query);
$system->check_mysql($res, $query, __LINE__, __FILE__);
$parent_node = mysql_fetch_assoc($res);
$id = (isset($parent_node['cat_id'])) ? $parent_node['cat_id'] : $id;
$catalist = '';
if ($parent_node['left_id'] != 1)
{
$children = $catscontrol->get_children_list($parent_node['left_id'], $parent_node['right_id']);
$childarray = array($id);
foreach ($children as $k => $v)
{
$childarray[] = $v['cat_id'];
}
$catalist = '(';
$catalist .= implode(',', $childarray);
$catalist .= ')';
$all_items = false;
}
$NOW = time();
/*
specified category number
look into table - and if we don't have such category - redirect to full list
*/
$query = "SELECT * FROM " . $DBPrefix . "categories WHERE cat_id = " . $id;
$result = mysql_query($query);
$system->check_mysql($result, $query, __LINE__, __FILE__);
$category = mysql_fetch_assoc($result);
if (mysql_num_rows($result) == 0)
{
// redirect to global categories list
header ('location: browse.php?id=0');
exit;
}
else
{
// Retrieve the translated category name
$par_id = $category['parent_id'];
$TPL_categories_string = '';
$crumbs = $catscontrol->get_bread_crumbs($category['left_id'], $category['right_id']);
for ($i = 0; $i < count($crumbs); $i++)
{
if ($crumbs[$i]['cat_id'] > 0)
{
if ($i > 0)
{
$TPL_categories_string .= ' > ';
}
$TPL_categories_string .= '' . $category_names[$crumbs[$i]['cat_id']] . '';
}
}
// get list of subcategories of this category
$subcat_count = 0;
$query = "SELECT * FROM " . $DBPrefix . "categories WHERE parent_id = " . $id . " ORDER BY cat_name";
$result = mysql_query($query);
$system->check_mysql($result, $query, __LINE__, __FILE__);
$need_to_continue = 1;
$cycle = 1;
$column = 1;
$TPL_main_value = '';
while ($row = mysql_fetch_array($result))
{
++$subcat_count;
if ($cycle == 1)
{
$TPL_main_value .= '<div class="col'.$column.'"><ul>' . "\n";
}
$sub_counter = $row['sub_counter'];
$cat_counter = $row['counter'];
if ($sub_counter != 0)
{
$count_string = ' (' . $sub_counter . ')';
}
else
{
if ($cat_counter != 0)
{
$count_string = ' (' . $cat_counter . ')';
}
else
{
$count_string = '';
}
}
if ($row['cat_colour'] != '')
{
$BG = 'bgcolor=' . $row['cat_colour'];
}
else
{
$BG = '';
}
// Retrieve the translated category name
$row['cat_name'] = $category_names[$row['cat_id']];
$catimage = (!empty($row['cat_image'])) ? '<img src="' . $row['cat_image'] . '" border=0>' : '';
$TPL_main_value .= "\t" . '<li>' . $catimage . '' . $row['cat_name'] . $count_string . '</li>' . "\n";
++$cycle;
if ($cycle == 7) // <---- here
{
$cycle = 1;
$TPL_main_value .= '</ul></div>' . "\n";
++$column;
}
}
if ($cycle >= 2 && $cycle <= 6) // <---- here minus 1
{
while ($cycle < 7) // <---- and here
{
$TPL_main_value .= ' <p> </p>' . "\n";
++$cycle;
}
$TPL_main_value .= '</ul></div>'.$number.'
' . "\n";
}
I was needing to divide the resulting links into three columns to fit my html layout.
We accomplished this by changing the numbers in the code marked with "// <---- here".
Because the amount of links returned could be different each time, I am trying to figure out how to change those numbers on the fly. I tried using
$number_a = mysql_num_rows($result);
$number_b = $number_a / 3;
$number_b = ceil($number_b);
$number_c = $number_b - 1;
and then replacing the numbers with $number_b or $number_c but that doesn't work. Any ideas?
As mentioned before, you can use the mod (%) function to do that.
Basically what it does is to get the remainder after division. So, if you say 11 % 3, you will get 2 since that is the remainder after division. You can then make use of this to check when a number is divisible by 3 (the remainder will be zero), and insert an end </div> in your code.
Here is a simplified example on how to use it to insert a newline after every 3 columns:
$cycle = 1;
$arr = range (1, 20);
$len = sizeof ($arr);
for ( ; $cycle <= $len; $cycle++)
{
echo "{$arr[$cycle - 1]} ";
if ($cycle % 3 == 0)
{
echo "\n";
}
}
echo "\n\n";