I am a beginner.
We are currently making simulated shopping and want to implement the paging function on the product screen.
The number of pages can be implemented with the current code, but the first and second pages are the same screen.
How should we improve it?
Please write the details of the question here.
I'm not paging well
Source code
<? php
try {
$dsn = 'mysql: dbname = Photo;host;charaset = utf8';
$user = 'root';
$password = '';
$dbh = new PDO ($dsn, $user, $password);
$dbh->
setAttribute (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION);
$sql = 'SELECT code, name, image FROM photo_product
WHERE 1 ';
$stmt = $dbh->prepare ($sql);
$stmt->execute ();
print '<b>Photo list<br /><br /></b>';
while (true) {
$rec = $stmt->fetch (PDO :: FETCH_ASSOC);
if ($rec == false) {
break;
}
print ' ';
print $rec ['name'];
print '<br />';
print ' ';
print '<br /><br/>';
print '';
print '<br />';
}
$photo_page = 3;
$page = empty ($_ GET ['page'])? 1: (int) $_GET ['page'];
$offset = $photo_page * ($page-1);
$sql = '"select * from photo_product limit". $offset. ",". $photo_page.';
$total = $dbh->query ("select count (*)
, (From photo_product ")->fetchColumn ();
$totalPages = ceil ($total/$photo_page);
$dbh = null;
}
catch (Exception $e) {
print '<br/>There is a problem right now.
<br/>Please wait for a while. ';
exit ();
}
?>
<? php for ($i = 1;$i<= $totalPages;$i ++):?>
"><? php print $i;?>
<? php endfor;?>
-
Answer # 1
-
Answer # 2
$sql = '"select * from photo_product limit". $offset. ",". $photo_page.';
$total = $dbh->query ("select count (*)
from photo_product ")->fetchColumn ();A story like a story
I put it in a variable with $sql, but I write a SQL statement statically at the next execution ...Originally, sql statements should be processed with prepare, and double quotes within single quotes
I don't know what it means to double. Also, if you cut by limit, at least
Requires order by.
Related articles
- an error occurs when calling a function in a php external file from html
- regarding the php bulletin board deletion function
- php - i want to create a function to post reviews
- php - function execution and return value after routing without framework
- php header function error
- php - i'm trying to create a chat function in laravel i get an error when starting laravel-echo-server
- php mysql reply function reply is displayed as a parent comment on the bulletin board
- php - i want to implement a chat function with laravel
- php - regarding passing laravel variables
- php fatal error: call to a member function fetchrow () does not show site
- php - regarding when extracting laravel relation defined data
- php - call to undefined function have_posts () is displayed [wordpress]
- about php search function
- php - i want to create a video posting function
- php - regarding the construction of laravel environment with docker, the installation was successful and the container was start
- php - basic usage of laravelconfig () function
- php - laravel implementation of tweet list function of users who are logged in
- empty function in php if function 3 conditions
- file not found in php's file_exists function
- php - when making a subscription with ec-cube, i would like to add a function that automatically places orders on behalf of cust
- php : How to write the query builder correctly
- php - i am having trouble with sqlstate [hy000]: general error: 2031
- php : SQLSTATE [42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;
- php : joining 2 MySQL tables and outputting data to a table
- php: there is an error in the insert into line and it cannot be resolved
- php - i want to create a condition that contains multiple ands and ors in laravel's query builder
- php - i want to insert data from multiple tbls into one tbl
- php - i want to remove some duplicates of the array acquired by sql
- narrow down by the conditions of the cakephp association destination
- php : Update SQL tables from CSV file
I'm not running this SQL, and here is a grammatical mistake.