Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Blank Page

  1. #1
    New Coder
    Join Date
    Jan 2010
    Posts
    45
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Post Blank Page

    Thought I would make a simple site map by getting info from sql table. Seemed to work but the link keeps directing people to the same page. The name of the link changes so don't know whats going on!!

    Here's the code:

    <?php

    //set variables to connect
    $host='localhost';
    $user='user';
    $pass='password';
    $db='database';


    //connect to mysql
    mysql_connect($host,$user,$pass);

    @mysql_select_db($db) or die( "Unable to select database");

    $query="SELECT * FROM site_map";

    $result=mysql_query($query);

    if (!$result){

    die("Query error! text $query<br> error is".mysql_error());


    }


    $num=mysql_num_rows($result);

    mysql_close();



    $i=0;
    while($i<$num){

    $name=mysql_result($result,$i,"name");
    $link=mysql_result($result,$i,"link");


    echo "<a href='$link'>$name</a> \t";

    $i++;

    }





    ?>

    I have a feeling I'm doing something wrong with this:
    echo "<a href='$link'>$name</a> \t";

    am I using quotes correctly?

    Thanks.

  • #2
    New Coder
    Join Date
    Jun 2010
    Location
    The Netherlands
    Posts
    52
    Thanks
    0
    Thanked 6 Times in 6 Posts
    Put your code between [ PHP] [ /PHP] tags, please.

    PHP Code:
    <?php

    //set variables to connect
    $host='localhost';
    $user='user';
    $pass='password';
    $db='database';


    //connect to mysql
    mysql_connect($host,$user,$pass);

    @
    mysql_select_db($db) or die( "Unable to select database");

    $query="SELECT * FROM site_map";

    $result=mysql_query($query);

    if (!
    $result){

    die(
    "Query error! text $query<br> error is".mysql_error());


    }


    $num=mysql_num_rows($result);

    mysql_close();



    $i=0;
    while(
    $i<$num){

    $name=mysql_result($result,$i,"name");
    $link=mysql_result($result,$i,"link");


    echo 
    "<a href='$link'>$name</a> \t";

    $i++;

    }





    ?>
    Have you tried putting your variables outside of quotes?
    echo "<a href='".$link."'>".$name."</a> \t";

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Enable your error reporting. Chances are, it will complain about your mysql_result.
    Move your mysql_close to the end.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •