Dynamic URLs using PHP

Discussion in 'PHP' started by themlife, May 2, 2007.

  1. #1
    Hi there. I am trying to figure out how to create a link like:

    site.com/index.php?id=5

    where it will pull the mysql data from id # 5 and populate the page with requested info.

    I thought this was very basic but I have been looking for a tutorial on how to achieve this and I haven't had much luck. Maybe I'm not using the right term. Can someone point me in the right direction with a tutorial or article on how to do this?

    Does this involve a mod_rewrite?

    Thanks for any help!
     
    themlife, May 2, 2007 IP
  2. manilodisan

    manilodisan Peon

    Messages:
    224
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Basic example

    <?php
    
    /**
     * This gathers the data from mysql
     * based on dynamic url's
     */
    
    //connection to db.....
    
    mysql_select_db($db, $link);
    $query = "SELECT * FROM table WHERE ID = ".$_GET['ID'];
    $do_query = mysql_query($query, $link) or die(mysql_error());
    
    	if(mysql_num_rows($do_query)>0)
    	{//if we do have something to display
    
    		do {//loop through records
    			echo '<a href="index.php?id='.$row['ID'].'" title="'.$row['title'].'">'.$row['title'].'</a><br />';
    		} while($row = mysql_fetch_assoc($do_query));
    		
    	}
    	else {
    		
    		echo 'no data to display.';
    		
    	}
    
    ?>
    PHP:
     
    manilodisan, May 2, 2007 IP