I'm using a small upload/download utility to allow the guys from my car club to use for image hosting on my website - it's all contained in one page, using switch/case depending on the variable passed through the URL. Since I'm already hosting a lot of images, I wanted a way to allow multiple pages so people wouldn't have to scroll forever. So, I added a DB and did a batch script to add all the necessary info the table in the database (ID, imagepath, filename). However, I can't get the variables extracted from the result array to format properly in my printed result set. In fact, nothing shows up at all. The pagination works fine, I just can't get any results displayed properly.
You can test out what I'm referring to here:
http://images.darwenstheory.net/upload.php
And, here's the code for the download case in the switch/case routine:
echo "
<table width=\"600\" border=\"1\" cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#0066FF\" style=\"border-collapse: collapse;\">
<tr>
<td colspan=\"3\" bgcolor=\"white\"><div align=\"center\" style=\"font-family: Verdana; font-size: 16px; font-weight: bold;\">Click
to Download</div></td>
</tr>";
$dbh=mysql_connect ('localhost', 'darwenst_kinsban', 'pass') or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ('darwenst_uploads', $dbh);
$Per_Page="50";
$SQL="SELECT COUNT(ID) AS Total FROM images";
$SQL_Result=mysql_query($SQL,$dbh);
$SQL_Result_Array=mysql_fetch_array($SQL_Result);
$Total=$SQL_Result_Array['Total'];
$SQL="SELECT ID FROM images ORDER BY ID DESC";
if (empty($_GET['Result_Set']))
{
$Result_Set=0;
$SQL.=" LIMIT $Result_Set, $Per_Page";
}
else
{
$Result_Set=$_GET['Result_Set'];
$SQL.=" LIMIT $Result_Set, $Per_Page";
}
$SQL_Result=mysql_db_query('darwenst_uploads', $SQL);
$SQL_Rows=mysql_num_rows($SQL_Result) or die(mysql_errno() . mysql_error());
echo $Total;
for ($a=0; $a < $SQL_Rows; $a++)
{
$SQL_Array=mysql_fetch_array ($SQL_Result);
$image_id=$SQL_Array['ID'];
$imagepath=$SQL_Array['image_path'];
$filenombre=$SQL_Array['filename'];
$finalimage=$imagepath.$filenombre;
echo "
<tr>
<td width=25 bgcolor=\"white\" style=\"font-family: Verdana; font-size:11px; font-weight: bold;\">".$image_id."</td>
<td width=\"475\" bgcolor=\"white\"><a href=".finalimage.">".$filenombre."</a></td>
<td width=\"100\" bgcolor=\"white\"><a href=".$finalimage."><img src=".$finalimage." width=\"100\" border=\"0\"></a></td>
</tr>";
}
echo "
<tr>
<td colspan=\"3\" bgcolor=\"white\"><div align=\"center\">";
if ($Total > 0)
{
if ($Result_Set < $Total && $Result_Set > 0)
{
$Res1=$Result_Set-$Per_Page;
echo "<a href=\"upload.php?action=download&Result_Set=$Res1\"><< Previous Page </a> ";
}
$Pages=$Total / $Per_Page;
if ($Pages > 1)
{
for ($b=0, $c=1; $b < $Pages; $b++, $c++)
{
$Res1 = $Per_Page * $b;
echo "<a href=\"upload.php?action=download&Result_Set=$Res1\">$c</a> \n";
}
}
if ($Result_Set >= 0 && $Result_Set<$Total)
{
$Res1=$Result_Set + $Per_Page;
if ($Res1<$Total)
{
echo "<a href=\"upload.php?action=download&Result_Set=$Res1\"> Next Page >></a>";
}
}
}
echo"
</div></td>
</tr>
</table>";
Any insight you guys could offer would be great, because I am STUMPED! 😕