Hi everyone, below is a copy of my script, that uploads pictures of sports from my database onto my website.this based on the subject type, i want to be able to modify this script to also upload pictures from all the different subject type on to their own individual pages, without me having to write the same code over again and over again for each subject type. At the moment theres six different subject type inputs (for example in subject type there sports, people,careers,animals etc) in my table called general cartoons. (I know I might not be making nay sense, but its hard to explain something without the person seeing it,if you understand what I mean, Im in desperate need of sorting this out!) Im very new to using php and my sql and I've search everywhere on the web to help me with this problem. Thank you <?php session_start(); require "connect.php"; $query = "select * from general_cartoon where subject_type='sport'"; $result = @mysql_query($query, $connection) or die ( "Unable to perform query. $query ".mysql_error()); //require "shoppingcart.php"; ?> <html> <body> <center> <h1><img src="logo.jpg" align=center width="600" height="200"></h1> </center> <html> <body> <table border=0 width=900> <tr> <td valign=top width=200> <p><a href="homepage.php">ARTIST[/url]</p> <p><a href="gallery.php">GALLERY[/url]</p> <p><a href="">CONTACT[/url]</p> <p><a href="customerlogin.php">SIGN IN/ SIGN-UP[/url]</p> <p><a href="">FORMAT/PRICE[/url]</p> <p><a href="shoppingcart.php">VIEW SHOPPING CART[/url]</p> </td> <td valign=top width=700><p> <ol type="A"> <font face="scans-serif" color="Purple" size="+5" align="right" >SPORT </p> </ol> </td> </tr> </table> </body> </html> <html> <body> <center> <table border="6"> <tr> <th >TITLE</th> <th >CARTOON</th> <th> </th> </tr> <?php while($row= mysql_fetch_array($result)) { echo "<tr>"; echo "<td>".$row['title']."</td>"; echo "<td><img src=\"pics/".$row['location_of_cartoon']."\"></td>" ; ?> <td><a href="addtoshoppingcart.php?cartoon_id=<?php echo $row['cartoon_id']; ?>&title=<?php echo $row['title']; ?>"> [ADD] [/url]</td></tr> <?php } ?> </table> <center>
I would implement a snippet like this, <?php /*************************************************************************** * PHP Paginate Array * ------------------- * begin : Wednesday, Aug 15, 2007 * author : FiRe (www.xeweb.net) * ***************************************************************************/ // Calculate page limits $per_page = 10; $cur_page = (int) $_GET['page']; if ($cur_page == 0) $cur_page = 1; $page_max = $cur_page * $per_page; $page_min = $page_max - $per_page; // Add data to array $arr = array(); $q = mysql_query("SELECT * FROM table"); while ($r = mysql_fetch_array($q)) { $arr[] = '<tr><td>'.$r['name'].'</td><td>'.$r['email'].'</td></tr>'; } // Now output the data from the array for ($i = $page_min; $i < $page_max; $i++) { echo $arr[$i]; } // Finally output the page numbers $total_pages = ceil(count($arr) / $per_page); for ($i = 1; $i <= $total_pages; $i++) { echo '<li><a href="?page='.$i.'">'.$i.'</a></li>' . "\n"; } ?> Code (markup): ·
The solution given by Dr XYZ should work also u need to change htaccess file in order to have a SEO friendly URL . Regards Alex
Well, I've added the code by the Dr XZY and something is working (i don't know what) because infromation from the database has been printed out, but not the way I want it to. but the other problem is its not showing the images from the databse, just he name of the images. I've added the image tag and its still not working. kmap(alex) what do you mean by I have to change the ataccess file in order to have a SEO friendly URL. Could you please explain it more. (i don;t know what where im doing wrong!) please help! This how i've changed it: <?php // Calculate page limits $per_page = 10; $cur_page = (int) $_GET['page']; if ($cur_page == 0) $cur_page = 1; $page_max = $cur_page * $per_page; $page_min = $page_max - $per_page; // Add data to array $arr = array(); $q = mysql_query("SELECT * FROM general_cartoon"); while ($r = mysql_fetch_array($q)) { $arr[] = '<tr><td>'.$r ['title'].'</td><td><img src=\"pics/"'.$r['location_of_cartoon'].'"\"></td></tr>'; } for ($i = $page_min; $i < $page_max; $i++) { echo $arr[$i]; } // Finally output the page numbers $total_pages = ceil(count($arr) / $per_page); for ($i = 1; $i <= $total_pages; $i++) { echo '<li><a href="?page='.$i.'">'.$i.'</a></li>' . "\n"; } ?>