Counts and left join not working right - count

Trying to do a count on these lines COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
but it keeps returning the same numbers for all three. So I'm trying to add a Where for each one, Example Count(isContractor where isContractor = 'yes') as contractorCount but getting errors please help, thank you.
<?php
clASs EfficiencyController extends DooController
{
function getEfficiency(){
include './protected/config/db.conf.php';
Doo::db()->setDb($dbconfig, 'local_network');
$Vendor = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['Vendor'] : $_GET['Vendor'];
$date = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['date'] : $_GET['date'];
$level = ($_SERVER['REQUEST_METHOD'] == "POST") ? $_POST['level'] : $_GET['level'];
switch($level) {
case "Region":
case "area":
$Market99="";
break;
default:
$Market99=$level;
break;
}
{
//
// LUCENT,NORTEL
//
$query = " SELECT
DayKey,
Market99,
Region,
areaName,
Sum(Total_Sites) as totalCount,
Max(engineerCount) AS engineerCount,
Max(managerCount) AS managerCount,
Max(contractorCount) AS contractorCount,
SC_Type,
Sum(Total_Carriers),
Sum(Total_Sectors),
Vendor
FROM
network.envEquipSummaryConfig a
Left Join
(SELECT
market,
areaName,
COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
FROM
employee.employees
GROUP BY market
ORDER BY COUNT(market) DESC) b ON a.Market99 = b.market
Where
a.DayKey <= \"$date\" and a.Vendor = \"$Vendor\"
Group By Market99 asc";
switch($level) {
case "region":
$query = $query. " order by region ASC";
break;
case "area":
$query = $query. " order by areaName ASC";
break;
default;
$query = $query. " order by Market99 ASC";
break;
}
}
//echo $query; exit;
$this->setContentType('xml');
$result = Doo::db()->fetchAll($query);
printf("<root>\n");
if(count($result) > 0)
foreach($result AS $row) {
printf("\t<data>\n");
printf("\t\t<date>%s</date>\n",$row["DayKey"]);
printf("\t\t<vName>%s</vName>\n",$row["Vendor"]);
printf("\t\t<location>%s</location>\n",$row["Market99"]);
printf("\t\t<toCount>%s</toCount>\n",$row["totalCount"]);
printf("\t\t<enCount>%s</enCount>\n",$row["engineerCount"]);
printf("\t\t<mnCount>%s</mnCount>\n",$row["managerCount"]);
printf("\t\t<cnCount>%s</cnCount>\n",$row["contractorCount"]);
printf("\t</data>\n");
}
printf("</root>\n");
}
}
?>

SELECT
market,
areaName,
COUNT(engineerName) AS engineerCount,
Count(managerName) as managerCount,
Count(isContractor) as contractorCount
FROM
employee.employees
GROUP BY market
should be
Group By market,areaName at a guess.
Which is all it can be seeing as you've provided next to no useful information.

Related

Doctrine query builder parenthesis bad place

I have a query that receive some array parameters without any ideas how rows there is. It must return contents with all filters (AND clause), and one or more categories (OR clause).
I can't get results I'd like because parentheses are not a the good place. I should got this SQL rendering:
WHERE (
f3_.idfilter = '87'
AND f5_.idfilter = '90'
AND f7_.idfilter = '154'
AND f9_.idfilter = '165'
)
AND (
c0_.content_category_idcontent_category = 1
OR c0_.content_category_idcontent_category = 3
)
and got this instead:
WHERE (
(
f3_.idfilter = '87'
AND f5_.idfilter = '90'
AND f7_.idfilter = '154'
AND f9_.idfilter = '165'
AND c0_.content_category_idcontent_category = 1
)
OR c0_.content_category_idcontent_category = 3
)
My code:
public function getContentByFiltersAjax($categs, $filters, $offset, $limit) {
$filtersTab = explode(',', $filters);
$query = $this->createQueryBuilder('c');
for ($i = 1; $i <= count($filtersTab); $i++) {
$query = $query
->leftJoin('c.filterfilter', 'f' . $i)
->andWhere('f' . $i . '.idfilter = :filter_idfilter' . $i)
->setParameter('filter_idfilter' . $i, $filtersTab[$i - 1]);
}
$categsTab = explode(',', $categs);
if(sizeof($categsTab) > 1) {
$expr = $query->expr();
$categsTab = explode(',', $categs);
foreach ($categsTab as $key => $value) {
if($key === 0){
$query->andWhere($expr->eq('c.contentCategorycontentCategory', $value));
} else {
$query->orWhere($expr->eq('c.contentCategorycontentCategory', $value));
}
}
} else {
$query
->andWhere('c.contentCategorycontentCategory = :category')
->setParameter('category', $categs);
}
$query
->andWhere('c.status = :status')
->setParameter('status', 'publie');
$query->orderBy('editor.plan', 'DESC');
$query->addOrderBy('c.creationDate', 'DESC');
$query
->setFirstResult($offset)
->setMaxResults($limit);
$result = $query->distinct()->getQuery()->getResult();
return $result;
}
You put the orWhere's inside 1 andWhere like this:
$query->andWhere(
$query->expr->orX(
$query->expr->eq('c.contentCategorycontentCategory', $value1),
$query->expr->eq('c.contentCategorycontentCategory', $value2)
)
);
Or in your foreach loop:
$orX = $query->expr->orX();
foreach ($categsTab as $value) {
$orX->add($query->expr->eq('c.contentCategorycontentCategory', $value));
}
$query->andWhere($orX);

Invalid parameter: token 1 is not defined in the query

Here is my code to filter pets base on a JSON ajax Query
I am getting error follwoing image
public function filter($object, $active=true){
$query = $this->createQueryBuilder('p');
$query->innerjoin('TadpetProfessionalBundle:ProPet', 'pp', 'WITH', 'pp.professionalId = p.id');
$query->innerjoin('TadpetManagerBundle:Pet', 'ppp', 'WITH', 'ppp.id = pp.petId');
$query->where('p.isActive = :active')
->setParameter('active', $active);
if(!empty($object->pets)){
$qString = "";
for($i=1; $i<=sizeof($object->pets); $i++){
if($i == 1){
$qString .= "ppp.name = :petname".$i;
}else{
$qString .= " OR ppp.name = :petname".$i;
}
}
$query->andWhere($qString);
$query->setParameter('petname'+1,$object->pets[0]);
$query->setParameter('petname'+2,$object->pets[1]);
$query->setParameter('petname'+3,$object->pets[2]);
}
return $query->getQuery()->getResult();
}
Help me please
In these lines:
$query->setParameter('petname'+1,$object->pets[0]);
$query->setParameter('petname'+2,$object->pets[1]);
$query->setParameter('petname'+3,$object->pets[2]);
You are adding 'petname' to the numbers, but you should concatenate them:
$query->setParameter('petname'.1,$object->pets[0]);
$query->setParameter('petname'.2,$object->pets[1]);
$query->setParameter('petname'.3,$object->pets[2]);
Also, you could use a loop:
for($i=1; $i<=sizeof($object->pets); $i++){
$query->setParameter('petname'.$i,$object->pets[$i-1]);
}

change weekly calendar to month wise calender

i am using the following code for weekly calendar it shows like enter image description here
function tribe_events_get_days_of_week( $format = null ) {
switch ( $format ) {
case 'min' :
$days_of_week = Tribe__Events__Main::instance()->daysOfWeekMin;
break;
case 'short' :
$days_of_week = Tribe__Events__Main::instance()->daysOfWeekShort;
break;
default:
$days_of_week = Tribe__Events__Main::instance()->daysOfWeek;
break;
}
$start_of_week = get_option( 'start_of_week', 0 );
for ( $i = 0; $i < $start_of_week; $i ++ ) {
$day = $days_of_week[ $i ];
unset( $days_of_week[ $i ] );
$days_of_week[ $i ] = $day;
}
return apply_filters( 'tribe_events_get_days_of_week', $days_of_week );
}
but, i want to display in month wise. how can i change my existing code.

How to get all data from easyui datagrid

I had try to use the getData e.g.
data = $("#dg").datagrid("getData");`
var total = data.total; (total is 100)`
var rows = data.rows; (rows.length is 25)`
It can result: the total number is correct like 100 records
but the rows return only get the current page rows like 25 rows.
I need to get all of the records (100 rows).
Is there something i missed ? Or how can we do this ? Please help me.
This is because of pagination. let me describe model with pagination for showing 100 row in php.
function get_invoiceinfoList($search_keyword,$custID){
$page = 1;
$rows = 100;
$sort = '';
$order = 'asc';
$offset = ($page - 1) * $rows;
if($custID > 0 && $search_keyword == 0){
$search = " and a.customer_id =$custID";
}else{
$search = "and (b.name like '%$search_keyword%' || a.inv_no like '%$search_keyword%')" ;
}
$vQuery=$this->db->query("SELECT a.inv_id,a.inv_no,a.inv_org,a.inv_date,
a.customer_id,a.heading,a.quot_id,a.total_cost as total_amount,
a.paid_amount,(a.total_cost-a.paid_amount)as due_amount,b.name
from sales_invoice a,view_customer_info b
where
a.customer_id = b.customer_id $search order by a.inv_date DESC limit $offset, $rows");
$result = $vQuery->result();
$rows = array();
foreach ($result as $rowData){
array_push($rows, $rowData);
}
$data['rows'] = $rows;
return $data;
}

Google geocoding using v3 not showing error

Kindly help on the code below. What happens is that I get the latitude and longitude of the name of a place when I click on a button. However, of late, it is not working. It prints that "Address x failed to Geocode. Received status " Note that x is a given address and no status code is given.
$id=$_REQUEST['id'];
define("MAPS_HOST", "maps.googleapis.com");
define("KEY", "xxxxxxx");
$query = "SELECT * FROM markers WHERE mid = $id LIMIT 1";
$result = mysql_query($query);
if (!$result) {
die("Invalid query: " . mysql_error());
}
// Initialize delay in geocode speed
$delay = 0;
$base_url = "http://" . MAPS_HOST . "/maps/api/geocode/xml?address=";
if($row = #mysql_fetch_assoc($result)){
$geocode_pending = true;
$address = $row["address"];
while ($geocode_pending) {
$request_url = $base_url . urlencode($address) . "&sensor=false&key=" . KEY;
$xml = simplexml_load_file($request_url) or die("url not loading");
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
// Successful geocode
$geocode_pending = false;
$coordinates = $xml->Response->Placemark->Point->coordinates;
//$coordinatesSplit = split(",", $coordinates);
// Format: Longitude, Latitude, Altitude
//$lat = $coordinatesSplit[1];
//$lng = $coordinatesSplit[0];
list($lat,$lng) = explode(",",$coordinates);
$query = sprintf("UPDATE markers " .
" SET lat = '%s', lng = '%s' " .
" WHERE mid = '%s' LIMIT 1;",
mysql_real_escape_string($lng),
mysql_real_escape_string($lat),
mysql_real_escape_string($id));
$update_result = mysql_query($query);
if (!$update_result) {
die("Invalid query: " . mysql_error());
}else{
echo "$lat;$lng";
}
} else if (strcmp($status, "620") == 0) {
// sent geocodes too fast
$delay += 100000;
} else {
// failure to geocode
$geocode_pending = false;
echo "Address " . $address . " failed to geocode. ";
echo "Received status " . $status . "
\n";
}
usleep($delay);
}
}
I'm not sure on which API your code is based on, but the response of the current API will not work with these lines:
$status = $xml->Response->Status->code;
if (strcmp($status, "200") == 0) {
There are no elements Response,Status or code, furthermore the response will not contain a numeric status-code.
use this instead:
$status = $xml->status;
if (strcmp($status, "OK") == 0) {
To fix the rest of the code please take a look at the structure of the returned XML, there are also no elements Placemark,Point and coordinates.
it should be:
$lat = $xml->result->geometry->location->lat;
$lng = $xml->result->geometry->location->lng;

Resources