PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Little Spy
Forum Commoner
Posts: 31 Joined: Thu Oct 10, 2002 8:18 pm
Contact:
Post
by Little Spy » Wed Nov 06, 2002 7:31 pm
Code: Select all
dbConnect();
$result = mysql_query("SELECT * FROM userinfo");
$content = "<table cellpadding="1" cellspacing="0" border="0" align="center" width="586" class="tbl_border">";
$content = " <tr>";
$content = " <td width="715">";
$content = " <table cellpadding="4" cellspacing="0" border="0" width="645" style="border-collapse: collapse" bordercolor="#111111">";
$content = " <tr>";
$content = " <td class="tbl_caption" colspan="2" height="12" width="661">Find User To";
$content = " Modify > Letter A</td>";
$content = " </tr>";
while ($data = mysql_fetch_assoc($result)) {
$username = $dataї'username'];
$i = 0;
if ($i % 1 == 0) {
$content = " <tr class="tbl_light">";
$content = " <td height="18" align="left" valign="top" width="550">". $username ."</td>";
$content = " <td width="104" height="18" align="left" valign="top">";
$content = " <p align="center">їModify]</td>";
$content = " </tr>";
} if ($i % 2 == 1) {
$content = " <tr class="tbl_dark">";
$content = " <td height="18" align="left" valign="top" width="550">" . $username. "</td>";
$content = " <td width="104" height="18" align="left" valign="top">";
$content = " <p align="center">їModify]</td>";
}
$i++;
}
$content = " </tr>";
$content = " </table>";
$content = " </td>";
$content = " </tr>";
$content = "</table>";
thats my code chunk maybe someone can tell me whats wrong
twigletmac
Her Royal Site Adminness
Posts: 5371 Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK
Post
by twigletmac » Thu Nov 07, 2002 3:03 am
Maybe this will help:
Code: Select all
<?php
dbConnect();
$sql = "SELECT username from userinfo";
@$result = mysql_query($sql) or die(mysql_error());
$content =<<<END
<table cellpadding="1" cellspacing="0" border="0" align="center" width="586" class="tbl_border">
<tr>
<td width="715">
<table cellpadding="4" cellspacing="0" border="0" width="645" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td class="tbl_caption" colspan="2" height="12" width="661">Find User To Modify > Letter A</td>
</tr>
END;
$bgclass = 'light';
while ($data = mysql_fetch_assoc($result)) {
$username = $dataї'username'];
$bgclass = ($bgclass == 'light') ? 'dark' : 'light';
$content .=<<<END
<tr class="tbl_$bgclass">
<td height="18" align="left" valign="top" width="550">$username</td>
<td width="104" height="18" align="left" valign="top"><p align="center">їModify]</td>
</tr>
END;
}
$content .=<<<END
</table>
</td>
</tr>
</table>
END;
?>
The <<<END ... END; syntax is called heredoc and using it means your source code will be formatted with linebreaks and tabs.
Code: Select all
$content =<<<END
This uses the "here document" (or "heredoc") syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator (ie. END;) must appear on a
line with just a semicolon no extra whitespace (which the forum so helpfully adds on)!
END;
It simplifies your HTML a bit and I've also added a new bit for doing the row colours.
Mac