gskurski Posted November 6, 2010 Share Posted November 6, 2010 Hello! I have a database of small image / names that I want to pull into a 3 x 4 table. My current code works perfectly if I have 12 images or less, but I will have more than 12 images. Currently the code is set up to retrieve and display the images in a table, three per table row. I want it so that when it reaches the 4th row in a page it generates a link to another page that has the next 3 x 4 (12 total images) page. I tried to follow the code on http://www.phpfreaks.com/tutorial/basic-pagination, but after I get it to what I think it should be, my page is blank -- but not due to an error, it's just blank. My code so far is: <?php $username = "xxxx"; $password = "xxxxx"; $host = "localhost"; $database = "images"; $conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); $db = mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $sql = "SELECT * FROM block_work ORDER BY Name"; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); header('Content-type: image/jpg'); $counter = 0; while ($row = mysql_fetch_array($result)) { if($counter==0) print "<tr align='center'>"; ++$counter; print "<td align='center' width='179' height='200'><img src='/management/show.php?id=" . $row['id'] . "&table=block_work' alt='" . $row['name'] . "' /><br/>"; print "<b>" . $row['name'] . "</b></td>"; if($counter==3) { $counter=0; print "</tr>"; }; }; while ($counter>0) { ++$counter; print " <td> </td>"; if($counter==3) { $counter=0; print "</tr>"; } } print "</table>"; mysql_close($con); ?> Thanks very much for any help! -Gerry Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2010 Share Posted November 6, 2010 Is that all of the code? Quote Link to comment Share on other sites More sharing options...
gskurski Posted November 6, 2010 Author Share Posted November 6, 2010 It's all of the PHP code that's on the page. There is some HTML before it that has some menu code, as well as the code that starts the actual table that's being produced. I also didn't include the code for the show.php page that the img tag refers to. The code for that is : <?php $username = "xxxx"; $password = "xxxxx"; $host = "localhost"; $database = "images"; $conn = mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error()); $db = mysql_select_db($database) or die("Can not select the database: ".mysql_error()); $id = $_GET['id']; $table = $_GET['table']; if(!isset($id) || empty($id)){ die("Please select your image!"); }else{ $sql = "SELECT * FROM $table WHERE id=" . $id; $result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR); $row = mysql_fetch_array($result); $content = $row['image']; header('Content-type: image/jpg'); echo $content; } ?> Again, thanks for the help! Quote Link to comment Share on other sites More sharing options...
gskurski Posted November 8, 2010 Author Share Posted November 8, 2010 Ideally, what I'm looking to do is display results from my database in an html table like this: Result 1 Result 2 Result 3 Result 4 Result 5 Result 6 Result 7 Result 8 Result 9 Result 10 Result 11 Result 12 Page 1 - 2 - 3 - 4 or however many pages would be generated by the amount of records in the table. Right now I can get it to display the results in a table such as the one I just described, but it would just keep creating new rows of 3 beyond the 12th result. I want to paginate it but I am having trouble implementing any code for pagination that I've found with the loop I use to make the table appear the way it does. Can anyone help? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.