how do I create multiple pages on my website from using a single php script

Discussion in 'PHP' started by callisto11, Feb 2, 2008.

  1. #1
    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. :confused:

    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>
     
    callisto11, Feb 2, 2008 IP
  2. Revolution333

    Revolution333 Peon

    Messages:
    227
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    add my msn which is located in my profile or PM me I could help you. It might cost you tho.
     
    Revolution333, Feb 3, 2008 IP
  3. yovishnurulez

    yovishnurulez Banned

    Messages:
    422
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Same here. I can also help you.
     
    yovishnurulez, Feb 3, 2008 IP
  4. Dr. XYZ

    Dr. XYZ Guest

    Messages:
    226
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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):
    ·​
     
    Dr. XYZ, Feb 3, 2008 IP
  5. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #5
    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
     
    kmap, Feb 3, 2008 IP
  6. callisto11

    callisto11 Peon

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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!):confused:
    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";
    }
    ?>
     
    callisto11, Feb 3, 2008 IP