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 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts

    echo single mysql result

    Hi guys.

    One problem to the next.
    I can now read from the session however I can not convert the output from the runid to runname.

    I want the database to store a runid however show the user a name.
    Below is the whole code and then the section which is specific to the problem.

    Jama

    PHP Code:
    <?php
    require("includes/sesh.inc");
    require(
    "includes/header.inc");
    require(
    "includes/db.inc");
    require(
    "includes/menu.inc");

    $currentuser $_SESSION['uid'];


    echo 
    "<h1>Run Selection</h1>";



    if(isset(
    $_GET['add']))
    {
    $i $_POST['rid'];
    $r $_POST['rname'];

    $query"UPDATE userdetails
    SET racetrainingfor = $r
    WHERE userdetails.userid = $currentuser"
    ;
    mysql_query($query);
    echo 
    "<p>Race Selected</p>";
    echo 
    $r;
    $query2 "SELECT runname FROM rundetails WHERE runid=$r";
    echo 
    mysql_query($query2);

    }



    echo 
    "<form action='selectrun.php?add=yes' method='post'>";
    echo 
    "<select name='rname'>";

    $query1 "SELECT * FROM rundetails";
    $result mysql_query($query1);

    while (
    $row mysql_fetch_array($result))
    {
    extract($row);

    echo
    "<option value= '".$runid."'> ".$runname." </option>";

    }
    echo 
    "</select>";
    echo 
    "<input type='submit' value='Select Race'></p>";
    echo 
    "</form>";



    require(
    "includes/footer.inc");
    ?>
    PHP Code:
    $query2 "SELECT runname FROM rundetails WHERE runid=$r";
    echo 
    mysql_query($query2); 

  • #2
    Senior Coder tomws's Avatar
    Join Date
    Nov 2007
    Location
    Arkansas
    Posts
    2,644
    Thanks
    29
    Thanked 330 Times in 326 Posts
    The return value of mysql_query is a mysql resource, not text output. You need to fetch the data from the result in order to display it. This information should be shown on any beginner level tutorial found through a search engine.
    Are you a Help Vampire?

  • #3
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    Yes you don't echo out a query like Tom said. This is one way of doing it.

    PHP Code:
    $query2 mysql_query("SELECT runname FROM rundetails WHERE runid=$r");
    $row mysql_fetch_array($query2);

    echo 
    "".$row['runname'].""
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?

  • #4
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Quote Originally Posted by masterofollies View Post
    PHP Code:
    $query2 mysql_query("SELECT runname FROM rundetails WHERE runid=$r");
    $row mysql_fetch_array($query2);

    echo 
    "".$row['runname'].""
    You could condense that to two lines:

    Code:
    $query2 = mysql_query("SELECT runname FROM rundetails WHERE runid=$r");
    print(mysql_fetch_result($query2));

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    30
    Thanks
    5
    Thanked 0 Times in 0 Posts
    Thanks very much guys.

    Sorry if i did seem obvious, i knew it was wrong but was not sure what to look for on how to output this.

    I'm gradually trying to teach myself php through this project

  • #6
    Senior Coder
    Join Date
    May 2005
    Posts
    2,137
    Thanks
    96
    Thanked 72 Times in 72 Posts
    No prob, we are here to help. It's nearly impossible to learn it all on your own. It's best to ask questions.
    Rowsdower! has accused me of having mental problems, and the administrator allowed it. What a great forum huh?


  •  

    Posting Permissions

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