joining two sections of php code in a loop
Posted: Sun Nov 08, 2009 10:55 pm
all the code below is in a php include file:
this first bit of code extracts images from a folder in the specified directory (filesInDir) and displays via the $t variable - the code by itself works good. I'll be replacing the hard coded directory with a variable extracting the address from the mysql table.
this second piece of code extracts the text information from the same table - again on its own it works just as I wish.
now the issue I have is to place the image code within the looping text extraction code so that the image code also loops and displays the images associated with the text - the images I want to display where the echo $t; is in the loop.
I'm having real difficulty in placing it in the loop as I can't work out where exactly or if in need extra brackets etc.
any ideas?
this first bit of code extracts images from a folder in the specified directory (filesInDir) and displays via the $t variable - the code by itself works good. I'll be replacing the hard coded directory with a variable extracting the address from the mysql table.
Code: Select all
filesInDir('reports/2009/yip/tinythumbs');
function filesInDir($tdir)
{
$dirs = scandir($tdir);
foreach($dirs as $file)
{
if (($file == '.')||($file == '..'))
{
}
elseif (is_dir($tdir.'/'.$file))
{
filesInDir($tdir.'/'.$file);
}
else
{
$t="<img src=".'http://www.globalaviationresource.com/'.$tdir.'/'.$file." />";
echo $t;
}
}
}
Code: Select all
mysql_connect("localhost", "[i]userid[/i]", "[i]password[/i]") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query = "SELECT * FROM main ORDER BY id DESC";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
echo "<div class=frontpagepost>";
echo "<div class=date>";
echo "<span class=month>";
echo $row['main_month'];
echo "</span>";
echo "<span class=day>";
echo $row['main_day'];
echo "</span>";
echo "<span class=year>";
echo $row['main_year'];
echo "</span>";
echo "</div>";
echo "<span class=title>";
echo "<a href=".$row['main_url'].">".$row['main_title']."</a>";
echo "</span>";
echo "<span class=paul>";
echo $t;
echo "</span>";
echo "<p>";
echo $row['main_preamble'];
echo "</p>";
echo "</div>";
}
I'm having real difficulty in placing it in the loop as I can't work out where exactly or if in need extra brackets etc.
any ideas?