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 4 of 4
  1. #1
    Banned
    Join Date
    Oct 2007
    Posts
    52
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Doesn't Work - Why?

    Why doesn't the contents of the "title" field get displayed on the screen?

    Code:
    <?php
    $con = mysql_connect("localhost","ODBC","");
    if (!$con)
    {
      die(mysql_error());
    }
    
    mysql_select_db("MP3", $con);
    
    $result = mysql_query("SELECT * FROM books");
    
    
    
      echo $result['title'];
    
    
    
    mysql_close($con);
    ?>

  • #2
    New Coder
    Join Date
    Aug 2007
    Posts
    53
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Try using this to connect via odbc:
    PHP Code:
    $conn=odbc_connect('northwind','','');
    $sql="SELECT * FROM customers"
    $rs=odbc_exec($conn,$sql); 

  • #3
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    mysql_query() returns a resource id, not the recordset. Once you have that resource id you need to use it to fetch the recordset before you can display it.

    For example:
    PHP Code:
    $row mysql_fetch_assoc($result);

    echo 
    $row['title']; 
    John

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Try this
    PHP Code:
    <?php
    $con 
    mysql_connect("localhost","ODBC","");
    if (!
    $con)
    {
      die(
    mysql_error());
    }

    mysql_select_db("MP3"$con);

    $result mysql_query("SELECT * FROM books") or die(mysql_error());
    if(
    mysql_num_rows($result) > 0)
    {
    $row mysql_fetch_assoc($result);
    echo 
    $row['title'];
    }

    mysql_close($con);
    ?>
    Edit: Beaten to it. Either way you should also check to see if mysql_num_rows is greater than 0 or you will nave nothing to echo.
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

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