I am trying to loop through an array, but keep getting the following error:
Notice: Undefined index: topic in threads.php on line 49
I am trying to put my result set in an array and then I want to loop through the array later in the code, showing only values from one particular column of the array. Below is my code:
<?php
$host = "";
$uname="root";
$pass="";
$database="discuss";
$tablename="threads";
$connection = mysql_connect($host, $uname, $pass);
$result =mysql_select_db("discuss");
$query ="SELECT topic, thread_num, sub_num, new_thread, date_time, name from threads order by thread_num desc, sub_num asc";
$result = mysql_query($query);
$t_array[] = mysql_fetch_assoc($result);
?>
<input type="hidden" name="thread_num" value="
<?php $max_thread = array_slice ($t_array,2,1);
foreach ($max_thread as $th)
{
echo $th+1;
}
?>
">
<input type="hidden" name="sub_thread" value="0">
to start a new topic.
<?php
for ($i = 0; $i < mysql_num_rows($result); $i++) {
print "<th>".$t_array["topic"][$i]."</th>\n";
}
?>