Not exactly sure how to do that, though I do understand what you mean.
Even though the query works, it seems very crude next to the existing code, is there anyway of using what's already there to add what I need?
Here's the full page
<?
require 'config.php';
require_once( 'mod_errorlogs.php' );
require_once( 'mod_owned.php' );
require_once( 'mod_members.php' );
require_once( 'mod_settings.php' );
// function to clean data
if( !function_exists( 'clean' ) ) {
function clean( $data ) {
$data = trim( htmlentities( strip_tags( $data ), ENT_QUOTES ) );
if( get_magic_quotes_gpc() )
$data = stripslashes( $data );
$data = addslashes( $data );
return $data;
}
}
// get listing info and member type
$info = get_listing_info( $listing );
$member_type = ( $info['listingtype'] == 'fanlisting' ) ? 'fans' : 'members';
// explode the fields for sorting and make sure there are no whitespace
$sortarray = explode( ',', $info['sort'] );
foreach( $sortarray as $i => $s ) $sortarray[$i] = trim( $s );
// what sorting fields have been selected already by the visitor?
// obtain from $_GET array
$set = 0;
$selected = array(); // what have we selected?
$sortfield = $sortarray[$set]; // what field are we currently sorting?
while( isset( $sortarray[$set] ) && isset( $_GET[$sortarray[$set]] ) ) {
// while the user has selected a value to sort with
$selected[$sortarray[$set]] = $_GET[$sortarray[$set]];
if( $selected[$sortarray[$set]] == 'all' )
$selected[$sortarray[$set]] = '%';
$set++;
if( isset( $sortarray[$set] ) )
$sortfield = $sortarray[$set];
}
//$set--;
$sorters = get_member_sorter( $listing, $set, $selected );
// are we still going to show the sorting?
if( count( $sortarray ) == $set ) // this is the last?
return;
// create list URL
$list_url = $info['listpage'];
$connector = '?';
if( substr_count( $list_url, '?' ) > 0 )
if( $info['dropdown'] == 1 )
$connector = '&';
else
$connector = '&';
// get anything that's already in $selected and put it in the URL
$in_url = array();
foreach( $selected as $field => $value ) {
$field = clean( $field );
$value = clean( $value );
if( in_array( $field, $in_url ) )
continue;
$list_url .= "$connector$field=$value";
if( $info['dropdown'] == 1 )
$connector = '&';
else
$connector = '&';
$in_url[] = $field;
}
// if owner selected the dropdown method
if( $info['dropdown'] == 1 ) {
?>
<script type="text/javascript">
<!--
function change( form ) {
var dropDown = form.elements[0];
var myIndex = dropDown.selectedIndex;
if( dropDown.options[myIndex].value != "0" ) {
window.open( "<?php echo $list_url . $connector . $sortfield ?>=" +
dropDown.options[myIndex].value, target = "_self" );
}
}
// end -->
</script>
<form method="get" action="<?php echo $list_url ?>" class="show_sort_form">
<p>
<select name="<?php echo $sortfield ?>" onchange="change( this.form );">
<option value="0"> Select sort option</option>
<option value="all"> All <?php echo $member_type ?></option>
<?php
foreach( $sorters as $sort )
if( $sort == '' )
echo '<option value="none"> None given </option>';
else
echo '<option value="' . $sort . '"> ' . $sort . '</option>';
?>
</select>
</p>
</form>
<?php
} else { ?>
<p class="show_members_showing_what">from <?=count($sorters) ?> Countries</p>
<p class="center"><a href="">Sorted by Country</a> | <a href="<?=$siteurl?>/sort.php?country=all">Full List</a></p>
<div class="flaglist">
<?
foreach( $sorters as $sortvalue )
$dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password);
foreach($dbh->query('SELECT country, COUNT(*) FROM $table GROUP BY country') as $row) {
if( $sortvalue == '' )
echo '<li> <a href="' . $list_url . $connector . $sortfield .
'=none">None given</a> </li>';
else
if ($row['COUNT(*)'] != "1")
echo '<a href="' . $list_url . $connector . $sortfield .
'=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a> ' . $row['COUNT(*)'] . ' fans<br>';
else
echo '<a href="' . $list_url . $connector . $sortfield .
'=' . $sortvalue . '"><img src="' . $flags . str_replace(' ', '_', $sortvalue) . '.gif" title="' . $sortvalue . '" alt="' . $sortvalue . '"></a> ' . $row['COUNT(*)'] . ' fan<br>';
}
}
?>
</div>