SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL query problem

    Hey guys and gals,

    I have a database that has a table called content. I would like to pull the data from a column called nav and have it show up in a php file. Here is the code I have right now. Please tell me what I'm doing wrong:

    PHP Code:
    if (! @mysql_select_db("$database") ) {
     die( 
    '<p>Unable to locate routes database.</p>' );
     }
     
    $result = @mysql_query('SELECT nav FROM content ');
    if (!
    result) {
     die(
    '<p>Error performing query: ' mysql_error() .
     
    '</p>');
     } 
    Any help would be great! Thanks!
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,338
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    well, i can comment only on the mysql part of your question --> SELECT nav FROM content

    looks okay to me

    what exactly was the SQL problem with it?

    as for the php part of your question, perhaps you could ask that in the php forum
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sputza
    if (!result) {
    Looks like you forgot the $ sign.

  4. #4
    SitePoint Member
    Join Date
    Jul 2004
    Location
    Budapest
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    syntay

    Quote Originally Posted by sputza
    PHP Code:
    if (! @mysql_select_db("$database") ) {
     die( 
    '<p>Unable to locate routes database.</p>' );
     } 
    the syntax is:

    PHP Code:
    $stuff mysql_something
       
    or die("Error: " mysql_error()); 
    you forgot the "or", and
    PHP Code:
    if (!result) { 
    should be
    PHP Code:
    if (!$result) { 

  5. #5
    SitePoint Evangelist sputza's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    528
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for all your help. It turned out to be a one of those late night mistakes... like forgetting to put this bit of code in:


    PHP Code:
    while ( $row mysql_fetch_array($result) ) {
     echo(
    '<p>' $row['nav'] . '</p>');
     } 
    Thanks anyways guys. If anyone else had a similar late night mistake here was the final working code:

    PHP Code:
    // connect to database
    $dbcnx = @mysql_connect("$host""$user""$pass");
    if (!
    $dbcnx) {
     echo( 
    '<p>Unable to connect to the ' 
       
    'database server at this time.</p>' );
      exit();
     }
     
    //select database
     
    if (! @mysql_select_db("$database") ) {
     die( 
    '<p>Unable to locate database.</p>' );
     }
     
    //Get nav from the database and show result
    $result = @mysql_query('SELECT nav FROM content ');
    if (!
    result) {
     die(
    '<p>Error performing query: ' mysql_error() .
     
    '</p>');
     }
     
    while ( 
    $row mysql_fetch_array($result) ) {
     echo(
    '<p>' $row['nav'] . '</p>');
     } 
    Time for some coffee to keep me going. Thanks again guys! Have a good night.

    [Offtopic] Has anyone tried any caffeine products from ThinkGeek.com? [/Offtopic]
    Steven Watkins
    Chief Web Ninja
    Code Monkey Interactive
    lowgravity.ca

  6. #6
    SitePoint Evangelist goughb's Avatar
    Join Date
    Sep 2000
    Location
    Chicago
    Posts
    526
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sputza: Happy to hear it all worked out for you, I was feeling the burn last night also with a late project. Keep kickin! Sorry, haven't tried any of Think Geek's products. Happy Hacking!


Bookmarks

Posting Permissions

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