www.webdeveloper.com
Results 1 to 4 of 4

Thread: [RESOLVED] Select * works but not individual columns

  1. #1
    Join Date
    Apr 2012
    Posts
    12

    resolved [RESOLVED] Select * works but not individual columns

    Hello,
    could you please help me figure out why selecting all works but not individual columns? When selecting individual columns I get an empty result set.
    Code is below.

    I greatly appreciate the help, i have been looking at this for hours.

    PHP Code:
    function getBookReviews($connection)
    {
            
    //works
            
    $sql="SELECT * FROM theDatabase Where isbn = " $_POST['isbn'];

            
    //returns empty set
        //$sql="SELECT index, parent, user, primary, review, spoilers FROM theDatabase Where isbn = " . $_POST['isbn'];

        
    $result mysql_query($sql$connection);
        
    $reviews = array();
        
        while (
    $row mysql_fetch_array($result))
        {
            
    $review['index'] = $row['index'];
            
    $review['parent'] = $row['parent'];
            
    $review['user'] = $row['user'];
            
    $review['primary'] = $row['primary'];
            
    $review['review'] = $row['review'];
            
    $review['spoilers'] = $row['spoilers'];
        
            
    array_push($reviews,$review);
        }
            
        echo 
    json_encode($reviews);
                
        
    mysql_free_result($result);


  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,611
    Try quoting the column names -- in MySQL typically done with the `back-tick` character -- as some of them may be reserved words.

    PS: You can help the debugging by checking to see if the result of your mysql_query() is false, and if so log or output an error with info from mysql_error().

    PPS: The PHP MySQL extension is now deprecated, and you should really be using either the MySQLi extension or even the PDO extension.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2012
    Posts
    12
    That was it, thank you for the help. index and primary are reserved words.

    I will do as you advise and look into MySQLi. Thank you again

  4. #4
    Join Date
    Sep 2011
    Posts
    60
    when you naming columns try to avoid reserve words like index, primary, user....it will help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles