studgate Posted February 4, 2008 Share Posted February 4, 2008 Hi guys, I am trying to solve a little problem. I have built a simple blog with name, content, title, time. i have a list in the bottom of each page and I also have the list in the bottom of the blog page. In the blog page, what I want to do is check the bottom list id and if the blog id is equals to the any of the bottom's id, i want to highlight the one in the list. Thank you in advance! Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 4, 2008 Share Posted February 4, 2008 Your query is not very clear, it would be VERY helpful if you provided the two queries you are currently using to generate those two lists. I would look for a solution to modify the query of the list you want to use the highlighting in to add an additional column to identify if it should be highlighted or not. Quote Link to comment Share on other sites More sharing options...
studgate Posted February 4, 2008 Author Share Posted February 4, 2008 This is the list in the bottom <? // generate and execute query $query = "SELECT id, title, timestamp FROM blog ORDER BY timestamp DESC LIMIT 0, 4"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // if records present if (mysql_num_rows($result) > 0) { // iterate through resultset // print article titles while($row = mysql_fetch_object($result)) { ?> <li><a href="blog.php?id=<? echo $row->id; ?>"><span><? echo $row->slug; ?></span><em><? echo formatDate($row->timestamp); ?></em></a></li> <? } } // if no records present // display message else { ?> <font size="-1">No Blog Entry currently available</font> <? } // close database connection mysql_close($connection); ?> And the blog page entry: <? // generate and execute query $query = "SELECT title, content, contact, timestamp FROM blog WHERE id = '$id'"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); // get resultset as object $row = mysql_fetch_object($result); // print details if ($row) { ?> <h2><? echo $row->title; ?></h2> <p><? echo nl2br($row->content); ?></p> <p><font size="-2">This blog entry was published on <? echo formatDate($row->timestamp); ?>. For more information, please contact <? echo $row->contact; ?></font></p> <? } else { ?> <p> <font size="-1">That blog entry could not be located in our database.</font> <? } ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted February 4, 2008 Share Posted February 4, 2008 Don't use the php short tags they are not supported on all servers. Also the FONT tag has been depricated for many years, use styles. this should do what you are asking for: <?php // generate and execute query $query = "SELECT id, title, timestamp FROM blog ORDER BY timestamp DESC LIMIT 0, 4"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if (mysql_num_rows($result) > 0) { // records present // iterate through resultset // print article titles while($row = mysql_fetch_object($result)) { $span_style = ($row->id==$id) ? ' style="background-color:#FFFF00;"' : ''; echo "<li><a href=\"blog.php?id={$row->id}\">"; echo "<span {$span_style}>{$row->slug}</span><em>".formatDate($row->timestamp)."</em>"; echo "</a></li>"; } } else { // no records present // display message echo "<font size=\"-1\">No Blog Entry currently available</font>"; } // close database connection mysql_close($connection); ?> Quote Link to comment Share on other sites More sharing options...
studgate Posted February 4, 2008 Author Share Posted February 4, 2008 Thank you very much mjdamato, you solve my problem again, thanks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.