SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: A little help
-
Jun 30, 2004, 14:08 #1
- Join Date
- Jun 2004
- Location
- WV,SC
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
A little help
Ive been trying to get this code to work and ive looked at other post and tutorials with no luck. Can someone tell me if this code is right. or what im doing wrong.. WHen i view it it just repeats the color echo and freezes the window.
Thanks
PHP Code:<table width="300" height="400">
<?
// Connect to MySQL
mysql_connect ('localhost', 'blank', 'blank') ;
mysql_select_db ('mysite');
$query = "SELECT title, news, author, date FROM news ORDER BY id DESC LIMIT 3";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)) {
//run the for loop
for ($i = 0; i < count($row); $i++) {
// Set Table Row Color
if ($i % 2) {
echo "<tr bgcolor=B0C4DE>";
} else {
echo "<tr bgcolor=FOF8FF>";
}
// Now display our table cell info
}
?>
<td><? echo $row["<TR>
<TD><b>Posted on $date</b></TD>
</TR>
<TR>
<TD><b>Title:</b>$title</TD>
</TR>
<TR>
<TD><b>News:</b>$news</TD>
</TR> "];
?></td>
</table>
<? }
?>
-
Jun 30, 2004, 14:19 #2
- Join Date
- Jun 2004
- Location
- in front of a computer
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You're missing a $ right before the
PHP Code:i < count($row)
-
Jun 30, 2004, 15:07 #3
- Join Date
- Jun 2004
- Location
- Wales, UK
- Posts
- 788
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Basically its:
PHP Code:$i < count($row)
Also, why have you got 3 sets of php? I mean why is there 3 blocked of code enclosed in <?php and ?>. Im not saying its wrong, ive just never come across it before?
-
Jun 30, 2004, 15:50 #4
- Join Date
- Jun 2004
- Location
- WV,SC
- Posts
- 4
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thanks for the replies.
i redid some of it. but now its only showing 1 post when my limit is set to 2. any ideas?
PHP Code:<table width="200" height="100">
<?
// Connect to MySQL
mysql_connect ('localhost', 'spl', '') ;
mysql_select_db ('mysite');
$query = "SELECT `title`,`news`,`date` FROM `news` ORDER BY `ID` DESC LIMIT 2";
$result = mysql_query($query);
if ($row = mysql_fetch_array($result)) {
//run the for loop
for ($i = 0; $i < count($row); $i++) {
// Set Table Row Color
if ($i % 2) {
echo "<tr bgcolor=FOF8FF>";
} else {
echo "<tr bgcolor=B0c4de>";
}
// Now display our table cell info
}
?>
<td><?
echo "<p><tt>Posted On :";
echo $row["date"];
echo "</tt></p>";
echo "<p><tt>Title:";
echo $row["title"];
echo "</tt></p>";
echo "<p><tt>News:";
echo $row["news"];
echo "</tt></p>";
?></td>
</table>
<? }
?>
-
Jun 30, 2004, 15:57 #5
- Join Date
- Jun 2004
- Location
- in front of a computer
- Posts
- 94
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by spl
Bookmarks