Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8225167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:19:28+00:00 2026-06-07T15:19:28+00:00

I have a website under construction, using PHP MYSQL, which contains a news page

  • 0

I have a website under construction, using PHP MYSQL, which contains a news page with three columns.

  • col1(middle column) displays the news title and news text.

  • col2(left column) displays the titles of 10 most recent news entries.

  • col3(right column) – is an archives column that displays the month and year.

Like I said above, the Recent News column (col2) displays the titles of the 10 most recent news entries. When I click on a particular title, then col1 displays the main content corresponding to that title. What I want to do is to highlight the active title in col2. Is there a way to do this using css & PHP?

The db queries are as below:

mysql_select_db($database_admin_conn, $admin_conn);
$query_getArchives = "SELECT DISTINCT DATE_FORMAT (news.updated, '%M %Y') AS archive, DATE_FORMAT (news.updated, '%Y-%m') AS link FROM news ORDER BY news.updated DESC";
$getArchives = mysql_query($query_getArchives, $admin_conn) or die(mysql_error());
$row_getArchives = mysql_fetch_assoc($getArchives);
$totalRows_getArchives = mysql_num_rows($getArchives);

mysql_select_db($database_admin_conn, $admin_conn);
$query_getRecent = "SELECT news.news_id, news.title FROM news ORDER BY news.updated DESC LIMIT 10";
$getRecent = mysql_query($query_getRecent, $admin_conn) or die(mysql_error());
$row_getRecent = mysql_fetch_assoc($getRecent);
$totalRows_getRecent = mysql_num_rows($getRecent);


$var1_getDisplay2 = "-1";
if (isset($_GET['archive'])) {
  $var1_getDisplay2 = $_GET['archive'];

$query_getDisplay = sprintf("SELECT news.news_id, news.title, news.news_entry, DATE_FORMAT (news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE DATE_FORMAT(news.updated, '%%Y-%%m') = %s ORDER BY news.updated DESC", GetSQLValueString($var1_getDisplay2, "text"));

} elseif (isset($_GET['news_id'])) {
  $var2_getDisplay3 = $_GET['news_id'];

$query_getDisplay = sprintf("SELECT news.news_id, news.title, news.news_entry, DATE_FORMAT(news.updated, '%%M %%e, %%Y') AS formatted FROM news WHERE news.news_id=%s ", GetSQLValueString($var2_getDisplay3, "int"));

} else {
mysql_select_db($database_admin_conn, $admin_conn);
$query_getDisplay = "SELECT news.news_id, news.title, news.news_entry, DATE_FORMAT (news.updated, '%M %e, %Y') AS formatted FROM news ORDER BY news.updated DESC LIMIT 3";
}
$getDisplay = mysql_query($query_getDisplay, $admin_conn) or die(mysql_error());

And here is the relevant extract of the html/css for news page:

<div class="col1">
<div class="news">

<?php  while($newsItem = mysql_fetch_array($getDisplay))
{ ?>
<?php $arrayNews[$getDisplay['news_id']] = $newsItem; ?>

<?php foreach($arrayNews AS $newsItem)
{  ?>   

<h1> <?php echo $newsItem['title'] ; ?> <h3><?php echo $newsItem['formatted'];?></h3></h1>

<?php $query_getPhotoDetails = "SELECT *
FROM photos INNER JOIN news2photo USING (photo_id)
WHERE news2photo.news_id = '" . $newsItem['news_id'] . "' LIMIT 3
";
$getPhotoDetails = mysql_query($query_getPhotoDetails, $admin_conn) or die(mysql_error());

while($photo = mysql_fetch_array($getPhotoDetails))
{ ?>
<div class="imagefield">
<p>&nbsp</p>
<p> <img src="../images/<?php echo $photo['filename']; ?>" width="200" />
</p>
</div> 
<?php }
?>
<?php $newsItem['news_entry'] = preg_replace("/((http)+(s)?:\/\/[^<>\s]+)/i", "<a href=\"\\0\" target=\"_blank\">\\0</a>", $newsItem['news_entry'] ); ?>
<div class="newsitem">
<p>&nbsp</p>
<p> <?php echo nl2br($newsItem['news_entry']);
?>  
</p>
</div>
<?php } ?>
<?php } ?>

</div><!--end news-->         
</div>

<div class="col2">
<h3>Recent News</h3>
<ul> 
  <?php do { 
 ?> <li class="seperator"><a href="news.php?news_id=<?php echo $row_getRecent['news_id'];
     ?>"><?php echo $row_getRecent['title']; ?></a></li> 
    <?php } while ($row_getRecent = mysql_fetch_assoc($getRecent)); ?>

</ul>



</div>
<div class="col3"><h3>News Archives</h3>
<ul>
  <?php do { ?>
    <li class="seperator"><a href="news.php?archive=<?php echo $row_getArchives['link']; ?>"><?php echo $row_getArchives['archive']; ?></a></li>
    <?php } while ($row_getArchives = mysql_fetch_assoc($getArchives)); ?>
</ul>

</div>

Things work fine, but I need help with highlighting the current list item in the ‘Recent News’ (col2) column.
I did search quite a bit, but almost all of solutions are wordpess specific.
Thanks in advance 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T15:19:31+00:00Added an answer on June 7, 2026 at 3:19 pm

    I’m not quite sure what you want highlighted how.

    What I think you’re trying to do is add some effect to the <li>s in the col2 div when a user is over that space?

    You can easily achive this by putting something like this between your <head></head> tags:

    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript">
      $(document).onLoad(function(){
        $('.col2 li').hover(function() { this.toggleClass('hovered'); });
      });
    </script>
    <style type="text/css">
      .hovered { background-color: black; color: white; }
    </style>
    

    What this does is toggle a CSS class on or off on your <li> tags under col2 after your page has loaded.

    EDIT: To mark the currently selected news item in the col2 div, make a class for it in the header and apply it based on the submitted news_id:

    <head>
      <style type="text/css">
        .currentItem { background-color: darkorange; }
      </style>
    </head>
    ...
    <h3>Recent News</h3>
    <ul>
      <?php do { ?>
      <li class="seperator
          <?php echo (isset($_GET['news_id']) && $_GET['news_id'] == $row_getRecent['news_id']
                      ? 'currentItem' : '') ?>">
        <a href="news.php?news_id=<?php echo $row_getRecent['news_id']?>">
          <?php echo $row_getRecent['title'] ?>
        </a>
      </li>
      <?php } while ($row_getRecent = mysql_fetch_assoc($getRecent)); ?>
    </ul>
    

    EDIT2: To mark the currently selected month in col3, you’d have to mark <li>s like this:

    <li class="seperator
               <?php echo (isset($_GET['archive'] && $row_getArchives['link'] == $_GET['archive']
                           ? 'currentItem' : '') ?>">
      <a href="news.php?archive=<?php echo $row_getArchives['link'] ?>">
        <?php echo $row_getArchives['archive']; ?>
      </a>
    </li>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ASP.NET website deployed under IIS uisng virtual directories. I'm using forms
i have website of application which sells applications online.on the home page i want
I have a php/apache website under my userdir, say http://localhost/~johnny5/ I have a /en
I have an ASP.net website running under IIS6. In one .aspx page the user
heys guys, i have a website, which contains lots of db work to display
I have a website written in PHP under source control (SVN). I would like
I was already running a sub-website under following path http://example.com/sub-site/ Now, I have created
I have a gallery of images on my website. Under each one, I'd like
On my website www.staygold-design.com I have a fancybox jquery script on a button under
I have website on the server, which is not precompiled (with source code, so

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.