hallo,
habe eine datenbank, ein table countrys mit namen und id und dann noch einen table "location" in welchem zu countrys noch regionen und stadte zugeordnet werden.
jetzt möchte ich 2 textstrings vergleichen. der erste ist das ergebniss einer datenbankabfrage ($res['countryname']), der 2. eine variable welche den inhalte der vorherigen zeile ($country_tmp) beinhaltet. jetzt soll jedesmal, wenn in der abfrage ein neues land beginnt dieses als link ausgegeben werden - ansonsten sollen einfach die anderen werte aus der aktuellen spalte ausgegeben werden.
wer mit jetzt nicht folgen kann, für den das ganze nochmal als php-code:
function listcountrys() {
global $db;
$out = "";
$sql = "SELECT l.country_id, l.state_short, l.state_long, c.name as countryname FROM location l INNER JOIN country c ON c.country_id=l.country_id GROUP BY l.country_id, l.state_short, l.state_long, countryname ORDER BY countryname DESC";
//echo $sql."<br>";
$erg = $db->query($sql);
while ($res = $db->getdata($erg)) {
if(!$country_tmp==$res['countryname']) {
$country_tmp=$res['countryname'];
$out .= '<br><h2><a href="?country_id='.$res['country_id'].'">'.$country_tmp.'</a></h2>'."\n";
}
$state_tmp=$res['state_short'];
$out .= ' <a href="?country_id='.$res['country_id'].'&state='.$res['state_short'].'">'.$res['state_long'].'</a> '."\n";
}
return $out;
}
wer den fehler nicht sofort findet und es ausprobieren möchte, hier die 2 tables: (2.5kB)
http://www.shareyourride.net/test/transport.sql
jemand mit einer idee hier was in den diesen zeilen falsch ist:
if(!$country_tmp==$res['countryname']) {
$country_tmp=$res['countryname'];
$out .= '<br><h2><a href="?country_id='.$res['country_id'].'">'.$country_tmp.'</a></h2>'."\n";
}
danke für eure mühen...