SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Generating dynamic page + dynamic url?

    Hi, I am creating a small app that allows user to view content entries and nothing more (simple CMS i guess)

    on the homepage i display a shortened version of my content by calling mysql using while loops

    Code:
    $result = @mysql_query($query);
    
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
    	if ($first = TRUE) {
    		echo '<h2>Contents</h2>';
    		$first = FALSE; 
    		}
    	echo "<a href="..."> content name
    --

    Onto my real question. Even though i provided basic infos, but i really need to create specific content pages where user can click the link on the homepage and go into another page that's dynamically generated.

    Which i have no idea how to do (both the URL, and the page.)

    so for the <a href=" part i dont know what to put there.

    Do i need to create a seperate script (another php file), on add some more script on the homepage (index.php) in order to have seperate dynamically generated pages?

    --

    Just like a forum:

    http://www.sitepoint.com/forums/showthread.php?t=456441

    i assume the showthread.php calls everything needed (poster, thread content, replier, replied contents blah blah blah), and ?t=XXXXXXX specifies the thread id.

    I need something just like this >.<

    Thank you for your time.

  2. #2
    SitePoint Addict
    Join Date
    Jul 2007
    Location
    San Jose, California
    Posts
    355
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so the href is going to look
    <a href=./dynamicpage.php?id=<?= $databaseRowKey ?>">BLAH</a>

    Then in dynamicpage.php
    Code PHP:
    <?php
         if(!isset($_GET['id']))
              exit();
         else{
    $id = $_GET['id'];
    $result = @mysql_query("SELECT * FROM DB where PrimaryKey = $id);

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The link on the home page could be like this:

    story.php.?story=123

    Story.php goes and gets story who's id = 123
    PHP Code:
    // do some validation then:
    $id = (int)$_GET['story'];

    "select * from stories where story_id = " $id 
    Does that help?

  4. #4
    SitePoint Enthusiast
    Join Date
    May 2007
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sweet. that makes a lot of sense

    on the other hand i just make a new php file say named dynamicpage.php

    then i put the mysql connection in the beginning right?

    also i could generate the <a href="..."> and the stuff in between say the actual text that displayed for the link <a>....</a>

    right?

    wow there are so many cool things you could accomplish with php


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •