
July 3rd, 2009, 03:16 PM
|
 |
Epically Godly figure
|
|
Join Date: May 2008
Location: Windows :p
Posts: 237
Time spent in forums: 2 Days 10 h 11 m 51 sec
Reputation Power: 0
|
|
|
Strange array error
Why am I getting this error, when:
Code:
$arrayname[] = "value"; //This is Valid
Code:
Parse error: syntax error, unexpected ']', expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Quote\mysqlconnect.php on line 24
Code:
<?php
echo '<table border="1" cellpadding="0" cellspacing="0">';
$array = getarray("localhost", "root", "h4x0rD", "gonads", "employees");
$rownumber = 0;
$colcount = 0;
$tmpcount = 0;
$lastone = -1;
$colarray = array();
foreach ($array as $row)
{
foreach ($row as $column)
{
while ($tmpcount < strlen($column))
{
if ($column[$tmpcount] == ';')
` {
$column = substr($column, $lastone + 1, $tmpcount - 1);
$colcount++;
$colarray[] = $column;
}
$tmpcount++;
}
}
}
//----------------------
$FilterColumn = "name";
$FilterTerm = "Tar";
$Include = 0;
//----------------------
foreach ($array as $row)
{
//loop trough filters => if $array[0][$i] != "$FilterColumn" and subfind($FilterTerm)
$tempcolumn = namefind($array[0], $FilterColumn);
$tempif = subfind($row[$tempcolumn], $FilterTerm);
//if ($tempif == $Include)
//{
$i = 0;
echo '<tr>';
foreach ($row as $column)
{
if (colcount == 0)
{
if ($array[0][$i] != 'ID')
{
echo '<td>';
echo $column;
echo '</td>';
}
$i++;
}
else
{
foreach ($colarray as $colitem)
{
if ($array[0][$i] != 'ID')
{
echo '<td>';
echo $column;
echo '</td>';
}
$i++;
}
}
}
echo '</tr>';
$rownumber++;
//}
}
echo '</table>';
function getarray($host, $user, $pass, $db, $table)
{
$con = mysql_connect("$host","$user","$pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db", $con);
$values = mysql_query("SELECT * FROM $table");
$names = field_names($host, $user, $pass, $db, $table);
$array = array();
$temparray = array();
foreach ($names as $column)
{
$temparray[] = $column;
}
$array[] = $temparray;
while ($row = mysql_fetch_array($values))
{
$colarray = array();
foreach ($names as $column)
{
$temp = $row[$column];
//If $db has a table named $column, get value 2 from row 'ID' $row[$column] and substitute here
if (table_exists("localhost", "root", "h4x0rD", "gonads", $column))
{
$results = mysql_query("SELECT * FROM $column WHERE ID=$row[$column]");
$replacer = mysql_fetch_array($results);
$temp = $replacer[1];
}
$colarray[] = $temp;
}
$array[] = $colarray;
}
mysql_close($con);
return $array;
}
function field_names($host, $user, $pass, $db, $table)
{
$con = mysql_connect("$host","$user","$pass");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$db", $con);
$result = mysql_query("SELECT * FROM $table");
$i = 0;
$names = array();
while ($i < mysql_num_fields($result)){
$fieldname = mysql_field_name($result, $i);
$names[$i] = $fieldname;
$i++;
}
return $names;
}
function subfind($haystack,$needle)
{
$pos = strpos($haystack,$needle);
if($pos === false)
{
return 0;
}
else
{
return 1;
}
}
function namefind($columnarray, $name)
{
$temp = 0;
foreach ($columnarray as $columns)
{
if ($name == $columns)
{
return $temp;
}
$temp++;
}
//none found
return -1;
}
function table_exists($host, $user, $pass, $db, $table)
{
mysql_connect($host, $user, $pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
if (mysql_query("SELECT 1 FROM `".$table."` LIMIT 0"))
{
return true;
}
else
{
return false;
}
}
?>
__________________
This is my sig.
|