array causing blank page


#1

Not sure what Im doing wrong here.

BUT this snippet here is causing my page to show up blank white.

//Get all group submisions $sgroups = $db->sql_query("SELECT * FROM group_report ORDER BY greport_id ASC"); //roll the above into an array indexed by greport_id while(list($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date) = sql_fetch_row($sgroups)) { $sgroups_array[$greport_id[] = array($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date); }

if I comment out

$sgroups_array[$greport_id[] = array($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date);

The page will at least load, but with no data as its missing the array.


#2

Why use list() and array()? They both have the same variables in the same order:

[php] //Get all group submisions
$sgroups = $db->sql_query(“SELECT * FROM group_report ORDER BY greport_id ASC”);
//roll the above into an array indexed by greport_id
while(list($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date) = sql_fetch_row($sgroups)) {
$sgroups_array[$greport_id[] = array($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date);
}[/php]

Becomes:

[php] //Get all group submisions
$sgroups = $db->sql_query(“SELECT * FROM group_report ORDER BY greport_id ASC”);

//roll the above into an array indexed by greport_id
while($mygroupreport = sql_fetch_row($sgroups)) {
	$sgroups_array[$greport_id[] = $mygroupreport;
}[/php]

Now the code is a lot more readable, and the problem shows itself (to me, that is): $sgroups_array[$greport_id[] should be $sgroups_array[$greport_id]. I’ll leave it up to you to figure out why ;) It wouldn’t be fun if you didn’t learn anything, now would it?

Also, I don’t think sql_fetch_row() is gonna do the trick for you (unless you’ve defined it yourself).


#3

Thats the error!

$sgroups_array[$greport_id[]

should have been

$sgroups_array[$greport_id][]

to give the full code of
which also explains my use of list() and array()

[code]<?php
if (!eregi(“modules.php”, $_SERVER[‘PHP_SELF’])) {
die (“You can’t access this file directly…”);
}

require_once(“mainfile.php”);
$module_name = basename(dirname(FILE));
$index = 1; //show right blocks

function viewgroupsubmit() {
global $module_name, $db;

//Get all group submisions
$sgroups = $db->sql_query("SELECT * FROM group_report ORDER BY greport_id ASC");
//roll the above into an array indexed by greport_id
while(list($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date) = sql_fetch_row($sgroups)) {
	$sgroups_array[$greport_id][] = array($greport_id, $group_stime, $group_etime, $group_date, $group_loc, $group_mem1, $group_mem2, $group_mem3, $group_mem4, $group_mem5, $group_mem6, $submit_date);
}

include("header.php");
title("Grouping Submissions");	

OpenTable();
$is_empty = 1;

foreach ($sgroups_array as $value) {//cycle through all members
if ($value[0][0] != “”) {
$is_empty = 0;
echo "

Start Time End Time Date Location Sumbit Date
{$value[0][1]} {$value[0][2]} {$value[0][3]} {$value[0][4]} {$value[0][11]}
Member 1 Member 2 Member 3 Member 4 Member 5 Member 6
{$value[0][5]} {$value[0][6]} {$value[0][7]} {$value[0][8]} {$value[0][9]} {$value[0][10]}



";

}
if ($is_empty) {
echo “

There are pending group posts.”;
}
}
CloseTable();

include(“footer.php”);
}

switch($op) {
default:
viewgroupsubmit();
break;
//
// case “post”:
// recruitPost($greport_id));
// break;
}

?>[/code]


#4

Yes, but here’s what you’re doing:

1 sql_fetch_row() returns an array
2 you unravel the array into x number of values with list()
3 then you put these values back into an array with array()
4 then you put your (newly created) array into another array

Steps 2 and 3 pretty much cancel each other out :)