开发者

Show more button: With PHP and Mysql

I have been learning PHP/Mysql for a while. But don't yet know enough to do this.

I have table "cities"

I am using this query "SELECT * FROM cities GROUP B开发者_如何学GoY country"

I can output the results with

<?php do { ?>
<div class="cities">
<h4><a href="/cities/?id=<?php echo $row_cities['id']; ?>"><?php echo $row_cities['city']; ?></a></h4>
</div>
<?php } while ($row_cities = mysql_fetch_assoc($cities)); ?>

The group by country in the select query forces the results to only have one city for each country.

I want to create a "show more button/link" that once clicked will show all cities for each country.

This isn't very difficult somthing like this would do the trick.

<a href="/cities/?country=<?php echo $row_cities['country']; ?>">Show More</a>

However, I would like this show more button to be more "sophisticated".

a). The show more button should only appear if results of each city is greater than 1.

b). Show More text should also contain a number indicating the number of results example Show 1 More, Show 2 More Show 3 More etc.

Your help will be much appreciated


This will do

SELECT cities.id, cities.country, cities.city, count(*)
    FROM cities
    GROUP BY cities.country

The last selected field will hold the number of elements in each group.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜