Jquery Mobile data-autodividers - jquery-mobile

Is there a way to have the auto-dividers sort by last name?
I don't think it should have anything to do with the php code, but I thought I would include it for a reference below:
$result = mysql_query("SELECT * FROM `patients` WHERE `company_id` = " . $user_data['company_id'] . " ORDER BY `patient_lastname`");
while($row = mysql_fetch_array($result)) {
echo '<li>' . $row['patient_firstname'] . ' ' . $row['patient_lastname'] . '<span class="ui-li-count">DOB: ' . $row['patient_dob'] . '</span></li>';
}
Appreciate any help!

You can do the sorting in the front-end by selecting the list items and sorting them afterward. In the example below, instead of selecting the text content of the list items, you can select the last-name value.
var listContentArray = listViewInstance.find('li').not('.ui-li-divider').get();
listContentArray.sort(function (a, b) {
var first = $(a).text(),
second = $(b).text();
if (first < second) {
return -1;
}
if (first > second) {
return 1;
}
return 0;
});
Then you can destroy the content of the listViewInstance, re-append the elements in the listContentArray, and finally refresh the listView component.
You can download a fully functional example that does all of this at:
http://appcropolis.com/page-templates/autodividers/

Couldn't find a way to display Firstname then Lastname and autodivide by Lastname, so I just replaced the code with:
' . $row['patient_lastname'] . ', ' . $row['patient_firstname'] . '
which displays: "Lastname, Firstname" and autodivides by Lastname. It'll have to work for now.

Related

How can I generate report using Google adwords api without downloading the file?

How can I generate the report CAMPAIGN_PERFORMANCE_REPORT without downloading the file (for example just showing the result).
Here is actually what I do:
$reportQuery = 'SELECT CampaignId,CampaignName, Impressions, Clicks, Ctr , Cost '
. ' FROM CAMPAIGN_PERFORMANCE_REPORT '
. ' WHERE CampaignId = '.$campaignId.' DURING '.$date.','.$date;
// Download report.
ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user,$reportFormat, $options);
$dataArray =file($filePath);
I download the file, then I read from the data to show it up.
Actualy i didn't found a way except that i generate that file then i read from it and i use that result :
$reportQuery = 'SELECT CampaignId,CampaignName, Impressions, Clicks, Ctr , ConversionRate '
. ' FROM CAMPAIGN_PERFORMANCE_REPORT '
. ' WHERE CampaignId = '.$id.' DURING '.$date.','.$date;
// Download report.
ReportUtils::DownloadReportWithAwql($reportQuery, $filePath, $user,$reportFormat, $options);
$dataArray =file($filePath);
foreach ($dataArray as $value) {
$data = explode(",", $value);
$resultat[$i-1]['jours'] = $date;
$resultat[$i-1]['impressions'] = $data[2];
$resultat[$i-1]['clicks'] = $data[3];
$resultat[$i-1]['taux_click'] = $data[4];
$resultat[$i-1]['taux_conversion'] = $data[5];
}
echo json_encode($resultat);
Hope it helps.
After a day I found the solution:
In the source of the lib the method DownloadReport of Utils/ReportUtils.php say that:
Downloads a new instance of an existing report definition. If the path parameter is specified it will be downloaded to the file at that path, otherwise it will be downloaded to memory and be returned as a string.
You can set NULL to path and use the return value
$filePath = null;
$stringOfResult = $reportUtils->DownloadReport($reportDefinition, $filePath, $user, $options);
//now you can parse the result

Remove older $_GET from url

I've got some problems with my url on my website. I'm trying to get a link with the given GET parameters, but i'm getting my previous parameter aswell.
My url looks like this:
www.cdwinkel.dev/search-results?genre=Pop&medium=DVD&medium=Single .
It should be:
www.cdwinkel.dev/search-results?genre=Pop&medium=Single .
I'm running the following code:
$data['url'] = createurl();
function createurl(){
$i = 1;
$string = "?";
$keys = array_keys($_GET);
foreach($_GET as $get){
if($get != ""){
$string .= $keys[$i] . "=" . $get ."&";
$i++;
}
}
$string = rtrim($string, "&");
return $string;
}
$i = 1, because my first value in my array is empty.
And my button looks like this:
<a href='".$data['url'].'&medium='.$names[$i]."'>
I guess I should'nt set &medium=.$names[$i] in the href tag,
but I wont get the new $names[$i] in my function, so I won't get a new url if i wont add it in.
I'm looking forward to your responce.
Sincerely,
Kars Takens
At this point i've created an array with the right arraykeys and values.
$url = array_slice($_GET, 1);
This returns the following array:
array (size=2)
'genre' => string 'Pop' (length=3)
'medium' => string 'DVD' (length=3)
After this I decoded this into a new string:
genre=Pop&medium=DVD
I got 6 button which I created in a foreach loop, but i'm getting &medium='VALUE' Twice. This only happens after the first time. So the first time my button works well.
<?php
$names = array_keys($data['tellen']);
$i = 0;
foreach($data['tellen'] as $m){
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}
Hopefully you can help me further with this information.
I solved my problem by adding this in my forloop:
foreach($data['tellen'] as $m){
if(isset($_GET['medium'])){
unset($_GET['medium']);
$url = array_slice($_GET, 1);
$data['url'] = urldecode(http_build_query($url));
}
echo "<li><a href='search-results?".$data['url'].'&medium='.$names[$i]."'>". $names[$i] ." <span class='product-amount'>(". $m[0]->count. ")</span></a></li>";
$i++;
}

How to generate a grid(Table) with a foreach

My problem is simple, but I'm beginning with cakephp. I'll explain my problem:
I have 2 tables:
Table: Expenditures
Columns:
sub_category_id
account_id
date
ammount
created
modified
description
Table: BudgetRecords
Columns:
budget_id
ammount
sub_category_id
created
modified
I have a 'home-work' to do, and my teacher wants me to do a report. This report will generate a table, and will show an balance (Expenditures.ammount - BudgetRecords.ammount), and each month (BudgetRecords.created, or Expenditures.date, whatever).
Here's my question: I'm trying to do a foreach, passing for each year (if exists), if a year exists, then execute a query for each month. But, how I do that with CakePHP? I've tried to do this only inside the Controller, and it runs fine. But returns me only the last month of the last year. Then, I've tried a different approach.
Inside the View, execute the query and search if exists the year. If exists, then search for this month. Then gives me back the result.
That's what I did:
Inside the View:
<table align="center" border="2" rules="All">
<tr>
<td>Valor:</td>
<td>Data:</td>
</tr>
<?php
for ($month = 1; $month <= 12; $month++) {
if (strlen($month) == 1)
$month = '0' . $month;
foreach ($Expenditure->SaldoMes($month) as $result) {
echo "<tr>";
echo "<td> R$:" . $result[0] . "</td>";
echo "<td> " . $result[1] . "</td>";
echo "</tr>";
}
}
?>
</table>
Inside the Controller:
public function SaldoMes($month = null) {
$month = 0;
for ($month = 1; $month <= 12; $month++) {
if (strlen($month) == 1)
$month = '0' . $month;
$query = "SELECT (SUM(ex.ammount) - SUM(br.ammount)) as total , br.created as data
FROM budget_Records br, expenditure ex
where SUBSTRING(br.created, 6, 2) = '" . $month .
"' and SUBSTRING(br.created, 6, 2) = SUBSTRING(ex.created, 6, 2)";
$this->set('Expenditure', $this->Expenditure->query($query));
foreach ($this->Expenditure->query($query) as $records) {
$this->set(('Total'), $records[0]['total']);
$this->set(('Data'), $records['br']['data']);
}
}
}
I hope I've explained my problem well enough for someone to show me a solution.
I think this will help
http://book.cakephp.org/2.0/en/controllers.html
This part is what you are looking for I think. Taken from that website.
<?php
# /app/Controller/RecipesController.php
class RecipesController extends AppController {
public function view($id) {
//action logic goes here..
}
public function share($customer_id, $recipe_id) {
//action logic goes here..
}
public function search($query) {
//action logic goes here..
}
}
"The view files for these actions would be app/View/Recipes/view.ctp, app/View/Recipes/share.ctp, and app/View/Recipes/search.ctp. The conventional view file name is the lower cased and underscored version of the action name."
So if you wanna just use another method like SaldoMes() then just call it in the view method.
#earlonrails, solved:
public function SaldoMes() {
$result = array();
for ($month = 1; $month <= 12; $month++) {
if (strlen($month) == 1)
$month = '0' . $month;
$query = "SELECT (SUM(ex.ammount) - SUM(br.ammount)) as total , br.created as data
FROM budget_Records br, expenditure ex
where SUBSTRING(br.created, 6, 2) = '" . $month .
"' and SUBSTRING(br.created, 6, 2) = SUBSTRING(ex.created, 6, 2)";
$this->set('Expenditure', $this->Expenditure->query($query));
foreach ($this->Expenditure->query($query) as $records) {
$result[$month][0] = $records[0]['total'];
$result[$month][1] = $records['br']['data'];
}
}
return $this->set('result', $result);
}
Using the $result array, now i can get my values.
Thanks for teh help.

How to call value of selected List from Jquery

I want to call the value of selected li with jquery . Here is my ul list,get data from Database and
<ul id="scroller1">
<?php
$globalregion_result = mysql_query("SELECT * FROM GlobalRegion");
$i = 0;
while($globalregion_row = mysql_fetch_array($globalregion_result)){
echo "<li id='scroller1_" . $i . "' value='" . $globalregion_row["GlobalRegionID"] . "'>" . $globalregion_row["GlobalRegionName"] . "</li>";
$i++;
}
?>
</ul>
Here is my jquery call for list
var scroll1SCell = null;
var scroll1SVal = $("#scroller1 .active-item").attr("value");
It show "undefined" at console.
The li's id is something like: id='scroller1_" . $i . "'. Which means you'll have to use that specific selector to find the element:
var index = // get the index of the li you need.
$("#scroller1_"+index).attr("value");
As #rgthree pointed out you're using li's incorrectly. These elements are meant to just be lists of text or other elements, but not select boxes. The value attribute is not a valid attribute. Instead you might want to use this code:
HTML:
<select id="scroller1">
<?php
$globalregion_result = mysql_query("SELECT * FROM GlobalRegion");
$i = 0;
while($globalregion_row = mysql_fetch_array($globalregion_result)){
echo "<option value='" . $globalregion_row["GlobalRegionID"] . "'>" . $globalregion_row["GlobalRegionName"] . "</option>";
$i++;
}
?>
</select>
JS:
var value = $("#scroller1").val();
This will work:
$("#scroller1").val();
var scroll1SVal = $("#scroller1 option:selected").val();

jQuery UI Autocomplete: return only strings that use input as prefix

I am using jQuery Autocomplete 1.8. Every time it returns every string that contains the input as a substring. How can I make it return only the strings that contains the input as a prefix?
I'm doing it in the sql. I'm using php to generate the json
<?php
set_include_path(get_include_path() . ':' . '/home/lms/library/php');
set_include_path(get_include_path() . ':' . '/home/lms/systems/ORM');
require_once("Configuration.php");
require_once("DALI_Class.php");
//$unitID = $_POST['unitID'];
$unitID = $_GET["term"];
$return_array=array();
$row_array=array();
$lmsAdminSysDB = DALI::connect(LMS_MIDDLEWARE_DATABASE);
$selectUnit = "SELECT " .
"UnitID, " .
"Title " .
"FROM UnitTBL " .
"WHERE UnitID LIKE '".$unitID."%' " .
"ORDER BY UnitID " .
"";
$resultUnit = $lmsAdminSysDB->Execute($selectUnit);
while($row = $resultUnit->FetchRow()) {
$row_array['label'] = $row['UnitID']." - ".$row['Title'];
$row_array['value'] = $row['UnitID'];
$row_array['title'] = $row['Title'];
array_push($return_array,$row_array);
}
unset($resultUnit);
//header('Content-type: application/json');
//echo json_encode($result);
DALI::disconnect($lmsAdminSysDB);
echo json_encode($return_array);
?>

Resources