pinehead18 wrote:btw thats my parse error
Fatal error: Cannot use [] for reading in / on line 46
When adding a value to an array, a blank key just tells php to set the next numerical key - but this:
..has no meaning: no array key has been specified for the comparison.
Also: in your code, the if statement needs to migrate south - inside the foreach loop.
I think it would be useful to split that code up into functions, here's an idea of what I mean:
Code: Select all
function fetchData($name, $con)
{
$sql = "SELECT col1, col2, col3 [..etc] FROM users
WHERE user='$name'";
$result = mysql_query($sql,$con);
return mysql_fetch_array($result) or die(mysql_error());
}
function pruneList($list)
{
foreach($list as $key=>$value)
{
if ($list[$key] == DEFAULT_GIF) // define a config constant?
{
unset($list[$key])
}
}
return $list;
}
function buildList($name, $con)
{
$list = fetchData($name, $con)
return pruneList($list);
}
function buildCell($picname, $name)
{
$td = '<td align=center>';
$td .= '<a href=http://lifeinkc.com/viewimage.php?image=' . $picname . '&name=' . $name . '>';
$td .= '<span style="text-decoration: none">';
$td .= '<img src=http://lifeinkc.com/pics/' . $picname . ' height=80 width=80>';
$td .= '</a>';
$td .= '</span>';
$td .= '</td>';
return $td;
}
function buildCells($list, $name)
{
$cells = '';
foreach($list as $value)
{
$cells .= buildCell($value, $name);
}
return $cells;
}
// in use:
$list = buildList($name, $con);
$cells = buildCells($list, $name);
Untested. Just a quick once over to give you an idea how it might be refactored.