I\\'m very new to PHP, so I hope you can help me out.

I have a database with 3 field: id, name, www.

I want a code that will yank out the www address when i call an id number. For example, I want
http://domain.com/index.php?id=1
to send me to www address at the first row.

Does anyone know where i can get this code? Thanks.

    if this db is mysql, you could write code like this:

    <?php
    mysql_connect($hostname, $user, $password) or die("Could not connect");

    mysql_select_db($db_name) or die("Could not select db $db_name");

    //$id is the id from the url
    //i.e. http://domain.com/index.php?id=1
    //id would be 1
    $sql = "SELECT www from the_table where id=$id LIMIT 1";

    $result = mysql_query($sql);
    $row = mysql_fetch_array($result);

    header("Location: $row['www']");
    exit();
    ?>

    You need to put this script at the very top of the page and make sure that nothing gets outputed to the browser before the header() function is called, including spaces.

    BT

      I tried the code you gave me, but I get this message:

      Parse error: parse error, expecting T_STRING' orT_VARIABLE' or `T_NUM_STRING'

        on which line? my code is based on the following assumptions:

        1. you have a page where there are links that contain something similar to:
          <a href="http://domain.com/index.php?id=1">go here</a>

        2. when the user clicks this link, it will be taken to your 'index.php' page where the code i wrote is located. after getting the id from the url, it should automatically redirect to the website contained in the db.

        I can probably help you further but I would need to see all your code to determine what exactly you're trying to accomplish and by what method.

        BT

          The error is coming from
          header("Location: $row['www']");

            This should work

            .....
            $result = mysql_query($sql);
            $row = mysql_fetch_array($result);

            // add this line
            $url=$row['www'];

            header("Location: $url");

              This is what I am using so far:

              <?
              $hostname="localhost";
              $user="username";
              $password="password";
              $usertable="links";
              $dbname="database";

              mysql_connect($hostname, $user, $password) or die("Could not connect");
              mysql_select_db($dbname) or die("Could not select db $dbname");

              $sql = "SELECT www from the_table where id=$id LIMIT 1";
              $result = mysql_query($sql);
              $row = mysql_fetch_array($result);

              $url=$row['www'];

              header("Location: $url");
              exit();
              ?>

              I get this message:
              Warning: Supplied argument is not a valid MySQL result resource in /basedirectory/test.php on line 13

              Warning: Cannot add header information - headers already sent by (output started at /basedirectory/test.php:13) in /basedirectory/test.php on line 17

              I'm very new at PHP, but I was studying the code and have a few questions. When searching, it only searches the database. What if I want it to search a particular table. As you can see, I added a variable $usertable to the code.

              Also, does using header("Location: $url"); simply redirects to the www address? I want to come out like what phpbuilder.com has.

              At last, what exactly do you call this process? Dynamic links?

                There are a error in your MySql query

                You wrote:
                $sql = "SELECT www from the_table where id=$id LIMIT 1";

                "the_table" is not correct table. (must be, in your case "links" or $usertable)

                Correct is... (full code)

                <?
                $hostname="localhost";
                $user="username";
                $password="password";
                $usertable="links";
                $dbname="database";

                mysql_connect($hostname, $user, $password) or die("Could not connect");
                mysql_select_db($dbname) or die("Could not select db $dbname");

                $sql = "SELECT www from $usertable where id='$id' ";
                $result = mysql_query($sql);
                $row = mysql_fetch_array($result);

                $url=$row['www'];

                header("Location: $url");
                exit();
                ?>

                I test this script at home and work fine.

                  The code works perfectly now, but the problem is that it simply redirects to the www address.

                  For example, this is my table.
                  1 Benny Agbayani http://domain.com/ba.htm

                  The code picks up id 1 and sends me to http://domain.com/ba.htm with THAT address on my URL Address bar.

                  Is there a way to hide the orignal path and have http://domain.com/index.php?id=1 show on my URL Address bar?

                  Sorry if i'm taking a lot of your time with stupid questions. Thanks a lot for your help though. =)

                  Jason

                    I try allot to do this but with no results. I only get a page but without a pictures with this code
                    <?
                    $fcontents = join ('', file ($page));
                    echo $fcontents ;
                    ?>

                    where $page="http://www.php.net"

                    NOTE: THIS IS NOT CORRECT TO OWNER OF A PAGE!

                      What happens if I replace the Header() with

                      include("$url");
                      exit;

                      Somehow it works for me, but is there anything you see wrong using it?

                        HUH..

                        include(\"$url\");
                        exit;

                        Work on OS other than WINDOWS. On my W2k OS this don\'t work! Also work if \"URL fopen wrappers\" is enabled in PHP.INI

                          Write a Reply...