Ok
What i have is a button on a page called invoices. now when this button is clicked it goes to the invoices page.
Now on this page i want it to display a table showing the top 300 or so records returned from a basic select query.
My question is how do i get it to display the rows returned by the query in such a table and then a possible drop down to expand the query.
Also if possible once it displays the results i would like the record to be editable somehow so they could update certain fields.
Any help would be greatly appreciated im really struggling
Thanks in advance.
Queries in php
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Queries in php
You don't paste any code so i'll work on the assumption that you have none at the moment.markyboy17 wrote:My question is how do i get it to display the rows returned by the query in such a table and then a possible drop down to expand the query.
To display data once you have selected it is passed to a function that fetches the data; mysql_fetch_array, mysql_fetch_row or mysql_fetch_object.
Code: Select all
<?php
$query = "SELECT field, field1 FROM table LIMIT 0, 300";
$sql = mysql_query($query);
// start to display data
while ($ary = mysql_fetch_array($sql)) {
echo $ary['field'];
echo $ary['field1']
}
http://www.plus2net.com/sql_tutorial/sql_limit.php
To have this option as a dropdown menu you need to modify your query to accept input from a form;
Code: Select all
<?php
if (isset($_POST['dropdownValue'])) {
$limit = $_POST['dropdownValue'];
}
else {
$limit = 300;
}
// select query will look like this
$query = "SELECT field, field1 FROM table LIMIT 0, ' . $limit . '";
$sql = mysql_query($query);
// proceed as normal
Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: Queries in php
That's a very broad question. You are essentially asking, "How do I write a PHP script to display database records that can be edited by the user, updating the database, and flexibly displayed in pages?" This is much, much more than can be answered in a couple of posts to a forum! I think the best way to help you is to refer you to several online resources that deal with these programming techniques.markyboy17 wrote:Ok
What i have is a button on a page called invoices. now when this button is clicked it goes to the invoices page.
Now on this page i want it to display a table showing the top 300 or so records returned from a basic select query.
My question is how do i get it to display the rows returned by the query in such a table and then a possible drop down to expand the query.
Also if possible once it displays the results i would like the record to be editable somehow so they could update certain fields.
Any help would be greatly appreciated im really struggling
Thanks in advance.
For basic display of database data in an HTML table, I recommend:
http://scriptplayground.com/tutorials/p ... -with-PHP/
For pagination (displaying a particular number of records at a time and allowing the user to page forward and back), I recommend:
http://www.phpfreaks.com/tutorial/basic-pagination
For making the data editable (and updating the database), all the above will have to be done with the data elements displayed in an HTML Form, then another PHP script (or the same one, if you divide your script into 2 sections and determine each time whether it is being called upon to display the data or update the database) will update the database. For this, I recommend:
http://blog.chapagain.com.np/very-simpl ... ay-in-php/