Print mysql result 10 by 10 php css page break after - php

For example I have 100 result in my query.
I want to printing paper every page 10 result.
How to print php mysql query result 10 by 10 css page-break-after?

You did not ask your question very well in English.
But I think that you can run your query like this :
SELECT * FROM tableName ORDER BY fieldName DESC LIMIT $startIndex, $count
Which $startIndex could be your starting number and $count could be 10 in your case.
NOTE Do not forget to edit my code and use prepared statement in your query

Related

Selecting the next set of records from a MYSQL database table - PHP

I would like to know the syntax of how to construct a sql query that retrieves sets of data from the database. For example, I am able to retrieve a set of 10 records from a table , but then would like to retrieve the next ten after that based on the same query.
PHP
$limit = 10;
$SQl = "SELECT * FROM myTable LIMIT {$limit}";
What would the sql query be for the next 10 records, given that I already have the previous 10 records and would not want them to also be retrieved?
There are two options:
LIMIT 11, 10
and one more:
LIMIT 10 OFFSET 11
Legend:
11 - start row
10 - how much rows

php - Making a pagination by Limiting results from Mysql Database [duplicate]

This question already has answers here:
PHP & MySQL Pagination
(4 answers)
Closed 7 years ago.
im making a script that gets some rows from mysql and returns them to user
after some time.those rows numbers got increased like 300 and now loading page takes a little time.
i wanted to page them.every page contain 50 of them so i have 6 pages and i mean:
row 1-50 in page 1
row 51-100 in page 2
row 101 to 150 page 3
row 151 to 200 page 4
row 201 to 250 page 5
row 250 to 300 page 6
i have some idea about limiting them by using LIMIT in my mysql query but dont know how to make button for it(page buttons)
i want the code to do this
sorry for my bad english, i hope you understand.
Use LIMIT in your SQL statements.
SELECT * FROM `wherever` ORDER BY `whatever` LIMIT 0,50
Then replace your starting point (0) with a PHP variable, and set that variable as $start = $page_number * 50;
SELECT * FROM `wherever` ORDER BY `whatever` LIMIT $start,50
Read mysql LIMIT syntax here: https://dev.mysql.com/doc/refman/5.0/en/select.html
The first number is the start, second number is how many more to go. Unless only one number is given in which case its how many more to go.
As far as a button is concerned, there are a few ways to do this. But the basic maths are here:
$total_rows = mysql_num_rows(mysql_query($original_query_without_limit));
$total_pages = $total_rows / 50;
$prev_page = $current_page - 1;
$next_page = $current_page + 1;
if ($prev_page > 0){
// Print previous page link/button
}
if ($next_page < $total_pages){
// Print next page link/button
}
Try using the OFFSET query
SELECT * FROM `table` LIMIT 50 OFFSET <amount>

PHP / SQL - Show specific number of rows per query

I apologize if this question has been asked already, I'm sure it has I just was not able to find a similar question/answer that solved my problem.
I am pulling data from PostgreSQL and I have an SQL statement similar to:
$SQL = "SELECT * FROM my_view_table WHERE id='".$my_id."'";
From this I run my query. The request pulls from a view in PostgreSQL which looks through more tables. That is correct. I'm not sure how to limit the number of rows to display. I receive about 1,000 rows of information with about 20 columns of data so it takes an incredible amount of time to query.
Is there a way to ask for rows 0 - 100, then 101 - 200, etc, so I can pull 100 at a time to display? I know I'll have to use a little code to keep track of the count, but I just need some SQL help with querying "x to y" rows.
Thank you for the help with this issue. (If there is another very similar question that has already been answered a link to that would be a sufficient answer!)
I've posted the answer to my question down below.
I found the answer to this question from gnarly's suggestion of LIMIT on SQL
$sql = "SELECT * FROM my_table LIMIT X OFFSET Y";
Where LIMIT only gives the X number of rows you want, and OFFSET gives the Y starting point. So showing rows 0 through 30:
$sql = "SELECT * FROM my_table LIMIT 30 OFFSET 0";
And showing rows 31 through 60:
$sql = "SELECT * FROM my_table LIMIT 30 OFFSET 30";

Mysql query - using like <something> and <something='1'> with limit

I am being stumped over this problem, and I can't seem to figure it out, hoping someone here can do make heads or tails over this.
When I use the following to query my database:
$q = "SELECT * FROM items WHERE (searchable='1' and title LIKE'%".$_srch."%')";
the items show up they way they are supposed to. But when I add limit 10, 5 to the end:
$q = "SELECT * FROM items WHERE (searchable='1' and title LIKE'%".$_srch."%') limit 10, 5";
The query shows up nothing. I have tried everything I can think of, but I must have missed something. Someone help?
Thanks
By using LIMIT 10, 5 you're stating that you want the database to start displaying from the 11th row, and display 5 rows. (11th, 12th, 13th, 14th, 15th) - It might be possible that you actually, don't have enough rows.
Try something like, LIMIT 0, 5 - this will display the first 5 rows from the beginning, but 10, 5 will only work if you have more than 10 rows for the search query.
Read more here: http://www.mysqltutorial.org/mysql-limit.aspx
The Limit clause arguments are offset and number of items respectively.
So the query you write would show 5 rows starting from the 10th row.
How many rows does your original query show. If it is less then 10 rows then the limit query you provide wont work as the number of rows are less.

PHP output couple times data from a column

How do I output data from column, but to be like.. for example - the column is with 40 lines of query results and I want to output only that, that are from 10 to 30 . How to do it with PHP?
For MySQL, you could use a LIMIT offset, maxrows:
SELECT * FROM tbl LIMIT 9,20;
will get you rows 10-30. Note that the offset value is 0 based, hence the 9 rather than 10.

Categories