Hi I have my existing code

<?php
$query = sprintf("select venue,count(venue) as frequency from matches group by venue ORDER BY `frequency` DESC limit 300");
$result = mysql_query($query);
?>

and it outputs a table

<?php
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
$text = "".$row['venue'] . "";
$url = urlencode($text);
echo '<tr><td><a href="./venuedetails.php?v='. $url .'" target="_blank">'. $text .'</url></td>';
echo "<td> ".$row['frequency'] . "</td></tr>"; 
}
?>

I want to make it so that only venues where England have visited are counted for example. I have tried

$query = sprintf("select venue,count(venue) as frequency from matches WHERE Away = `England` group by venue ORDER BY `frequency` DESC limit 300");

but it doesn't work and I don't know what's wrong, apart from it telling me England doesn't exist when it does:'( :confused:

Any help would be great as I have searched and can only find the same way as I am using (and have used on other pages successfully (although not involving tables like this))

Thanks
Zack:)

Recommended Answers

All 3 Replies

try this

$query = sprintf("select venue,count(venue) as frequency from matches WHERE Away = 'England' group by venue ORDER BY frequency DESC limit 300");

Try to use some standard in your coding, rather than some caps and some lower case, for example SQL commands in caps and value in lower case, makes it easier to read

You would do well to add an error handle to the end of the SQL query to see if it is actually fetching any data from the db:

$var = mysql_query(some query)or die(mysql_error());

try this

$query = sprintf("select venue,count(venue) as frequency from matches WHERE Away = 'England' group by venue ORDER BY frequency DESC limit 300");

Thanks that worked :)

Try to use some standard in your coding, rather than some caps and some lower case, for example SQL commands in caps and value in lower case, makes it easier to read

You would do well to add an error handle to the end of the SQL query to see if it is actually fetching any data from the db:

$var = mysql_query(some query)or die(mysql_error());

Thanks I will try to include that in new code as I agree it would look easier to read then, and will add the die function

Thanks
Zack

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.