php script where clause
php script where clause
kevin2012
Posts: 7Questions: 1Answers: 0
In the server side scripting using PHP, if I have multiple tables, how can i specify a query like this :
select a.first_name, a.last_name, b.date from users a, birthdays b where a.id = b.user_id order by b.date desc.
Thanks for your help !
This discussion has been closed.
Answers
2 ways:
one:
another way
Thanks, mkleinosky. I like the first solution better, way easier. Is there any added benefit with the second approach ?
Second one works nicely if you are using Editor. In fact, it looks like the first also uses the Editor database libraries.
Other options exist such as using PHP's PDO interface to query the database,
mysqli
, etc. I would suggest referring to the PHP documentation and tutorials available on the web if you aren't sure how to query the database in PHP.Allan
I've been trying to get my head around adding a Where clause for the last 2 days. I'm using Editor and hoping someone can help me out.
I'd like the table to only show results based on the GET URL, eg ?order_number=9
Demo URL:- http://tinyurl.com/ppqgw99
HTML/JS:- http://tinyurl.com/kx99ofy
PHP: http://tinyurl.com/lammcj4
I've read the documentation at https://editor.datatables.net/manual/php/conditions and I've made some progress...
When I hardcode for example:
->where( 'order_number', 9 )
->process( $_POST )
->json();
to my "table.order_inventory.php" it correctly shows only the rows from order 9.
I don't understand how to dynamically change the order number though. I think it needs to be sent through the Javascript/Ajax request but all of my attempts (not saved) haven't worked. Guessing I need something like this though:-
If someone could show me an example I'd appreciate it =)
Cheers
Use the
ajax.data
option to send the order option to the server, which you can then get using$_REQUEST['order_number']
(or whatever variable name you select) to apply to the condition.Allan
where can i find Datatables.php ?
It is in the
php
directory of the Editor package.Allan
I'm not really looking for editor capabilities. Just want to display the table from a php/mysql datasource. I also want to ability to add checkboxes and radio buttons as columns so that I can make some selections and capture them when a submit button is clicked on the page.
What is the best way to achieve this ?
Simply get the data from the database using an SQL query (there are lots of tutorials about how to do this in PHP available on the web) and then JSON encode the results so DataTables can read it by Ajax.
Allan