Jump to content

[SOLVED] Listing the 'categories'


tomhoad

Recommended Posts

<?php
//display the competitions
$query = "SELECT comp_name FROM comps";
$result = mysql_query($query) or die('Error : ' . mysql_error());
while ($row     = mysql_fetch_array($result, MYSQL_ASSOC)) { 

$comp_name   = $row['comp_name'];

?>


<p><?php echo $comp_name;?> - 
<a href="comp_view.php?comp_name=<?php echo(urlencode($comp_name))?>">View Entrants</a></p>


<?php
}

?>

 

This code works fine, it displays the comp_name. However, it does it for every record, e.g. if there were three records:

 

Great Competition - View Entrants

Great Competition - View Entrants

Great Competition - View Entrants

 

What I'd like to do is just list the different comp_names, e.g.

 

Great Competition - View Entrants

Brilliant Competition - View Entrants

 

Regardless of how many people have entered - that's on the next page (comp_view.php, which works fine).

 

Sorry if this isn't clear, I'm struggling to put into words what I want!

 

Thanks  ;D

Link to comment
https://forums.phpfreaks.com/topic/158988-solved-listing-the-categories/
Share on other sites

<?php
//display the competitions
$query = "SELECT comp_name FROM comps";
$result = mysql_query($query) or die('Error : ' . mysql_error());
$comp_names = array();

while ($row     = mysql_fetch_array($result, MYSQL_ASSOC)) { 
     $comp_names[]   = $row['comp_name'];
}

$comp_names = array_unique($comp_names);

foreach($comp_names as $comp_name){
?>


<p><?php echo $comp_name;?> - 
<a href="comp_view.php?comp_name=<?php echo(urlencode($comp_name))?>">View Entrants</a></p>


<?php
}

?>

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.