I'm making the shift from asp to php and having trouble with one particular problem:
I want to query the dbase, then take the result set and put it into an array so that I can immediately close the connection to the dbase, thus saving on resources.
Lastly, I want to loop through the array viewing only data from a particular column of the array.
My question: The code below works fine, but I thought that mysql_fetch_assoc required an open connection to the dbase- can someone verify for me that I have effectively closed the connection to my dbase?
<?php
$host = "";
$uname="root";
$pass="";
$database="discuss";
$tablename="threads";
$connection = mysql_connect($host, $uname, $pass);
$result =mysql_select_db("discuss");
$query ="SeLECT * from threads where thread_num = $thread";
$result = mysql_query($query);
mysql_close($connection);
?>
blah blah code code
<?php
//here comes my loop
mysql_data_seek($result,0);
while ($row = mysql_fetch_assoc($result))
{
echo "<tr><td>";
{
if ($row["new_thread"] == "yes")
echo "<br> ";
}
echo "<img src=\"graphic".$row["sub_num"].".bmp\">";
echo "<a href=\"read_thread-" .$row["thread_num"]. "-" .$row["sub_num"]. ".html\">";
echo $row["topic"];
echo "</a> ";
echo "<font size=\"-1\">$row[name] $row[date_time]</font>";
echo "</td></tr>";
}
?>