How To Create Link with ID Connection from MySQL Database?

Discussion in 'PHP' started by PHPDummy, Jun 12, 2007.

  1. #1
    Hello Folks,

    i am in some mess as it seems,

    i have created a PHP Site with that i write different informations in different cells of that mysql table. the writing into the table works fine and without any problem...

    the table looks like this :

    ID1 Value1 Value2
    ID2 Value3 Value4

    now when doing a result approach on that table i want to have a page generated with the view like this :


    Value1(shown as hyperlink) Value2(Simple Text)
    Value3(shown as hyperlink) Value4(Simple Text)
    ....


    i mainly got probs with generating the part where the Value1 information (is shown as hyperlink) where i connect the id with the Value1 cell and giving that out as hyperlink.

    the script that i am using to show the result yet is this one :


    <?php

    include ('dbconnect.php');

    $sel = "SELECT * FROM table ORDER by Value1";
    $result = mysql_query($sel);

    while($row = mysql_fetch_object($result)) {

    $site = "";
    if(trim($row->link) != ""){

    $site = "<a href='".$row->link."'>WebSite</a>";
    }

    echo "<table border=0 style='width: 450px'>
    <tr>
    <td style='width: 150px'>$row->Value1 </td>
    <td style='width: 150px'>$row->Value2 </td>
    <td style='width: 120px'>$row->Value3 </td>
    <td style='width: 120px'>$webseite </td>
    </tr>
    </table>
    <br>";
    }


    to put it in my own words... i wish to see as result a table where the information from the Value1-Row is shown as hyperlink and when clicked you can go to a "detailpage" where you can get additional informations about that entry, but the tricky in my view is that the information in that row actually is only a text.

    i hope i could explain my problem well and i would appreciate it a lot if someone here could give me an advice or a hint on how to create that script part.


    many thanks in advance,

    your PHPDummy
     
    PHPDummy, Jun 12, 2007 IP
  2. *louie*

    *louie* Peon

    Messages:
    48
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    this line is wrong
    
    <td style='width: 120px'>$webseite </td> 
    
    Code (markup):
    cause you set the $site variable but looking for $webseite afterwards so it should be like this:
    
    <td style='width: 120px'>$site </td> 
    
    PHP:
     
    *louie*, Jun 12, 2007 IP
  3. dvd871

    dvd871 Guest

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Try something more like this:
    <?php
    
    include ('dbconnect.php');
    
    $sel = "SELECT * FROM table ORDER by Value1";
    $result = mysql_query($sel);
    
    echo "<table border='0' style='width: 450px'>
    while($row = mysql_fetch_object($result)) {
    	if(trim($row->link) != ""){
    		echo"<tr><td style='width: 150px'><a href='$row->link'>$row->Value1</a></td></tr>";
    		echo"<tr><td style='width: 150px'><a href='$row->link'>$row->Value2</a></td></tr>";
    		echo"<tr><td style='width: 120px'><a href='$row->link'>$row->Value3</a></td></tr>";
    		echo"<tr><td style='width: 120px'><a href='$row->link'>$row->website</a></td></tr>";
    	}
    	echo"</table><br>";
    }
    ?>
    Code (markup):
     
    dvd871, Jun 12, 2007 IP
  4. ansi

    ansi Well-Known Member

    Messages:
    1,483
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    100
    #4
    ansi, Jun 12, 2007 IP
  5. PHPDummy

    PHPDummy Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    for your replies and for the offered details to solve my problems, i really appreciate your help folks!

    im optimistic that im able to finish this with your offered help :)


    kind regards

    PHPDummy
     
    PHPDummy, Jun 12, 2007 IP