Help - Search - Member List - Calendar
Full Version: Please help me with my code
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
I've written the code below to perform the following:

Create a table that has three cells for each row. Each cell has a graphic and a radio button. The first row works fine. It gets to the third cell and starts creating the next row. The second row, however, just keeps creating cell after cell after cell, never getting around to creating the third row.

I have scoured this code for the reason, but I am obviously too close to the problem. Please help!

<?php

// Get the graphics, if any

$queryg = "SELECT * FROM spec_graphics WHERE graph_id >= '2' ORDER BY graph_id";
$resultg = mysql_query($queryg)
or die ("can't execute query. Refresh your browser to try again.");

$graph_num = mysql_num_rows($resultg);

if ($graph_num == "0")
{
// No graphics to display

echo <<<BLIMEY
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td width="99%" height="50" class="back"><b>Delete a Graphic:<br />
At this time you have no uploaded custom graphics to delete</b></td>
</tr>
<tr align="center" valign="middle">
<td class="back"><img src="images/grey-span.gif" width="100%" height="3" /></td>
</tr>
</table>

BLIMEY;

}
else
{

// There is at least one graphic to display

echo <<<THEBEGIN
<form action="del_graph.php" method="post">
<input type="hidden" name="do" value="markit">
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr align="center">
<td height="50" colspan="3" class="back"><b>Delete a Graphic:</td>
</tr>
<tr align="center" valign="top">
<td height="10" colspan="3" class="back"><img src="images/grey-span.gif" width="100%" height="3" /></td>
</tr>

THEBEGIN;

$cell_num = "1";
$row_alter = "yes";

do
{
$rowg = mysql_fetch_array($resultg);
extract($rowg);

if ($row_alter == "yes")
{

if ($cell_num == "1")
{
echo <<<FARLEFTER
<tr align="center" valign="middle">
<td width="33%" class="tdgray"><img src="../special_images/$graph_loc" alt="$graph_id" width="100" /><br>
<input type="radio" name="kill_graph" value="$graph_id" /> Delete $graph_id</td>

FARLEFTER;

if ($graph_num == "1")
{
echo <<<FILLTHEREST
<td width="33%" class="tdgray">&nbsp;</td>
<td width="33%" class="tdgray">&nbsp;</td>
</tr>

FILLTHEREST;
}

$cell_num = "2";

}
elseif ($cell_num == "2")
{
echo <<<MIDDLIN
<td width="33%" class="tdgray"><img src="../special_images/$graph_loc" alt="$graph_id" width="100" /><br>
<input type="radio" name="kill_graph" value="$graph_id" /> Delete $graph_id</td>

MIDDLIN;
if ($graph_num == "1")
{
echo <<<FILLTHEREST
<td width="33%" class="tdgray">&nbsp;</td>
</tr>

FILLTHEREST;
}

$cell_num = "3";

}
else
{
echo <<<FARRIGHTER
<td width="33%" class="tdgray"><img src="../special_images/$graph_loc" alt="$graph_id" width="100" /><br>
<input type="radio" name="kill_graph" value="$graph_id" /> Delete $graph_id</td>
</tr>

FARRIGHTER;
$cell_num = "1";

$row_alter = "no";

}
}
else
{
if ($cell_num == "1")
{
echo <<<FARLEFTER
<tr align="center" valign="middle">
<td width="33%" class="back"><img src="../special_images/$graph_loc" alt="$graph_id" width="100" /><br>
<input type="radio" name="kill_graph" value="$graph_id" /> Delete $graph_id</td>

FARLEFTER;

if ($graph_num == "1")
{
echo <<<FILLTHEREST
<td width="33%" class="back">&nbsp;</td>
<td width="33%" class="back">&nbsp;</td>
</tr>

FILLTHEREST;
}

$cell_num = "2";

}
elseif ($cell_num == "2")
{
echo <<<MIDDLIN
<td width="33%" class="back"><img src="../special_images/$graph_loc" alt="$graph_id" width="100" /><br>
<input type="radio" name="kill_graph" value="$graph_id" /> Delete $graph_id</td>

MIDDLIN;
if ($graph_num == "1")
{
echo <<<FILLTHEREST
<td width="33%" class="back">&nbsp;</td>
</tr>

FILLTHEREST;
}

$cell_num == "3";

}
else
{
echo <<<FARRIGHTER
<td width="33%" class="back"><img src="../special_images/$graph_loc" alt="$graph_id" width="100" /><br>
<input type="radio" name="kill_graph" value="$graph_id" /> Delete $graph_id</td>
</tr>

FARRIGHTER;
$cell_num = "1";

$row_alter = "yes";

}
}

$graph_num--;

} while ($graph_num > "0");

echo <<<FINISHIT
<tr align="center" valign="bottom">
<td height="11" colspan="3" class="back">cell num=$cell_num, row alter=$row_alter, graph num=$graph_num<img src="images/grey-span.gif" width="100%" height="3" /></td>
</tr>
<tr align="center" valign="middle">
<td colspan="3" class="back"><input name="Submit" type="submit" value="Delete the Above Selected Graphic" /></td>
</tr>
<tr align="center" valign="middle">
<td colspan="3" class="back"><img src="images/grey-span.gif" width="100%" height="3" /></td>
</tr>
</table>
</form>

FINISHIT;

}

?>

There is obviously more to the code, but everything else works fine. It's just that darned second row!

Geoff Berrow
I noticed that Message-ID: <pn3xe.3391$[Email Removed]> from
<[Email Removed]> contained the following:

QUOTE
I've written the code below to perform the following:

Create a table that has three cells for each row. Each cell has a graphic and a radio button. The first row works fine. It gets to the third cell and starts creating the next row. The second row, however, just keeps creating cell after cell after cell, never getting around to creating the third row.

I have scoured this code for the reason, but I am obviously too close to the problem. Please help!


I think you need to look carefully at the logic of what you are trying
to do. Obviously this will only work properly if your results are in
multiples of three, otherwise you will have to pad out your results in
some way to accommodate the format.
--
Geoff Berrow 0110001001101100010000000110
001101101011011001000110111101100111001011
100110001101101111001011100111010101101011


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.