Empty results with fetch_array, though DB cell is NOT empty

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PHPstarter
    New Member
    • Jun 2009
    • 77

    #1

    Empty results with fetch_array, though DB cell is NOT empty

    Heya.. Im using this code to fetch several results from my database.

    The database cells does contain info, no weird symbols, regular utf-8 encoding.
    regular mysql_result() works, but I'd like to fetch a larger amount of data at once, and I'm guessing this is a valid method.

    Code:
    $chapterdetails = mysql_query("SELECT * FROM Chapters WHERE id='".$getID."'");
    
    while($row = mysql_fetch_array($chapterdetails))
     		 	{
    		$id = $row['id'];
    		$article_name = $row['article_name'];
    		$article_cont = $row['article_content'];
    		$article_type = $row['article_type'];
    			}
    Any hints regarding what would be wrong?

    The $id variable does print out, some other do too, like article_type, but not article_name.

    The spelling is correct, so I'm TOTALLY lost here.
    I've used this method before and it has always worked.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    firstly check what $row contains (var_dump()).

    Comment

    • PHPstarter
      New Member
      • Jun 2009
      • 77

      #3
      Well var_dump($row) only gives me bool(false),

      what do I make out of that?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        where does it give you false (that’s important)?

        Comment

        • PHPstarter
          New Member
          • Jun 2009
          • 77

          #5
          No wait, only now I put var dump inside of the brackets and it is printing out quite a lot with the values who are existant (some fields are empty by default).

          But I still cant, for example, assign $test = $row['article_name']; and use $test later in my script :S

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            first you would have to make sure, the article_name value is present.

            Comment

            • PHPstarter
              New Member
              • Jun 2009
              • 77

              #7
              It's very much there

              Code:
              ["article_name"]=>  string(26) "The Hierarchy"
              So I can't understand why my $test wont show anything..

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                then I’d like to have a look at the code myself …

                Comment

                • PHPstarter
                  New Member
                  • Jun 2009
                  • 77

                  #9
                  Here's the whole part related to this:
                  (database connection is included earlier, so it's not that)

                  (db row 'id' was changed to 'chapterID' to see if that worked instead, no luck (the real id field is still existant ofc).

                  Code:
                  $chapter=$_GET['chapter'];
                  
                  $getID=$chapter;
                  
                  $chapterdetails = mysql_query("SELECT * FROM Chapters WHERE chapterID='".$getID."'");
                  while($row = mysql_fetch_array($chapterdetails))
                   		 {
                  		$row['id'];
                  		$row['article_name'];
                  		$test=$row['article_name'];
                          var_dump($row);
                  		}
                  
                  echo "
                  <center>	
                  	<table width='650' border='0' cellspacing='0' cellpadding='0'>
                  		<tr>
                  		   <td height='60' class='boe_headline'>
                  				Book of Enlightenment, Chapter $getID: <br />
                  				$test
                  		   </td>
                  		</tr>
                  	</table>
                  </center>
                  ";

                  Comment

                  • Dormilich
                    Recognized Expert Expert
                    • Aug 2008
                    • 8694

                    #10
                    what is var_dump($test) ;?

                    Comment

                    • PHPstarter
                      New Member
                      • Jun 2009
                      • 77

                      #11
                      It is...:

                      string(26) "The Hierarchy" string(0) "" string(0) ""

                      Comment

                      • Dormilich
                        Recognized Expert Expert
                        • Aug 2008
                        • 8694

                        #12
                        that looks like $row['article_name'] is empty in the last cycle (i.e. no value in the db assigned) and since you always overwrite $test, the final value (which is printed) is "".

                        Comment

                        • PHPstarter
                          New Member
                          • Jun 2009
                          • 77

                          #13
                          So what method should I use to retrieve data from multiple rows?
                          The db cell is not empty x)
                          But they all have in common that their 'chapterID' is the same number (1), but I have tried replacing the variable with '1' and no luck... looks like the database.

                          Comment

                          • PHPstarter
                            New Member
                            • Jun 2009
                            • 77

                            #14
                            Ahhh... I think I might have found the reason..

                            There are other inputs with the same chapterID. I didn't know they existed because it shouldn't be possible to create one with the same chapterID, I'll try adjust it and check if that helps

                            (tough the one i want have the lowest real ID assigned by the db itself, so if I try sorting the results as DESC it might work?. trying)

                            Edit: Bullseye!

                            I think we solved this noobish problem :))

                            Thanks a lot for the help.
                            As usual it was my bad, but I wouldnt have spotted it :)

                            Comment

                            Working...