-
-
Save mpavel/2492558 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$conn = mysql_connect("localhost", "username", "password" ) or die (mysql_error()) ; | |
mysql_select_db("database", $conn); | |
if( !isset( $_GET['p']) ) {$_GET['p']=0;} // Ideally check if it's numeric also | |
$per_page= 9; | |
$sql= "SELECT * FROM black"; // You don't use this one ... | |
// The first int in LIMIT specifies the start row, thus you need to do $_GET['p'] * $per_page | |
// More importantly you're trying to use both ID and IMAGE columns from your database, but you only select image ??? | |
$sql2= "SELECT * FROM black ORDER BY id Asc LIMIT ".$_GET['p'] * $per_page."," . $per_page; | |
$query= mysql_query( $sql2 ); | |
$rows= mysql_num_rows( mysql_query ( $sql ) ); | |
$pages= ceil ( $rows / $per_page ); | |
// Always read manual: http://php.net/manual/en/function.mysql-fetch-assoc.php | |
// Also, the "convention" is to use while ($row = ...) { } | |
while( $fetch= mysql_fetch_assoc( $query) ){ | |
// Why do you have a $_GET['id'] here? Should that not be $fetch['id'] ??? | |
echo '<a href="chaos_request.php?id='.$fetch['id'].'"><img src="'.$fetch['image'].'"/></a>'; | |
echo "<br/>" ; | |
} | |
for( $i=0;$i<$pages;$i++){ | |
// Do the multiplication in the query, like above, to have a sane pagination | |
echo '<a href="chaos.php?p='. $i .'">'. ($i + 1 ) ."</a> "; | |
} | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$conn = mysql_connect("localhost", "username", "password" ) or die (mysql_error()) ; | |
mysql_select_db("database", $conn); | |
if( !isset( $_GET['p']) ) {$_GET['p']=0;} | |
$per_page= 9; | |
$sql= "SELECT * FROM black"; | |
$sql2= "SELECT image FROM black ORDER BY id Asc LIMIT ".$_GET['p']."," . $per_page; | |
$query= mysql_query( $sql2 ); | |
$rows= mysql_num_rows( mysql_query ( $sql ) ); | |
$pages= ceil ( $rows / $per_page ); | |
while( $fetch= mysql_fetch_assoc( $query) ){ | |
echo '<a href="chaos_request.php?id='.$_GET['id'].'"><img src="'.$fetch['image'].'"/></a>'; | |
echo "<br/>" ; | |
} | |
for( $i=0;$i<$pages;$i++){ | |
echo '<a href="chaos.php?p='. ( $i * $per_page ) .'">'. ($i + 1 ) ."</a> "; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment