how to make a link for the info get from database in php

Discussion in 'PHP' started by JoeyWong, Nov 17, 2010.

  1. #1
    Hi all, how can I make a link for the data get from database? Can anyone help me.. thanks~

    <?php 
    $sql = "SELECT * from institution where type='foreign'";
    $result = mysql_query($sql) or die("SQL select statement failed");
    // execute query
    $result=mysql_query($sql);
    while ($row = mysql_fetch_array($result))  {
    $Iname = $row["i_name"];
    $Website = $row["website"];
    $Address = $row["address"];
    echo "<table>";
    echo "<tr><th>Institution Name:</th><td>$Iname</td></tr>";
    echo "<tr><th>Website&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th><td>$Website</td></tr>";
    echo "<tr><th>Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th><td>$Address</td></tr>";
    echo "</table><br>";
    }
    ?>
    PHP:
     
    JoeyWong, Nov 17, 2010 IP
  2. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #2
    
    <?php
    $sql = "SELECT * from institution where type='foreign'";
    $result = mysql_query($sql) or die("SQL select statement failed");
    // execute query
    $result=mysql_query($sql);
    echo "<table>";
    while ($row = mysql_fetch_array($result))  {
    $Iname = $row["i_name"];
    $Website = $row["website"];
    $Address = $row["address"];
    echo "<tr><th>Institution Name:</th><td>$Iname</td></tr>";
    echo "<tr><th>Website&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th><td>$Website</td></tr>";
    echo "<tr><th>Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th><td>$Address</td></tr>";
    echo "<br>";
    }
    echo "</table>";
    ?>
    PHP:
    i guess this is what u needed right?
     
    arpit13, Nov 17, 2010 IP
  3. JoeyWong

    JoeyWong Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you have do any changes??
     
    JoeyWong, Nov 17, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Is this a file on its own and you want to send a query to it ?
     
    MyVodaFone, Nov 17, 2010 IP
  5. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #5
    yes i put <table> code out of the loop. very small but effective change.
    this will put everything in one table.i actually read title of a different post and saw a different post.
    i didn't read wat u wanted sry for that.i hope that u made sure that mysal database is connected.
     
    arpit13, Nov 17, 2010 IP
  6. JoeyWong

    JoeyWong Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok.. thanks~ i get what u mean..
     
    JoeyWong, Nov 17, 2010 IP
  7. arpit13

    arpit13 Well-Known Member

    Messages:
    294
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    128
    Digital Goods:
    1
    #7
    anyways wat kind of link do u want?
     
    arpit13, Nov 18, 2010 IP
  8. JoeyWong

    JoeyWong Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Nevermind.. I try to do it... If having any problem, i will ask u guys here... thanks~
     
    JoeyWong, Nov 19, 2010 IP
  9. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #9
    ahh I think I know what you want.... a link to a file that will connect to the database ?

    If you already have a db connection file skip this part or ...

    1, Create a file called db.php place the following into it, upload it to your server
    
    <?php
    
    // db options
    
    define('DB_NAME', "myDatabase");
    define('DB_USER', "username");
    define('DB_PASSWORD', "password");
    define('DB_HOST', "localhost");
    
    mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
    mysql_select_db(DB_NAME);
    
    ?>
    
    PHP:
    2, Next add the following to your code above like this:
    
    <?php
    
    include "db.php"; // this is how you connect to the database
    
    $sql = "SELECT * from institution where type='foreign'";
    $result = mysql_query($sql) or die("SQL select statement failed");
    // execute query
    $result=mysql_query($sql);
    echo "<table>";
    while ($row = mysql_fetch_array($result))  {
    $Iname = $row["i_name"];
    $Website = $row["website"];
    $Address = $row["address"];
    echo "<tr><th>Institution Name:</th><td>$Iname</td></tr>";
    echo "<tr><th>Website&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th><td>$Website</td></tr>";
    echo "<tr><th>Address&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;:</th><td>$Address</td></tr>";
    echo "<br>";
    }
    echo "</table>";
    ?>
    
    PHP:
     
    MyVodaFone, Nov 19, 2010 IP
  10. JoeyWong

    JoeyWong Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    What I want is when data retrieved from database then the <a href="" >$data</a> something like this...
     
    JoeyWong, Nov 19, 2010 IP
  11. JoeyWong

    JoeyWong Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    I have another problem... how to do second selection menus change depend on first selection menus.
    Exp: After user select Institute Name then the selection menus of School Name change depend on Institute Name..Using javascript & php..
    thanks~
     
    JoeyWong, Nov 19, 2010 IP
  12. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #12
    Try this:
    
    <a href=\"' . $data . '\">$data</a>
    
    PHP:
     
    MyVodaFone, Nov 19, 2010 IP