php echo statement problem trying to create dynamic link

Discussion in 'PHP' started by saturn100, Nov 8, 2012.

  1. #1
    Hi
    I have a simple pho echo statement designed to get data from a db
    Thats fine but am trying to create a dynamic link within it using data from the db
    I think I know the code for it but am having issues where to put it

    here is the code as it stands

    <?php
    // Make a MySQL Connection
    mysql_connect("xxxx", "xxxx", "xxx") or die(mysql_error());
    mysql_select_db("xxx) or die(mysql_error());
    
    // Get all the data from the "example" table
    $result = mysql_query("SELECT * FROM blog_posts ORDER BY id DESC LIMIT 0, 5 ") 
    or die(mysql_error());  
    
    echo "<table border='1' width='350px' cellspacing='5' style='color:#fff;'>";
    echo "<tr> <th>&nbsp;</th> <th>&nbsp;</th> </tr>";
    // keeps getting the next row until there are no more to get
    while($row = mysql_fetch_array( $result )) {
    	// Print out the contents of each row into a table
    	echo "<tr><td colspan='2'><b>"; 
    	echo $row['title'];
    	echo "</b></td></tr><tr><td>"; 
    	echo $row['summary'];
    	echo "</td></tr>"; 
    } 
    
    echo "</table>";
    
    ?>
    PHP:
    This line
     echo $row['title']; 
    PHP:
    I wasnt to turn into a dynamic link basically to read
    <a href="www.mysite/blog/$id/$title">$row['title']</a>

    I have tried various things but nothing is working
    any ideas
     
    Last edited: Nov 8, 2012
    saturn100, Nov 8, 2012 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    why is it that people don't read properly?

    check php.net. mysql functions are discouraged and it is suggested to use mysqli or PDO functions instead

    If you would read php.net you would also see your problem

    change this lne
    
    while($row = mysql_fetch_array( $result )) {
    
    PHP:
    to this
    
    while($row = mysql_fetch_assoc( $result )) {
    
    PHP:
     
    stephan2307, Nov 8, 2012 IP