zhangy Posted July 14, 2009 Share Posted July 14, 2009 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 More sharing options...
Asheeown Posted July 14, 2009 Share Posted July 14, 2009 <?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. Link to comment https://forums.phpfreaks.com/topic/165878-solved-stop-repeating-selection/#findComment-874950 Share on other sites More sharing options...
haku Posted July 14, 2009 Share Posted July 14, 2009 "SELECT DISTINCT(column_name) FROM ' . $table . ' ORDER BY submission_id DESC LIMIT 10" Link to comment https://forums.phpfreaks.com/topic/165878-solved-stop-repeating-selection/#findComment-874960 Share on other sites More sharing options...
zhangy Posted July 14, 2009 Author Share Posted July 14, 2009 ah sweet! It worked. Thanks Fearsoldier, thanks haku! Link to comment https://forums.phpfreaks.com/topic/165878-solved-stop-repeating-selection/#findComment-874972 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.