Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Help on Automatic Creation of Dynamic Pages

    First post here, just want to say what an excellent site this is!

    Firstly, check out this site for a basic comprehension of what I'm doing: http://www.seainthecity.net/hard_corals.htm

    Ok, here's what I'm trying to do. On that page, you'll see a 3x5 (columns x rows) array of various Hard Corals. Everything on that page is hard coded in HTML. I'm in the process of recreating it with PHP and SQL.

    Everything's gone well, but I've run into a hypothetical problem. My friend who runs seainthecity.net would like it to become a very big site. In otherwords, we're worried about expansion problems. At the moment, it automatically grabs whatever's in the hard coral SQL table and displays it all on one page. It's limited to 3 columns, but unlimited rows. Somehow, we'd like it to dynamically create more pages automatically as the table gets bigger. ATM we're looking at a 3x5 array per page. As items are sold, items will be marked SOLD, then eventually removed from the table.

    This dynamic creation of new pages, as well as automatic links between pages, has obviously been done before, as seen on almost every bulletin board, including this one, when a thread goes over a certain number of posts per page, or a forum goes over a certain number of threads. Does anyone out there know how to do this?

    W H E W! Thanks in advance for the help!

    [EDIT: ARGH! In the edit screen, Dynamic is spelled right, but in the main threads, it's still wrong. :dead: typos :dead:]
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  2.  

  3. #2
    Junior Member Cinders117's Avatar
    Join Date
    Mar 2003
    Location
    Kent, OH
    Posts
    19
    Member #
    833
    first post also
    Pretty new to PHP and MySQL but this should work, although maybe not in the best possible way.

    page: hardcoral.php?id=1

    $id = $_GET[id];
    $result = mysql_query("SELECT * FROM coral LIMIT $id, 15");

    Says start at the $id and go through 15 results
    then at the bottom make links like this:
    echo '<a href="news.php?id=';
    echo $id + 15;
    echo '">Next</a>';

    so that will 'reload' the page with the id as 16 and layout another 15 and have a link at the bottom to start with id 30 and continue.

    It doesn't really have a stop place...maybe have an
    if(!$result) {
    echo 'there are no more results, please return home';
    } or something.
    Hope that helps.

  4. #3
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    Thanks a lot! I posted this question over at http://www.webmaster-forums.net, and got a link to this: http://www.devshed.com/Server_Side/PHP/Paginating/. I haven't completely checked out the code yet and absorbed it, but I believe it'll stop by itself and have links to the next and previous pages. I'm going to work with both, see which one works best for me.

    Here's the code they laid out:

    <?
    // Set Script Variables
    $DB_Host="localhost";
    $DB_Name="MyDataBase";
    $DB_User="MyUserName";
    $DB_Pass="MyPassword";
    $Per_Page=10;
    // Open MySQL Connection
    $Connection=mysql_connect($DB_Host, $DB_User, $DB_Pass);
    // Run The Query Without a Limit to get Total result
    $SQL="SELECT COUNT(*) AS Total FROM Products WHERE Description LIKE '%".$_REQUEST['Keyword']."%'";
    $SQL_Result=mysql_db_query($DB_Name, $SQL);
    $SQL_Result_Array=mysql_fetch_array($SQL_Result);
    $Total=$SQL_Result_Array['Total'];
    // Create a new SELECT Query with the ORDER BY clause and without the COUNT(*)
    $SQL="SELECT * FROM Products WHERE Description LIKE '%".$_REQUEST['Keyword']."%' ORDER BY ProductID";
    // Append a LIMIT clause to the SQL statement
    if (empty($_GET['Result_Set']))
    {
    $Result_Set=0;
    $SQL.=" LIMIT $Result_Set, $Per_Page";
    }else
    {
    $Result_Set=$_GET['Result_Set'];
    $SQL.=" LIMIT $Result_Set, $Per_Page";
    }
    // Run The Query With a Limit to get result
    $SQL_Result=mysql_db_query($DB_Name, $SQL);
    $SQL_Rows=mysql_num_rows($SQL_Result);
    // Display Results using a for loop
    for ($a=0; $a < $SQL_Rows; $a++)
    {
    $SQL_Array=mysql_fetch_array($SQL_Result);
    $Product=$SQL_Array['Name'];
    $Description=$SQL_Array['Description'];
    echo "$Product - $Description<BR><BR>";
    }
    // Create Next / Prev Links and $Result_Set Value
    if ($Total>0)
    {
    if ($Result_Set<$Total && $Result_Set>0)
    {
    $Res1=$Result_Set-$Per_Page;
    echo "<A HREF=\"test.php?Result_Set=$Res1&Keyword=".$_REQUE ST['Keyword']."\"><;<; Previous Page</A> ";
    }
    // Calculate and Display Page # Links
    $Pages=$Total / $Per_Page;
    if ($Pages>1)
    {
    for ($b=0,$c=1; $b < $Pages; $b++,$c++)
    {
    $Res1=$Per_Page * $b;
    echo "<A HREF=\"test.php?Result_Set=$Res1&Keyword=".$_REQUE ST['Keyword']."\">$c</A> \n";
    }
    }
    if ($Result_Set>=0 && $Result_Set<$Total)
    {
    $Res1=$Result_Set+$Per_Page;
    if ($Res1<$Total)
    {
    echo " <A HREF=\"test.php?Result_Set=$Res1&Keyword=".$_REQUE ST['Keyword']."\">Next Page >></A>";
    }
    }
    }
    // Close Database Connection
    mysql_close($Connection);
    ?>
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com

  5. #4
    WDF Staff Wired's Avatar
    Join Date
    Apr 2003
    Posts
    7,657
    Member #
    1234
    Liked
    138 times
    http://www.tweaky.org/SITC/test-3.php is the culmination of the code above. Seems to work fine.
    The Rules
    Was another WDF member's post helpful? Click the like button below the post.

    Admin at houseofhelp.com


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 08:40 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com