php data between two dates for specific person - javascript

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?

Related

is there any way to select all the fields data from the table except one field data using nodejs

I want to fetch all the fields data but don't want to specify the fields name and don't want to create a view.
I have tried
WITH orderschema as
(SELECT array_to_string(ARRAY(SELECT c.column_name
FROM information_schema.columns As c
WHERE table_name = 'orders'
AND c.column_name NOT IN('Quantity')
), ','))
SELECT * from orderschema
but this is returning the schema fields name as a single string and i can't use this single string to get all the fields from the orders table.
is there any way to exclude the field directly in psql?
Generally speaking no such way exists.
But - if you plan on converting data to JSON in Pg (which you shouldn't for performance reasons, but you might if you really, really want to), you could just delete the column from json.
The best way, though, is to write query that lists only the columns you need.

Sql query for data stored as JSON

I have data stored in column as JSON, as shown below:
{"category":{"value":CAT, "demo":A.......
I want to query in SSMS and want an output like:
CAT
I tried "SELECT JSON_QUERY(TABLENAME,'$.CATEGORY') FROM TABLENAME" which gave result of the
{"value":CAT, "demo":A....... but I want only CAT. How do I do that?
Use JSON_VALUE to get specific values.
SELECT JSON_VALUE(TABLENAME,'$.CATEGORY.VALUE') AS Value
JSON_QUERY is for JSON fragments.
Source
You should use JSON_VALUE.
SELECT JSON_VALUE(ColumnName, '$.category.value') FROM TableName
Take note of the first parameter, it should be the column name, not the table name (as opposed to your example).

PHP: How to remove/disable a selection from a checkbox group if the value is already selected and stored in database previously

Right now I am coding in PHP & HTML
I need to make a selection from the checkbox group
and it goes like this:
The value in the dropdown menu is retrieved from the value stored in the database in table subject. So the checkbox options will appears as (for example) Mathematics, Algebra, Calculus, English, Linguistic etc. -- I have no problem with displaying this one.
Table subject
subject_id subject_name
========== ============
1 Mathematics
2 Algebra
3 Calculus
4 English
5 Linguistic
So after that, a student can choose their subject and it will be stored in another table named student_subject where it stores the student_id and the subject_id (to store what subjects did a student chose)
Example:
table student_subject
student_id subject_id
========== ===========
1 1
1 2
1 3
2 1
2 3
Now, the student comes again to add another subject to his profile. The same checkbox option will be displayed as mentioned earlier in (1) but I would love to disabled/remove/not display the already selected option from being selectable again to avoid redundancy.
I really have no idea on how to create this function. I know there are a lot of experienced programmers and developera here so I wish you could show me the right way. Your guidance is highly appreciated.
You should not remove/disabled/not display the existing subjects.
First, you should check for existing rows for student_subject table and render it in HTML checkbox as selected.
Second, while student makes changes for subject selection in edit mode, check with the database rows with student and subject ids in a loop.
If submitted subject id for the student is not available in the database, insert that value to the table.
If submitted subject id for the student is available in the database, do nothing with it.
Check for the removed subject from submitted values with the database, and delete from the database.
If you want to disable existing subjects, use readonly to the checkbox if the subject is assigned to the student.
This is just an idea:
On your #2 where a table will store student_id and subject_id, I think it's best that whenever you store value to subject_id- you just serialize the value by storing it on an php array in that way you can iterate the whole array if the field was checked or not.
Json_encode is also good since it will be a string and same as serialize
Example:
Student_id Subject_ID
999-0518 a:{this is the serialize value };
Then when you query the result it will be serialize, then use unserialize function and do a loop to iterate the results, same goes when you json_encode; just perform json_decode() function and perform loop.
You can use a query which only picks up subjects which ID isn't in student_subject.
It would look something like:
SELECT * FROM `subject`
WHERE `subject_id` NOT IN (
SELECT `subject_id` FROM `student_subject` WHERE `student_id` = '1'
)
(you can ommit the inner where clause if you don't want this to be user specific)
and then build the <select> element based on the array returned from it.

Laravel count the IP adressess from this month

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.

Sort two table's by date and show output in html <table>

I have a PHP code ready which will fetch data from a mysql database,The PHP code will also display the data in tabular form.
What I want to Achieve:
I have a dummy database named "stackoverflow" with two tables "customer" & "receipt"
both of these tables have a field called "date" with datatype as date as well.
full schema here
I want some selected entries from these tables to appear in an html table.
the entries should be sorted by date in increasing order.
What I have tried and accomplished:
The data is fetched and shown in tabular form successfully, but date wise sorting is partially complete.
output of my result (without php code since jsfiddle doesn't support php)
I have used PHP to compare dates between dates of each table and then show the respective data
<?php
while( $kb = mysql_fetch_assoc($customer) ){
customer_data($kb); //function which echos <tr>'s of customer table
while($cd = mysql_fetch_assoc($reciept)){ //function which echos <tr>'s of reciept table
if($cd['date'] <= $kb['date']){
reciept_data($cd);
break;
}
}
}
?>
Problems I am facing:
The sorting is not exactly like what I wanted. (only some of them are as per increasing date order).
link to my whole project file with database schema and sample data (just import into phpmyadmin) for reference: http://www.mediafire.com/?bcbvkn8uq89ya6n
If you are still confused about what kind of output I am trying to get.I made a table in excel here's the Image:
I am struggling with this problem since a couple of days. I think this is due to my lack of sql skills?. Any help would be appreciated.
Thanks!
UPDATE:
This is how I pickup data from the tables using php:
$customer = mysql_query("SELECT * FROM customer WHERE customer_name = '$name' ORDER BY date ASC ");
$reciept = mysql_query("SELECT * FROM reciept WHERE name = '$name' ORDER BY date ASC");
After some research, I came across the UNION operator which joins two select statements, and I developed this query:
SELECT DATE, customer_name, grand_total
FROM customer
WHERE customer_name = 'JHON'
UNION ALL
SELECT DATE, name, recd_amount
FROM reciept
WHERE name = 'JHON'
but I could only select equal no. of columns in both select statements, and how do I order by date?
You should use '==' for equality comparison in if statement. '=' will assign a value to the variable
if($cd['date'] = $kb['date']){
to
if($cd['date'] == $kb['date']){
Order by in union
$query = " (SELECT DATE, customer_name, grand_total
FROM customer
WHERE customer_name = 'JHON')
UNION ALL
(SELECT DATE, name, recd_amount
FROM reciept
WHERE name = 'JHON')
order by customer.Date desc"
a helping link
MYSQL UNION ORDER BY

Categories

Resources