Okay, here's the situation. I'm building the distributors page for a client's site, and I'm going to have a select list with all his distributors. It is to be structured as follows:
-----COUNTRY-----
---PROVINCE/STATE---
Dealer Name (City)
Dealer Name (City)
---PROVINCE/STATE---
Dealer Name (City)
-----COUNTRY-----
---PROVINCE/STATE---
Dealer Name (City)
Dealer Name (City)
Dealer Name (City)
---PROVINCE/STATE---
Dealer Name (City)
and so on.
Below is the code that I'm using to loop through the recordset, but first a short explanation.
I'm looping through the recordset and at the end I'm assigning the variable $last_dist the value of the current recordset (so for the first loop, $last_dist is empty). Then I perform a series of checks which decide if the two recordsets have the same province and country, the same country, or neither, and act accordingly.
Oh, and I'm using ADOdb for db access.
$last_dist; // set empty var to hold last record processed
while (!$dist_rs->EOF) {
if (count($last_dist) == 0) {
echo "<option>".strtoupper($dist_rs->fields['country_name'])." ----------</option>\n";
echo "<option>--- ".$dist_rs->fields['provstate']." ---</option>\n";
echo "<option value=\"".$dist_rs->fields['dist_id']."\">".$dist_rs->fields['name']." (".$dist_rs->fields['city_town'].")</option>\n";
} else if ($dist_rs->fields['country'] == $last_dist[country] && $dist_rs->['prov_state'] == $last_dist[prov_state]) {
echo "<option value=\"".$dist_rs->fields['dist_id']."\">".$dist_rs->fields['name']." (".$dist_rs->fields['city_town'].")</option>\n";
} else if ($dist_rs->fields['country'] == $last_dist[country] && $dist_rs->['prov_state'] != $last_dist[prov_state]) {
echo "<option>----- ".$dist_rs->fields['provstate']." -----</option>\n";
echo "<option value=\"".$dist_rs->fields['dist_id']."\">".$dist_rs->fields['name']." (".$dist_rs->fields['city_town'].")</option>\n";
} else if ($dist_rs->fields['country'] != $last_dist[country]) {
echo "<option>".strtoupper($dist_rs->fields['country_name'])."</option>\n";
echo "<option>------------------</option>\n";
echo "<option>----- ".$dist_rs->fields['provstate']." -----</option>\n";
echo "<option value=\"".$dist_rs->fields['dist_id']."\">".$dist_rs->fields['name']." (".$dist_rs->fields['city_town'].")</option>\n";
}
unset($last_dist);
$last_dist = $dist_rs->fields;
$dist_rs->MoveNext();
}
Now whenever I run the code as it is, I get the following error:
Parse error: parse error, expecting T_STRING' orT_VARIABLE' or '{'' or'$'' in c:\phpdev\www\rushtonlandingnets\includes\c_distributors.php on line 44
However, if I remove the three else if statements and replace them with an else statement, I can output the remaining records, through either the $last_dist variable, or the current recordset.
Anyone have any idea as to why the code won't work as it is? I've been looking at it for quite a while and trying everything I can think of but I can't find the problem.
Any help is greatly appreciated.
Thanks in advance,
Pablo