PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
jwalsh
Forum Contributor
Posts: 202 Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH
Post
by jwalsh » Wed Sep 14, 2005 9:37 am
Hi,
I'm working on parsing some mysql rows into a multidimensional array, but I'm having a bit of confusion... I think I am close though.
Code: Select all
$a = 0;
$result = DB_query("SELECT * FROM inquiry_data WHERE parent=0 ORDER BY title");
while ($row = DB_fetchArray($result)) {
$InquiryData[$a]['id'] = $row['id'];
$InquiryData[$a]['business'] = $row['business'];
$InquiryData[$a]['uid'] = $row['uid'];
$InquiryData[$a]['rand_id'] = $row['rand_id'];
$InquiryData[$a]['title'] = $row['title'];
$InquiryData[$a]['content'] = $row['content'];
$InquiryData[$a]['status'] = $row['status'];
$a++;
}
Now, I would think i could access the elements using foreach, like this...
Code: Select all
foreach ($InquiryData as $CurrentInquiry) {
echo $CurrentInquiry['title'];
}
What am I overlooking? Thanks.
shiznatix
DevNet Master
Posts: 2745 Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:
Post
by shiznatix » Wed Sep 14, 2005 9:54 am
what happens when you echo that out?
jwalsh
Forum Contributor
Posts: 202 Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH
Post
by jwalsh » Wed Sep 14, 2005 9:57 am
Sorry, should have specified... It just returns nothing. Although, I know the $row['title'] is populated, I have already tested that.
raghavan20
DevNet Resident
Posts: 1451 Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:
Post
by raghavan20 » Wed Sep 14, 2005 10:05 am
try this first
Code: Select all
echo "<pre>";
print_r($inquiryData);
echo "</pre>";
foreach ($InquiryData as $CurrentInquiry) {
if (is_array($currentInquiry)){
echo "<pre>";
print_r($currentInquiry);
echo "</pre>";
}else{
echo "currentInquiry is not an array<br />";
}
}
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Wed Sep 14, 2005 10:05 am
do a print_r on each array and see if they are populated as you expect them to be
also, when you do the foreach, you're trying to use it like its still an associative array, which it is not, it will be a numerically indexed array.
so
Code: Select all
foreach($blah AS $blah2)
{
echo $blah2['title'];
}
// IS WRONG!
// do this
foreach($blah AS $blah2)
{
echo $blah2;
}
Last edited by
s.dot on Wed Sep 14, 2005 10:07 am, edited 1 time in total.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
jwalsh
Forum Contributor
Posts: 202 Joined: Sat Jan 03, 2004 4:55 pm
Location: Cleveland, OH
Post
by jwalsh » Wed Sep 14, 2005 10:07 am
Thanks guys, I got it working
.