Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 9 of 9
  1. #1
    Member
    Join Date
    Jan 2005
    Posts
    53
    Member #
    8598
    Hello,
    I have a db table: page: *page_id, page_name, page_link.
    What I am trying to do is display records from the table showing the page_name and using the information in page_link to create a link.
    Hopefully, this is making some sense.

    This is the code I have:
    PHP Code:
    while ($add_info mysql_fetch_array($get_page_res)) 
        {
            
    $page $add_info[page_id];
            
    $page_name $add_info[page_name];
            
    $page_url $add_info[page_link];
            
    $display_block .= "<li><a href=\"$page_url\">$page_name</a></li>";
        } 
    Everything runs fine but when I click on the link it goes to the index.htm of my site not the address from the db.

    So, how do you do this or can it even be done. I figure that if anyone knows how it will be someone on this forum.

  2.  

  3. #2
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    PHP Code:
    echo "<a href=\"$page_url\">link text</a>"
    is what I use and it works fine.

    Tell me, when you hover over the link is the URL http://youraddress.com ?
    If so, then $page_url is set to that.

    Alternatively instead of assigning the value to a variable you could go

    PHP Code:
    echo "<a href=\"$add_info[column]\">link text</a>"

  4. #3
    Junior Member towerboy's Avatar
    Join Date
    Dec 2003
    Location
    Stevens Point, Wisconsin
    Posts
    28
    Member #
    4293
    Try this and see if it works:

    PHP Code:
    $result mysql_query("SELECT * FROM (Table Name) ORDER BY page_id ASC") or die ("Invalid query: SELECT");
    while (
    $data mysql_fetch_array($result))
      {
      
    extract($data);
      
    $n++;
      print 
    "<li><a href=\"$page_url\">$page_name</a></li>";
      } 
    :lick: I reject your reality and substitute my own.

  5. #4
    Member
    Join Date
    Jan 2005
    Posts
    53
    Member #
    8598
    Thank you both but I must admit that I am totally confused.

    bfsog - I tried using your echo... script but kept getting a parse error...no doubt I used it wrong. I admit to not being sure where the echo should have gone.

    PHP Code:
    $page_url = echo "<a href=\"$add_info[column]\">link text</a>"
    To answer your other question. When I look at the view source for the page the html has www.domain.com not the page I am trying for.


    towerboy - I am not sure where I would would put your code. Is it to replace my original $get_page_result or is it to replace the code I originally posted.

    Maybe more explanation is needed for you to help me. This is a page after a login. If the username and password is valid then the user selects a page from a list of pages they are allowed to access. The display_block shows the allowed list of pages. I am still fumbling through the learning process and often miss the obvious. Thank you for the help.

  6. #5
    Senior Member
    Join Date
    May 2003
    Location
    UK
    Posts
    2,354
    Member #
    1326
    Hey there.

    My original code would go after you pull or get the data from the db.. so..
    PHP Code:
    while ($add_info mysql_fetch_array($get_page_res))
        {
            
    $page $add_info[page_id];
            
    $page_name $add_info[page_name];
            
    // $page_url = $add_info[page_link]; commented out as we include directly
            
    echo "<a href=\"$add_info[page_link]\">link text</a>";
        } 
    Just to show heres some code from a file of mine:
    PHP Code:
        $query="SELECT * FROM users where username='$user'";
        
    $result mysql_query($query) or die("Query failed: ".mysql_error());
        
    $numrows mysql_num_rows($result);
        if (
    $numrows == "0") {
            echo 
    "Sorry. We do not have a user with that id number.<br /><br />";}
        
        else {
        while(
    $row mysql_fetch_array($result))
        {
            echo 
    "Url: <a href=\"$row[url]\">Visit website</a>";
            echo 
    "<br /><br />";
    $numrows++;
        }} 
    Hope this helps.. it can be done though so we should soon have you sorted.

  7. #6
    Junior Member towerboy's Avatar
    Join Date
    Dec 2003
    Location
    Stevens Point, Wisconsin
    Posts
    28
    Member #
    4293
    I would say either way (bfsog or mine) should work. Mine would be an alternative way of doing it, but either way would work.
    :lick: I reject your reality and substitute my own.

  8. #7
    Member
    Join Date
    Jan 2005
    Posts
    53
    Member #
    8598
    Sorry to be so slow to catch on. And I really do appreciate the help. I made the changes but the links are still going to index.htm.

    So here is all the code (forgive me for what you are about to see): :nervous:
    PHP Code:
    <?php
    if (($_POST['username'] =="") || ($_POST['password'] ==""))
    {
    header("Location: userlogintest.htm");
    exit;
    }
    $display_block "<p><h2>Please select the page you wish to work on:</h2></p>";
    $conn mysql_connect("localhost""dbname""dbpass") or die(mysql_error());
    mysql_select_db("db",$conn)  or die(mysql_error());

    $sql "select user_id, username, password from user
    where username='
    $_POST[username]' and password='$_POST[password]'";
    $sql_res mysql_query($sql) or die(mysql_error());

    if (
    mysql_num_rows($sql_res) > 0
    {
        
    //if authorized, get the values of f_name l_name
        
    $user_id mysql_result($sql_res0'user_id');
    }
        
    //$display_block .= "<p>Hi there.</p>";
    $get_page "select page_id, page_name, page_link from page";
    $get_page_res mysql_query($get_page) or die(mysql_error());

    $get_page_info "select user_page.user_id, user_page.page_id, page.page_id, 
            page.page_name FROM page, user_page WHERE user_page.user_id = 
    $user_id
            AND page.page_id=user_page.page_id"
    ;
        
    $get_page_res mysql_query($get_page_info)or die(mysql_error());

    if (
    mysql_num_rows($get_page_res) != 0
    {
        
    $display_block .= "<P><strong>page(s):</strong><br>
            <ul>"
    ;

        while (
    $add_info mysql_fetch_array($get_page_res)) 
        { 
            
    $page $add_info[page_id]; 
            
    $page_name $add_info[page_name]; 
            
    // $page_url = $add_info[page_link]; commented out as we include directly 
            
    $display_block .= "<a href=\"$add_info[page_link]\">$page_name</a>"
        } 

        
    $display_block .= "</ul>";
    }
    ?>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>User login</title>
    </head>
    <body>
    <?php echo $display_block?>
    </body>
    </html>

  9. #8
    Member
    Join Date
    Jan 2005
    Posts
    53
    Member #
    8598
    Oops I have found my first two big mistakes. 1. A duplicate $get_page_res and in the second which the code uses forgot to add page.page_link to the query.

  10. #9
    Member
    Join Date
    Jan 2005
    Posts
    53
    Member #
    8598
    Thank you for all the help...it works...it really works. Now, since I have been working at this from the time I got up this morning (6 1/2 hours ago) I will go enjoy some breakfast. I really appreciate the help and patience. Thank you again.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 07:03 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com