Jump to content

[SOLVED] row display question


zhangy

Recommended Posts

<?php
$sql = "SELECT * FROM $table ORDER BY id DESC LIMIT 25";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) >= 1)
{ 
echo '<div id="front_page_post_container">';
while($row = mysql_fetch_array($result))
{
	echo '<div id="hover_div">';
	echo '<div id="title_container">';
	echo '<h2>';
	echo '<a href="post.php?id='.$row['id'].'">'.stripslashes($row['title']).'</a>';
	echo '</h2>';
	echo '</div>';
	echo '<div id="post_container">';
	echo stripslashes(nl2br(substr($row['post'],0,450)));
	echo ' <a href="post.php?id='.$row['id'].'">Read on...</a>';
	echo '</div>';

have a counter variable initiated before your while loop and set it to zero.

inside the loop check this variable. if it is zero, highlight the current item however you want, then increment the counter.  then as it goes through the loop no other entry will be highlighted

Not sure how to right that. Can you point me in the right direction?

 

 

<?php
$sql = "SELECT * FROM $table ORDER BY id DESC LIMIT 25";
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql);
if(mysql_num_rows($result) >= 1)
{ 

$count = mysql_num_rows($result);
   
if  {
   $class = '0';
   }else{
   $class = '';
   }

    
echo '<div id="front_page_post_container">';
while($row = mysql_fetch_array($result))
{
	echo '<div id="hover_div" class="{$class}">';
	echo '<div id="title_container">';
	echo '<h2>';
	echo '<a href="post.php?id='.$row['id'].'">'.stripslashes($row['title']).'</a>';
	echo '</h2>';
	echo '</div>';
	echo '<div id="post_container">';
	echo stripslashes(nl2br(substr($row['post'],0,450)));
	echo ' <a href="post.php?id='.$row['id'].'">Read on...</a>';
	echo '</div>';

 

 

 

Ok i see what you mean, but I tried the following and it has no effect.

 

<?php
$sql = "SELECT * FROM $table ORDER BY id DESC LIMIT 25"; 
$result = mysql_query($sql) or die("Error ". mysql_error(). " with query ". $sql); 
if(mysql_num_rows($result) >= 1) 
{  
    echo '<div id="front_page_post_container">'; 
    $RsCounter = 0;
    while($row = mysql_fetch_array($result)) 
    { 
        $RsCounter++;
        if($RsCounter == 0){
             echo '<div id="hover_div" style="font-size: 15px; font-weight: bold;">'; 
        } else {
             echo '<div id="hover_div">'; 
        }
        echo '<div id="title_container">'; 
	echo '<h2>';
	echo '<a href="post.php?id='.$row['id'].'">'.stripslashes($row['title']).'</a>';
	echo '</h2>';
	echo '</div>';
	echo '<div id="post_container">';
	echo stripslashes(nl2br(substr($row['post'],0,450)));
	echo ' <a href="post.php?id='.$row['id'].'">Read on...</a>';
	echo '</div>';
	echo '</div>';
}
echo '</div>';
}
else
{
echo "That record does not exist!";
}
?>

 

 

<?php
    $RsCounter = 0;
    while($row = mysql_fetch_array($result)) 
    { 
        $RsCounter++;
        if($RsCounter == 0){
             echo '<div id="hover_div" style="font-size: 15px; font-weight: bold;">'; 
        } else {
             echo '<div id="hover_div">'; 
        }

 

you are incrementing the counter before you ever check it.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.