Jump to content

[SOLVED] stop repeating selection


zhangy

Recommended Posts

Hi! I have a small problem. On my blog i have a list of categories from recent posts. However some of these categories are used multiple times and so repeat in the list. I was wondering, is there a way to make it so that if once a specific category is output on the list it wont be able to do so again thereby avoiding repeats?

thanks!

 

<?php

require_once('load_data.php');

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$result = mysql_query("SELECT * FROM $table ORDER BY submission_id DESC LIMIT 10")or die(mysql_error());

while($row = mysql_fetch_array($result))
{

echo '<li><a href="author.php?id='.$row['col_2'].'" class="job_link" title="recent posts by '.$row['col_2'].'">'.$row['col_2'].'</a></li>';

}
?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/165878-solved-stop-repeating-selection/
Share on other sites

<?php

require_once('load_data.php');

if (!mysql_connect($db_host, $db_user, $db_pwd))
    die("Can't connect to database");

if (!mysql_select_db($database))
    die("Can't select database");

$result = mysql_query("SELECT * FROM $table ORDER BY submission_id DESC LIMIT 10")or die(mysql_error());
$Check = "";
while($row = mysql_fetch_array($result))
{
        if(!in_array($row['col_2'], $Check)) {
             $Check[] = $row['col_2'];
     echo '<li><a href="author.php?id='.$row['col_2'].'" class="job_link" title="recent posts by '.$row['col_2'].'">'.$row['col_2'].'</a></li>';
}
}
?>

 

 

Honestly, I don't even know if this will work, basically the idea is to populate a small array.  If the value is already in the array, don't display it, if it isn't display the row and insert the value into the array.

 

 

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.