Forum Moderators: coopster
while ($qry = mysql_fetch_array($p_edu)) {
print "
<tr>
<td>$qry[cYear]</td>
<td>$qry[Education]</td>
<td>$qry[School]</td>
<td>$qry[Program]</td>
<td>
<form name='form1' method='post' action=$PHP_SELF>
<input name='delid' type='hidden' value=$qry[id]>
<input type='submit' name='delete' value=Delete>
</form>
</td>
</tr>\n";
}
[edited by: ergophobe at 6:03 pm (utc) on Feb. 26, 2005]
[edit reason] made code readable - linebreaks [/edit]
while ($qry = mysql_fetch_array($p_edu)) {
if ($condition == true)
{
$first = '<th>';
$second = '</th>';
} else {
$first = '<td>';
$second = '</td>';
}
echo '<tr>';
echo $first . $qry['row'] . $second;
echo '</tr>';
Where $condition is whatever you want to determine whether the cells being output should be a 'th' and 'td'.
Shouldn't there be a counter which adds to a veriable and it makes it th when the number is even and td when the number is odd or something like that.
I am thinking like
while ($qry = mysql_fetch_array($p_edu)) {
if ($a == even_number) //There must be away to check that?
{
$b = 'th>'
} else {
$b = 'td>'
}
echo '<tr>';
echo '<'$b . $qry['row'] . </'$b;
echo '</tr>';
$a++
};
Using the code you pasted above:
while ($qry = mysql_fetch_array($p_edu))
{
$tx = ($tx == 'td')? ('th') : ('td');
print "
<tr>
<$tx>$qry[cYear]</$tx>
<$tx>$qry[Education]</$tx>
<$tx>$qry[School]</$tx>
<$tx>$qry[Program]</$tx>
<$tx>
<form name='form1' method='post' action=$PHP_SELF>
<input name='delid' type='hidden' value=$qry[id]>
<input type='submit' name='delete' value=Delete>
</form>
</$tx>
</tr>\n
";
}
I just read another thread about code optimisation and couldn't resist the urge to do away with all those "if" statements!
If the condition is true, then the left hand side statement will be assigned to the value, if the condition is false, the right hand side statement will be assigned to the value.
It's like a shorthand if, then, else statement.
In this case it checks that the value equals 'td', if it does, then it changes it to 'th'.
[edited by: ironik at 4:42 am (utc) on Mar. 1, 2005]
Here is my output - the delete button is the only thing I see and that works.
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<form name='form1' method='post' action=/usr/autobiography.php>
<input name='delid' type='hidden' value=3>
<input type='submit' name='delete' value=Delete>
</form>
</td>
</tr>
<tr>
<th></th>
<th></th>
<th></th>
<th></th>
<th>
<form name='form1' method='post' action=/usr/autobiography.php>
<input name='delid' type='hidden' value=4>
<input type='submit' name='delete' value=Delete>
</form>
</th>
</tr>
</table>
This is great. Still don't understand
Now I get that it is supposed to do
when $tx do ('th') OR ('td')
How does it know to alternate and which ons turn it is?
I guess thats done here
($tx == 'td')?
but I don't get the logic