Help - Search - Member List - Calendar
Full Version: This is freaking me out
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!

Tony
[Email Removed] wrote:
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 didn't examine it too closely, but I happened to notice this:


QUOTE
FILLTHEREST;
}

$cell_num == "3";

}

That's a test condition, so $cell_num isn't being set to 3. Delete one of
the equal signs "$cell_num = 3" and I'll bet it will work.

You also may want to consider simplifying the code. Just set a counter that
increments and test it for being a multiple of 3.

Something like

$cell_num = 1;

print "<table>n";
while (looping) // start loop - obviously psuedocode

if ( ($cell_num/3) == ceil($cell_num/3) ) { print "<tr>n"; }
print "<td>CELL CONTENTS</td>n";
if ( ($cell_num/3) == floor($cell_num/3) { print "</tr>n"; }
$cell_num++;
}
print "</table>n";

--
Tony Garcia
Web Right! Development


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.