I have a visitor counter that works. Now, I need to get the results back to display them into a chart. What I have now in my controller to display them works, but the date is wrong.
This is what I have:
$select_stats = DB::table('visitor')->where('visit_date', '>', '2015-04-01')->where('visit_date', '<', '2015-04-30')->get();
foreach($select_stats as $statics) {
//change our object to an array
$statics = array();
}
return View::make('admin.home.index')->with('stats', $select_stats);
I need to get the 'stats' from the current month, so in this case month 4, but if it is may, then it needs to select automatically the stats from the 5th month.
So that is already a problem for me.
Now, I need to loop them in my blade themplate, that works... But the date is in the format
YYY-MM-DD
I don't want it displaying like that I do prefer the format:
DD/MM/YYYY
Okay, so far, so good.
I also need to count the IP's that are stored in the database. Also from THAT month.
And also need to loop and display the count.
The database model I have:
The table name is called visitor.
My blade template for the chart:
<script type="text/javascript">
var visitors = [
#foreach($stats as $stat)
['{{ $stat->date }}', 500],
#endforeach
];
</script>
Yes, this works in the script.
If you're always dealing with the current month, try this:
$select_stats = DB::table('visitor')->whereBetween('visit_date', array(date('Y-m-01'), date('Y-m-t')))->get();
the lowercase t in the date function returns the number of days in the given month (http://php.net/manual/en/function.date.php).
Simply put, to convert that date format in your template, you could echo it as the following:
{{ date('Y/m/d', strtotime($stat->date)) }};
To get the count of the IP's you could perform the same query but add replace ->get() with ->count() like so:
DB::table('visitor')->whereBetween('visit_date', array(date('Y-m-01'), date('Y-m-t')))->count();
You already have the IP field from the first query, so just echo out {{$stat->ip}}
There's always different & better ways to achieve certain results, but without context, here's a solution that works.
Related
i retrieve data between two dates but the problem is to retrieve data between two dates for specific person so for i used this this is working perfectly when i only retrieve data between dates but did not work when i use dphone means for specific doctor phone number
$result = mysql_query("SELECT * FROM checker WHERE date between '$fromdate' AND '$todate' AND dphone='$splist'"
i want to retrieve data where dphone match any suggestion please so i can retrieve data according to my need
Try like this instead:
SELECT * FROM checker WHERE dphone='$splist' AND date BETWEEN '$fromdate' AND '$todate'
Also, are you sure the value in the "dphone" field for the doctor you're trying to get, matches $splist exactly?
I'm trying to create a class schedule here.
I know I'm not supposed to ask before trying anything, the problem is I can't think of any logic to do this.
As you can see I have a table as below
What I want to do is, I want to store the data in the database, and when I retrieve the data, I want to display it in the exact same location as the picture. Please help me out.
EDIT : I'm a beginner in programming please go easy on me
Code the PHP to create the HTML to display the schedule as it is in the image above, but without the courses. Hint: you should use a two dimensional array of days and times.
Create a two dimensional array of the schedule, using array keys that match those you created in step 1.
Write the code to put the schedule from step 2 in the display from step 1.
Create your database and a table for the schedule.
Write the code that reads the schedule from the database, discard the code that put the schedule into the display from the array.
Here is an example :
store data like this:
this is the query.
$query = "SELECT time_format(schedule,'%T') as schedule,
if(dayname(schedule)='Sunday',subject,'') as Sunday,
if(dayname(schedule)='Monday',subject,'') as Monday,
if(dayname(schedule)='Tuesday',subject,'') as Tuesday,
if(dayname(schedule)='Wednesday',subject,'') as Wednesday,
if(dayname(schedule)='Thursday',subject,'') as Thursday,
if(dayname(schedule)='Friday',subject,'') as Friday,
if(dayname(schedule)='Saturday',subject,'') as Saturday
FROM scheduleTable
WHERE schedule between '2016-7-25' and '2016-7-31 23:59'";
3.this is the result from the query
Then you can use PHP to style the table or send it to Ajax let javascript do the job.
I'm trying to get value from a cell with a type "Time".
In the sheets it's look like just: "15:40" (filled manually)
If I use getValue() from this cell, and setValue to another cell it will be no problem.
But when i'm trying to manage some parsing with regexp i'm getting an error like:
TypeError: Can't find a function match in object "Sun Dec 31 1899 05:22:00 GMT+0300 (MSK)."
Here is the code itself, it's simple:
...
var sheet = SpreadsheetApp.getActiveSheet();
cell = sheet.getRange(1, 1).getValue();
cellpart = cell.match(..:..);
...
Debug says that type im getting not a "String", but "Data" and its value is in the double quotemarks in the errormessage above.
How can i get a string value from the cell? Looks like simple, but i spent all night trying to get whats wrong. Any Help will be appreciated.
To make your data into a string you can use .toString()
cell.toString().match(..:..)
Note that cell is a Date object. That's why it doesn't support .match, but you can make it into a string, which will make it the string value "Sun Dec 31 1899 05:22:00 GMT+0300 (MSK).".
I have also run into this problem when creating a mail merge from sheets. I have not had the need to match/ search through these values but the first step in this process is to get the data into a format that you want. After that you can rewrite it back to the cells or process from there.
Below is my method to transfer the date format, then write the values into an array in the format I need. This effectively removed all of the extra garbage date information. Once I had a clean dates, I was able to manipulate that data without a problem.
var rawSubmitDate = sheet.getRange((i+2), 1, 1, 1).getValue();
var submitDate = Utilities.formatDate(rawSubmitDate, "PST", "MM/dd/yy");
This first portion was used with a loop of the rows with data. You can see I use .formatDate() to set the long data form into what I want. You can find more information on how to format the way you need in the GAS reference as well as online on the syntax of date formats.
var lastColumn = sheet.getMaxColumns();
var dataRow = sheet.getRange((i+2), 1, 1, (lastColumn - 2));
var dataArray = dataRow.getValues();
dataArray[0][2] = whenA;
dataArray[0][25] = whenB
dataArray[0][37] = whenC;
dataArray[0][40] = whenD;
dataArray[0][43] = whenE;
dataArray[0][46] = whenF;
In this section I create an array of all of my values and write my cleaned dates into that array. The [] values are defined by their column index in my row. For instance, the 26th row contained a date that needed to be reformatted (whenB). These dates were things like DOB, time of incident, etc.
I have not written code to place these values back into the sheet because I use QUERY() functions to populate the sheet I pull from. Writing values into the cells involved in a QUERY() will throw an error. The process however would require a nested loop. The outer loop cycles through rows and the inner loop cycles through the column cells in the row writing each data array value. Outer loop index would be defined by the number of rows you have; Inner loop index would be defined by the number of columns you have.
Try using getDisplayValue( instead of getValue(. This will return the cell value as it appears rather than the underlying Date value.
This is the best way I have found to extract a Duration (inserted from a Google Form) without all the gobbledygook inherent in a Date value.
I need to generate one ticket number using the given sequence which is given below using PHP.
1-W1(mandotary).
2-date(yy-dd-mm)format.
3-001-999(each day it will start from 001).
One example is given below.
e.g-W120160121001
I have done the below part which is incomplete.
if($_REQUEST['typeOfApp']=="WEB"){
$ticket_id='W1'.date("Y-m-d").'';
}
Suppose one click event I will generate this ticket number and each day the last 3 digit of this ticket number will start from 001 and up to 999.
PHP does not have a mecanism to synchronize a bloc code execution
2 users can obtains the same ticket number !!
also, you have to store the current ticket number somewhere !!
Personally, i've wrote an open source project that holds ans synchronize the access of variables, you can get it from here in github :PHP - Synchronized Data Structure Server
And there are other solutions, like storing and incrementing in synchronized flavor using database
Add one more field like id in your table, which stores id number of your ticket booking. and one more query you have to add before inserting the record in the table.
First check that how many records it will have for the same date? and then increment the count of that record and append your dynamic generating ticket code as follows.
$ticketnumber = 'W1' . date('YdM'). str_pad(($tempid + 1), 3, '0', STR_PAD_LEFT);
$tempid is the key which is added/started from 1 for the same date.
$file = 'ticketfile.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Increase ticket number
$current=$current+1;
// Write the contents back to the file
file_put_contents($file, $current);
$ticketNum = "W1".date('dmy').$current;
echo($ticketNum);
// This will echo out something like this
// W121012016001
You can also save the ticket number to a database and call last recored before creating new ticket.
Possible you only need something like this:
$ticketnumber = 'W1'.date('YdM' time()).str_pad($value, 3, '0', STR_PAD_LEFT);
$value is the last ticket key entered for the day. This could be handled by a function to check the last ticket day. If the same date +1 the count. if it is not same date reset the counter.
So lets say you have the following function to generate the ticket code:
function ticket_id_generator($ticketnumber){
$dateline = intval(substr($ticketnumber, 2, 8));
$value = intval(substr($ticketnumber, -3));
if($dateline == date('YdM', time())
return $value++;
else
return '1';
}
I've created a dashboard through using d3.js and I thought I had finished but it turns out that the static example data that I had been given is different to what the actual data is now the system is about to go live.
I'm loading the data from an csv for this I'm looking to find the budget for the correct month. This specific data is not being used to create the chart that is separate data completely this is being used so that under that graph I can have text elements saying things like Total sales Today = £80,000 for example. The old data I was given was in this format:
Target
9999999
So I this is the code I had for that data:
d3.csv("data/OrderValueTarget.csv", function(obj) {
var text = 'Budget = £';
var targetSales = text + d3.format(',')(obj[0].Target);
svgLabel = d3.select("#label2").append("h2")
.text(targetSales)
});
Which works great when the data was in the older format however now that data has changed quite a bit. This is what it looks like now for example:
Month,Target
APR,2222221
MAY,2222222
JUN,2222223
JUL,2222224
AUG,2222225
SEP,2222226
OCT,2222227
NOV,2222228
DEC,2222229
JAN,2222220
FEB,2222221
MAR,2222222
So what I've been asked to do is have something that can look up the month we are in and change the value to the corresponding month. So is there any way I can do that within d3/javascript? So if I wanted to Months budget from SEP its would just say Budget = £2222226
Thanks