Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You need to do two thing, first is an SQL query to retrive the values, you can do something like:</p> <pre><code>SELECT firstname,lastname,country FROM TABLE WHERE listedagree='Y' ORDER BY country </code></pre> <p>When you retrive the data on PHP you need to iterate over it, keeping the acctual country in a temp variable to be able to detect when it changes, for example you cand o something like:</p> <pre><code>//Conect to the database mysql_connect("hostaddress.com", "username", "password") or die(mysql_error()); //Selet the database to work with mysql_select_db("Database_Name") or die(mysql_error()); $sql = "SELECT firstname,lastname,country FROM TABLE WHERE listedagree='Y' ORDER BY country"; //retrive the data $result = mysql_query($sql) or die(mysql_error()); //Now iterate over the result and generate the HTML $html = ''; $tmp_country = ''; while($data = mysql_fetch_array( $result )) { //If the country have changed if($tmp_country != $data['country']) { //Check if we need to close the UL if($tmp_country != '') {$html .= "&lt;/ul&gt;"}; //Print the country header $html .= "&lt;h4&gt;$data['country']&lt;/h4&gt;"; $htm l .= "&lt;ul&gt;"; //store the last country $tmp_country = $data['country']; } //Add the names to each country $html .= "&lt;li&gt;$data['firstname'] $data['lastname']&lt;/li&gt;"; } //Close the last UL $html .= "&lt;/ul&gt;"; </code></pre> <p>I couldn't try the code so maybe it need some fine tunning to get it working but the it will do the job, if you have any problems let me know and i will help you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload