473,466 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Empty results with fetch_array, though DB cell is NOT empty

77 New Member
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.

Expand|Select|Wrap|Line Numbers
  1. $chapterdetails = mysql_query("SELECT * FROM Chapters WHERE id='".$getID."'");
  2.  
  3. while($row = mysql_fetch_array($chapterdetails))
  4.               {
  5.         $id = $row['id'];
  6.         $article_name = $row['article_name'];
  7.         $article_cont = $row['article_content'];
  8.         $article_type = $row['article_type'];
  9.             }
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.
Sep 6 '10 #1
13 1601
Dormilich
8,658 Recognized Expert Moderator Expert
firstly check what $row contains (var_dump()).
Sep 6 '10 #2
PHPstarter
77 New Member
Well var_dump($row) only gives me bool(false),

what do I make out of that?
Sep 7 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
where does it give you false (that’s important)?
Sep 7 '10 #4
PHPstarter
77 New Member
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
Sep 7 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
first you would have to make sure, the article_name value is present.
Sep 7 '10 #6
PHPstarter
77 New Member
It's very much there

Expand|Select|Wrap|Line Numbers
  1. ["article_name"]=>  string(26) "The Hierarchy"
So I can't understand why my $test wont show anything..
Sep 7 '10 #7
Dormilich
8,658 Recognized Expert Moderator Expert
then I’d like to have a look at the code myself …
Sep 7 '10 #8
PHPstarter
77 New Member
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).

Expand|Select|Wrap|Line Numbers
  1. $chapter=$_GET['chapter'];
  2.  
  3. $getID=$chapter;
  4.  
  5. $chapterdetails = mysql_query("SELECT * FROM Chapters WHERE chapterID='".$getID."'");
  6. while($row = mysql_fetch_array($chapterdetails))
  7.           {
  8.         $row['id'];
  9.         $row['article_name'];
  10.         $test=$row['article_name'];
  11.         var_dump($row);
  12.         }
  13.  
  14. echo "
  15. <center>    
  16.     <table width='650' border='0' cellspacing='0' cellpadding='0'>
  17.         <tr>
  18.            <td height='60' class='boe_headline'>
  19.                 Book of Enlightenment, Chapter $getID: <br />
  20.                 $test
  21.            </td>
  22.         </tr>
  23.     </table>
  24. </center>
  25. ";
  26.  
  27.  
Sep 7 '10 #9
Dormilich
8,658 Recognized Expert Moderator Expert
what is var_dump($test);?
Sep 7 '10 #10
PHPstarter
77 New Member
It is...:

string(26) "The Hierarchy" string(0) "" string(0) ""
Sep 7 '10 #11
Dormilich
8,658 Recognized Expert Moderator Expert
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 "".
Sep 7 '10 #12
PHPstarter
77 New Member
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.
Sep 7 '10 #13
PHPstarter
77 New Member
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 :)
Sep 7 '10 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jeff North | last post by:
I'm trying to print a tables' cell/row but when a cell/row is split across 2 pages the cell bottom/top border doesn't print on either page. Like this: +--------+-----------------------------+ | ...
31
by: Arthur Shapiro | last post by:
I'm the webmaster for a recreational organization. As part of one page of the site, I have an HTML "Calendar at a Glance" of the organization's events for the month. It's a simple table of a...
0
by: peterlan | last post by:
Hey everyone, I've built a webservice that's a wrapper for NFop. It takes in an FO formatted xml (in a string), and returns a pdf in a byte. Works fine on my local system (xp pro). When I moved...
2
by: Bob Stearns | last post by:
I thought that the given expression was always TRUE if "not_there" wasn't among the keys (or subscripts if you will) of $_SESSION. Below find a dump of $_SESSION, a small snippet of code and the...
6
by: Charlie | last post by:
Hi: Is there any difference between string.Empty and String.Empty? And what is the benefit of using it over "". Thanks, Charlie
1
by: Jon S via DotNetMonster.com | last post by:
HI all, I'm returning a dataset to a gridview control. When the gridview asp.net control is populated from the returning dataset some of the cells remain empty. This is expected as some data...
1
by: tbakas2 | last post by:
Thank you in advance for the help. I'm using Microsoft XP, I'm in the VBA editor in Excel. I'm trying to write code that will assign a positive or negative value based upon what the adjacent cell...
3
code green
by: code green | last post by:
strlen reports a length of 6 even though it is empty. Also if(empty) reports true. What is happening echo '<br>'.$this->message; trim($this->message); echo '<br>'.$this->message;...
1
by: James Roy | last post by:
Hi all, I have a datagrid and one specific column is editable. I want while i am typing in one of the cells of this column when i press a Function key (Example F7) to get what i have write. Till now...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.