I need to return list with prices only if there have groups i try already if else empty not !=
nothing help any suggestions ?
$usergroups = '11,9,10';
if (empty($usergroups)) {
return;
}
$fields = 'MIN(IF(prices.percentage_discount = 0, prices.price, prices.price - (prices.price * prices.percentage_discount)/100)) as price, prices.usergroup_id as usergroup_id, ud.usergroup as usergroup_name';
$condition = db_quote(' prices.product_id = ?i AND prices.usergroup_id IN (?p) AND ud.lang_code = ?s', $product['product_id'], $usergroups, DESCR_SL);
$group_by = 'usergroup_id';
$join = '?:usergroup_descriptions as ud ON ud.usergroup_id = prices.usergroup_id';
$opt_prices = db_get_array("SELECT ?p FROM ?:product_prices as prices LEFT JOIN ?p WHERE ?p GROUP BY ?p", $fields, $join, $condition, $group_by);
$currencies = Registry::get('currencies');
foreach ($opt_prices as &$price) {
$price['current'] = 0;
if (in_array($price['usergroup_id'], $auth['usergroup_ids'])) {
$price['current'] = 1;
$product['price'] = $price['price'];
}
$price['price'] = number_format($price['price'], 2, '.', ' ') . ' $';
}
$product['group_discounts'] = $opt_prices;
}
So i want display $product['group_discounts'] = $opt_prices;
only if there is $usergroups = '11,9,10';
Answer your comment:
You used that but ok here an example :
<?php
$usergroups = array('11','9','10');
$opt_prices='11';
if (in_array($opt_prices,$usergroups)){
echo 'yes';
}else{
echo 'no';
}
?>
Related
I try to make student result management system. I face problem when I try to give position every student depend on their total obtain mark in exam. In my output I get 1st(obtain mark 448),2nd(obtain mark 444),3rd(obtain mark 445),4th(obtain mark 447), 15th(obtain mark 450),8th(obtain mark 449) But I don't find any problem in my code. It should be 1st(obtain mark 450),2nd(obtain mark 449)....
if (!function_exists('get_student_position')) {
function get_student_position($school_id, $academic_year_id, $class_id, $student_id, $section_id = null) {
$condition = " academic_year_id = $academic_year_id ";
$condition .= " AND school_id = $school_id";
$condition .= " AND class_id = $class_id";
$condition .= " AND student_id = $student_id";
if($section_id){
$condition .= " AND section_id = $section_id";
}
$ci = & get_instance();
$sql = "SELECT id, avg_grade_point, FIND_IN_SET( (avg_grade_point+total_obtain_mark),
( SELECT GROUP_CONCAT( (avg_grade_point+total_obtain_mark) ORDER BY avg_grade_point DESC )
FROM final_results ) ) AS rank
FROM final_results
WHERE $condition";
$result = $ci->db->query($sql)->row();
$rank = '';
if(!empty($result)){
$rank = $result->rank;
}
if($rank == 1){
return $rank.'st';
}elseif($rank == 2){
return $rank.'nd';
}elseif($rank == 3){
return $rank.'rd';
}elseif($rank > 3 ){
return $rank.'th';
}else{
return '--';
}
}
}
What I want to do is When I enter all my information (for client ID 199 in the picture) In my account being submit it, it goes into the database. BUT I want it to change to something and so i added an if statement
Here the code im adding to the existing code already at the BOTTOM of the code
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
if the ($vpr_clid = 199)
i want the clname to be "Shelley Madsen And Associates" then what is show in the table below instead of "Nice and White Smiles" (that an example of the results look like)
but when i chcek the database it not changing it and still show "Nice and White Smiles :(
I dont see any error, so it might be the placement of the code i have to put the IF statement in the huge php file? Dont know how to fix this issue
Thanks (the code below is the base code before i added the If statement)
I also insert the if statement before the function were called but still didnt work example
if ($vpr_clid == 199) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
<?php
session_start();
if ($_SESSION['company'] != "ACB") {
// redirect to the logout page
$redirect = 'logout.php';
include './includes/redirect.php';
}
class variables_obj {
var $vpr_plan = '';
var $vpr_id = '';
var $vpr_clid = '';
var $vpr_cl_name = '';
var $vpr_cl_phone = '';
var $vpr_call_start_date = '';
var $vpr_db_account = '';
var $vpr_db_fname = '';
var $vpr_db_mname = '';
var $vpr_db_lname = '';
var $vpr_rp_fname = '';
var $vpr_rp_mname = '';
var $vpr_rp_lname = '';
var $vpr_rp_address = '';
var $vpr_rp_city = '';
var $vpr_rp_state = '';
var $vpr_rp_zipcode = '';
var $vpr_rp_phonenum = '';
var $vpr_rp_phonetype = '';
var $vpr_date_entered = '';
var $newrecdt = '';
var $vpl_day_offset = '';
var $vpl_action = '';
var $vpr_promocode = '';
}
function ScrubPhone($old_phone_num) {
$phone_length = strlen($old_phone_num);
$new_phone_num = "";
for($i = 0; $i < $phone_length; $i = $i + 1) {
if(is_numeric($old_phone_num[$i])) {
$new_phone_num .= $old_phone_num[$i];
}
}
return $new_phone_num;
}
function ScheduleCreated($link, $vars) {
$query = "UPDATE v_payreminder SET vpr_schedule_created = '1' WHERE vpr_id='".$vars->vpr_id."'";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateScheduleRow($link, $vars){
// echo "vpl_day_offset: ".$vars->vpl_day_offset."<br>";
// echo "vpl_action: ".$vars->vpl_action."<br>";
$plus_days = " +".$vars->vpl_day_offset." days";
// echo "plus days: ".$plus_days."<br>";
$date_offset = strtotime(date("Y-m-d", strtotime($vars->vpr_date_entered)).$plus_days);
$date_offset = date("Y-m-d", $date_offset);
// echo "date_offset: ".$date_offset."<br>";
// $date_offset = strtotime(date("Y-m-d",strtotime($vars->vpr_date_entered))." +".$vars->vpl_day_offset." days");
// $date_offset = strtotime(date("Y-m-d", strtotime($date)) . " +1 day");
// echo "date_offset: ".$date_offset."<br>";
$query = "INSERT INTO v_pr_schedule (
vpr_id,
vsc_plan,
vsc_date_entered,
vsc_action,
vsc_action_date,
vsc_status
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'$vars->vpl_action',
'$date_offset',
'VACT')";
//echo "query: ".$query."<br>";
if (!mysql_query($query,$link)) {
die('Error: ' . mysql_error());
}
return true;
}
function CreateSchedule($link, &$vars) {
// CREATE SCHEDULE
$query = " SELECT vpl_day_offset, vpl_action, vpl_condition
FROM v_plan
WHERE vpl_plan = '".$vars->vpr_plan."'";
// echo "query: ".$query."<br>";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
while ($row = mysql_fetch_array($qresult, MYSQL_ASSOC)) {
$vars->vpl_day_offset = $row['vpl_day_offset'];
$vars->vpl_action = $row['vpl_action'];
if ($row['vpl_condition'] == 'OO') {
CreateScheduleRow($link, $vars);
}
}
}
return true;
}
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
//echo "Client Name: ".$vars->vpr_cl_name."<br><br>";
//exit();
$sql="INSERT INTO v_payreminder (
vpr_clid,
vpr_cl_name,
vpr_cl_phone,
vpr_call_start_date,
vpr_db_account,
vpr_db_fname,
vpr_db_mname,
vpr_db_lname,
vpr_rp_fname,
vpr_rp_mname,
vpr_rp_lname,
vpr_rp_phonenum,
vpr_rp_phonetype,
vpr_rp_address,
vpr_rp_city,
vpr_rp_state,
vpr_rp_zipcode,
vpr_promo,
vpr_date_entered) VALUES (
'$vars->vpr_clid',
'$vars->vpr_cl_name',
'$vars->vpr_cl_phone',
'$vars->vpr_call_start_date',
'$vars->vpr_db_account',
'$vars->vpr_db_fname',
'$vars->vpr_db_mname',
'$vars->vpr_db_lname',
'$vars->vpr_rp_fname',
'$vars->vpr_rp_mname',
'$vars->vpr_rp_lname',
'$vars->vpr_rp_phonenum',
'$vars->vpr_rp_phonetype',
'$vars->vpr_rp_address',
'$vars->vpr_rp_city',
'$vars->vpr_rp_state',
'$vars->vpr_rp_zipcode',
'$vars->vpr_promocode',
'$vars->vpr_date_entered')";
if (!mysql_query($sql,$link)) {
die('Error2: ' . mysql_error());
}
return true;
}
function GetVpr_Id($link, &$vars) {
// Find out what vpr_id is
$query = "SELECT vpr_id FROM v_payreminder ";
$query .= "WHERE vpr_clid = '".$vars->vpr_clid."' AND vpr_date_entered = '".$vars->vpr_date_entered."'";
$qresult = mysql_query($query);
if (!$qresult) {
print(mysql_error());
}
if ($qresult && mysql_num_rows($qresult) > 0 ) {
$row = mysql_fetch_array($qresult, MYSQL_ASSOC);
$vars->vpr_id = $row['vpr_id'];
}
}
function InsertInActivity($link, $vars) {
// ENTER INTO ACTIVITY
$vaction_desc = 'PATIENT ENTERED';
$sql = "INSERT INTO v_pr_activity (
vpr_id,
va_plan,
va_action_dttm,
va_action_code,
va_action_desc,
va_disposition_code,
va_disposition_desc,
va_status_code,
va_status_desc
) VALUES (
'$vars->vpr_id',
'$vars->vpr_plan',
'$vars->vpr_date_entered',
'VINIT',
'$vaction_desc',
'SUCCESS',
'SUCCESS',
'VACT',
'ACTIVE'
)";
if (!mysql_query($sql,$link)) {
die('Error: ' . mysql_error());
}
}
include './includes/dblogin.php';
$vars = new variables_obj();
$vars->vpr_plan = 'VP01';
$vars->vpr_clid = $_SESSION['userid'];
//-------------------------------------------------------
// No commas can be in client name or they will
// mess up the Global Connect CSV file.
//-------------------------------------------------------
$vpr_cl_name = $_SESSION['username'];
$vpr_cl_name = str_replace(",", " ", $vpr_cl_name);
$vars->vpr_cl_name = $vpr_cl_name;
//-------------------------------------------------------
//-------------------------------------------------------
$vars->vpr_cl_phone = ScrubPhone($_SESSION['uphone']);
$vars->vpr_call_start_date = '0000-00-00';
$vars->vpr_db_account = $_POST['ndaccnum'];
$vars->vpr_db_fname = $_POST['ndfreqname'];
$vars->vpr_db_mname = $_POST['ndmname'];
$vars->vpr_db_lname = $_POST['ndlreqname'];
$vars->vpr_rp_fname = $_POST['ndrfreqname'];
$vars->vpr_rp_mname = $_POST['ndrmname'];
$vars->vpr_rp_lname = $_POST['ndrlreqname'];
$vars->vpr_rp_address = '';
$vars->vpr_rp_city = '';
$vars->vpr_rp_state = $_POST['ndrstatereqname'];
$vars->vpr_rp_zipcode = $_POST['ndrreqzipcode'];
$phonenumber = $_POST['1ndrreqphone'].$_POST['2ndrreqphone'].$_POST['3ndrreqphone'];
$vars->vpr_rp_phonenum = $phonenumber;
$vars->vpr_rp_phonetype = $_POST['treqphone'];
$vars->vpr_date_entered = date('Y-m-d H:i:s');
$vars->newrecdt = date('Ymd');
$vars->vpr_promocode = $_POST['promocode'];
// echo "vpr_plan: ".$vars->vpr_plan."<br>";
// echo "vpr_date_entered: ".$vars->vpr_date_entered."<br>";
// echo "newrecdt: ".$vars->newrecdt."<br>";
// echo "vpr_clid: ".$vars->vpr_clid."<br>";
// echo "vpr_id: ".$vars->vpr_id."<br>";
$result = InsertIntoPayReminder($link, $vars);
$result = GetVpr_Id($link, $vars);
$result = InsertInActivity($link, $vars);
$result = CreateSchedule($link, $vars);
$result = ScheduleCreated($link, $vars);
// echo "vpr_id: ".$vars->vpr_id."<br>";
mysql_close($link);
// redirect
$redirect = 'vpayremind.php';
include './includes/redirect.php';
?>
okay referencing the following lines..
if ( $vpr_clid == 199 ) {
$vpr_cl_name = "Shelley Madsen And Associates";
}
$result = InsertIntoPayReminder($link, $vars);
...and then:
function InsertIntoPayReminder($link, &$vars) {
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
so on and so forth... }
it doesnt seem as if you are actually setting the value of the class object. You seem to be setting some arbitrary php variable to the name you want, and then passing a totally different ' $vars ' object into the function. I don't see any reason to believe that the ' $vars ' you are passing into the function call contains the name value you want it to contain. You should be assigning the value of ' $vars ' before passing it in.
For instance:
if ( $vpr_clid == 199 ) {
$vars[ 'vpr_cl_name' ] = "Shelley Madsen And Associates";
}
then you can get rid of this line all together:
$vars->vpr_cl_name = strtr($vars->vpr_cl_name, "'", " ");
I have an website there are 5 categories, i only want to show the 1-4 category only in the new posts..how can I edit the code to do this job? thanks
Here is my code, and I do that in my sql by using following code:
SELECT * FROM `ff_se` WHERE Wid in ('1','2','3','4')"
but i dont know how to do that in php code. following is my part of php code:
$this->TableSe = 'ff_se';
$this->TableSeWord = 'ff_se_word';
$this->TableSeSupport = 'ff_se_support';
$this->TableSePost = 'ff_se_post';
$this->TableSePostTableId = 'ff_se_post_tableid';
public function GetAjaxList($Get){
$Results = array();
$Get = $this->StrToGBK($Get);
$Page = $Get['page'] ? intval($Get['page']):0;
$Where = '';
$Order = 'S.updateline';
if($Get['type'] == 'New'){
$Order = 'S.dateline';
}else if($Get['type'] == 'Hot'){
$Order = 'S.updateline';
if($this->Config['PluginVar']['ListHotVal']){
$Where .= ' and (S.support_count >= '.$this->Config['PluginVar']['ListHotVal'].' OR S.comment_count >= '.$this->Config['PluginVar']['ListHotVal'].')';
}
if($this->Config['PluginVar']['ListHotDataline']){
$Where .= ' and S.dateline >= '.strtotime("-".$this->Config['PluginVar']['ListHotDataline']." hours",time());
}
}else if($Get['type'] == 'Nearby'){//
$Order = 'S.updateline';
if($Get['lng'] && $Get['lat']){
$SquarePoint = $this->GetReturnSquarePoint($Get['lng'],$Get['lat'],$this->Config['PluginVar']['Distance']);
$Where .= ' and S.lat <> 0 and S.lat > '.$SquarePoint['right-bottom']['lat'].' and S.lat < '.$SquarePoint['left-top']['lat'].' and S.lng > '.$SquarePoint['left-top']['lng'].' and S.lng < '.$SquarePoint['right-bottom']['lng'];
}else{
return $Results;
}
}
if($_GET['wid']){
$Where .= ' and S.wid = '.intval($_GET['wid']);
}
$Where .= ' and S.display = 1 and S.fast_add_display = 1';
$Where = preg_replace('/and/','where',$Where,1);
$this->Config['PluginVar']['ListNum'] = $this->Config['PluginVar']['ListNum'] ? $this->Config['PluginVar']['ListNum'] : 10;
$Limit = 'LIMIT '.($Page * $this->Config['PluginVar']['ListNum']).','.$this->Config['PluginVar']['ListNum'];
$FetchSql = 'SELECT W.title as Ttitle,S.* FROM '.DB::table($this->Tablese).' S LEFT JOIN '.DB::table($this->TableSeWord).' W on W.id = S.wid '.$Where .' order by topdateline > '.time().' desc,'.$Order.' desc,S.dateline desc '.$Limit;
$Results = $this->ListFormat(DB::fetch_all($FetchSql));
return $Results;
}
I think you should try and understand the code first before you modify it ... but anyway:
You would only need to append the condition to the where clause generated in the PHP code.
You could do that by adding THE LINE MARKED "THIS LINE IS NEW" after this line:
$Where = '';
And this is the relevant part of the code:
$Where = '';
$Order = 'S.updateline';
if($Get['type'] == 'New'){
$Where .= ' and S.wid in (1,2,3,4)'; //THIS LINE IS NEW
$Order = 'S.dateline';
}else .......
As you can see any redundant initial "and"s are replaced with "where" here:
$Where = preg_replace('/and/','where',$Where,1);
so this should work - assuming that $Get['type'] == 'New' means that this is a new post which I can only guess.
I want to display the values from MySQL database using CodeIgniter. Here, I am using SELECT to query to compare the multiple values using the WHERE condition.
I want to display the checked rows values from one page to another. I am passing the the checked value via URL. In the second page, I am getting the value from the URL, and using the explode() function to split the value and display using a for loop. Here, values are displaying correctly. But, when passing the array values to the SELECT query, it displays only the last rows.
I want to display all checked rows from the database.
For example, sample code:
<?php
$id = $this->uri->segment(4);
$arr = explode(',', $id);
for ($kk = 0; $kk < count($arr); $kk++) {
echo $id_val13 = $arr[$kk];
$basicUrl = $this->config->item("basicUrl");
$basicUrl['bread_crumb'] = $this->breadcrumb();
$query = $this->db->query("SELECT aa.id as id,customer_type_id,start_time,close_time,dd.name as customer_name,bb.name as vehicle_name,cc.name as driver_name,other_expensive,depature_city,destination_city,journey_status,payment,tour_file,DATE_FORMAT(aa.created_date, '%d/%m/%Y') as created_date FROM " . $this->tbl . " as aa
left join vehicle as bb on aa.vehicle_id=bb.id
left join driver as cc on aa.driver_id=cc.id
left join tbl_customer as dd on aa.customer_id=dd.id
WHERE aa.id = $id_val13");
$result = array();
if ($query->num_rows()) {
$i = 1;
foreach ($query->result() as $row) {
$result_row = array();
$result_row[] = '<input type="checkbox" name="chk_id" id="chk_id" value="' . $row->id . '" />';
$result_row[] = $row->id;
$result_row[] = $row->customer_name;
if ($row->customer_type_id == "1")
$result_row[] = "Tour";
else if ($row->customer_type_id == "2")
$result_row[] = "Company";
else if ($row->customer_type_id == "3")
$result_row[] = "Guest";
$result_row[] = $row->driver_name;
$result_row[] = $row->vehicle_name;
$result_row[] = $row->destination_city;
$result_row[] = $row->start_time;
$result_row[] = $row->close_time;
$result_row[] = $row->payment;
$result_row[] = $row->other_expensive;
$result_row[] = $row->journey_status == "1" ? "Complete" : "On Progress";
if ($row->tour_file != "") {
$result_row[] = '' . $row->tour_file . '';
} else {
$result_row[] = "No File";
}
$result_row[] = $row->created_date;
$action_btn = action_button("Edit", $row->id) . action_button("Delete", $row->id) . action_button("Select", $row->id);
$result_row[] = $action_btn;
$result[] = $result_row;
$i++;
}
}
}
$tbl_header = array(
"",
"S NO",
"Customer Name",
"Type",
"Driver Name",
'Vehicle Name',
"Destination City",
"Start Time",
"Close Time",
"Rupee",
"Other Expensive",
"Journey Status",
"Itinerary",
"Created Date",
array(
"Edit",
"Delete"
)
);
$basicUrl['table'] = $this->makeTable($result, $tbl_header, $bool = TRUE);
$this->parser->parse("admin/center", $basicUrl);
?>
For example:
$array = array("1","2","6");
Normally using explode() and for loop, it display all the values. When I use select query using CodeIgniter, it displays the last row only.
Try this (I have defined $result before for loop) Also this is not a good practice to use your code like this use controller and models to do all the logical and database work....
<?php
$id = $this->uri->segment(4);
$arr = explode(',', $id);
$result=array();
for ($kk = 0; $kk < count($arr); $kk++)
{
echo $id_val13 = $arr[$kk];
$basicUrl = $this->config->item("basicUrl");
$basicUrl['bread_crumb'] = $this->breadcrumb();
$query=$this->db->query("SELECT aa.id as id,customer_type_id,start_time,close_time,dd.name as customer_name,bb.name as vehicle_name,cc.name as driver_name,other_expensive,depature_city,destination_city,journey_status,payment,tour_file,DATE_FORMAT(aa.created_date, '%d/%m/%Y') as created_date FROM ".$this->tbl." as aa
left join vehicle as bb on aa.vehicle_id=bb.id
left join driver as cc on aa.driver_id=cc.id
left join tbl_customer as dd on aa.customer_id=dd.id
WHERE aa.id = $id_val13");
if($query->num_rows()){
$i=1;
foreach($query->result() as $row){
$result_row=array();
$result_row[]='<input type="checkbox" name="chk_id" id="chk_id" value="'.$row->id.'" />';
$result_row[]=$row->id;
$result_row[]=$row->customer_name;
if($row->customer_type_id=="1")
$result_row[]="Tour";
else if($row->customer_type_id=="2")
$result_row[]="Company";
else if($row->customer_type_id=="3")
$result_row[]="Guest";
$result_row[]=$row->driver_name;
$result_row[]=$row->vehicle_name;
$result_row[]=$row->destination_city;
$result_row[]=$row->start_time;
$result_row[]=$row->close_time;
$result_row[]=$row->payment;
$result_row[]=$row->other_expensive;
$result_row[]=$row->journey_status=="1" ? "Complete" : "On Progress";
if($row->tour_file!="")
{
$result_row[]=''.$row->tour_file.'';
}
else
{
$result_row[]="No File";
}
$result_row[]=$row->created_date;
$action_btn=action_button("Edit",$row->id).action_button("Delete",$row->id).action_button("Select",$row->id);
$result_row[]=$action_btn;
$result[]=$result_row;
$i++;
}
}
}
$tbl_header=array("","S NO","Customer Name","Type","Driver Name",'Vehicle Name',"Destination City","Start Time","Close Time","Rupee","Other Expensive","Journey Status","Itinerary","Created Date",array("Edit","Delete"));
$basicUrl['table']=$this->makeTable($result,$tbl_header,$bool=TRUE);
$this->parser->parse("admin/center",$basicUrl);
?>
I have this function
public function getItem($idOn = false)
{
if($idOn) {
$id = $idOn;
} else {
$id = JRequest::getInt('id', $idOn);
}
if(!$id) return false;
$select = $this->_db->getQuery(true);
$select->select('a.*, b.title AS categoryTitle, c.email AS userEmail, SUM(s.view_item) AS hits');
$select->from('#__cddir_content AS a');
$select->join('INNER','#__cddir_categories AS b ON a.categories_id = b.id');
$select->join('LEFT','#__users AS c ON a.users_id = c.id');
$select->join('LEFT','#__cddir_statistic as s ON a.id=s.item_id');
$select->where('a.id = '.$this->_db->quote($id));
$select->where('a.published = 1');
$user=JFactory::getUser();
$aclgroups = implode(',', $user->getAuthorisedViewLevels());
$select->where('a.access IN (' . $aclgroups . ')')
->where('b.access IN (' . $aclgroups . ')');
$this->_db->setQuery($select);
$item = $this->_db->loadObject();
return $item;
}
I need to sum again the hits that I already added "SUM(s.view_item) AS hits", because some items have the same alias (a.alias) in #__cddir_content
So I need first sum all the s.view_items as hit that have the same id
Then I have to sum the saved hits that have the same alias.
I hope I made myself clear
Thank you for you help