lilqhgal
03-31-2006, 01:59 PM
I have a form where the user clicks to view results in order by US state OR by international (non-US states). Right now, the results are displayed properly if the view-by-state selection is chosen. If the international selection is chosen, it displayes the results twice and the format is messed up. Here's the code:
<?php
if(isset($_POST['view_all']))
{
switch($_POST['view_all'])
{
case "state_asc":
$query = tep_db_query("SELECT * FROM `vendors` ORDER BY `vendors_state` ASC");
break;
case "international_asc":
$query = tep_db_query("SELECT * FROM `vendors` WHERE `vendors_country_id` != '223' ORDER BY `vendors_company` ASC");
break;
default:
$query = tep_db_query("SELECT * FROM `vendors`");
}
# replace the following echo with your actual query and output code:
$vendor_query = $query;
# loop through each row returned by query
while($vendor = mysql_fetch_object($vendor_query))
{
$string_vendor = '';
if (strlen($vendor->vendors_company)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= "<b>" . $vendor->vendors_company . "</b>";
}
if (strlen($vendor->vendors_firstname)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= "<b>" . $vendor->vendors_firstname . "</b> ";
}
if (strlen($vendor->vendors_lastname)>0) {
if ($string_vendor!='' and !(strlen($vendor->vendors_firstname)>0)) $string_vendor .= "<BR>";
$string_vendor .= "<b>" . $vendor->vendors_lastname . "</b>";
}
if (strlen($vendor->vendors_street_address)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= $vendor->vendors_street_address;
}
if (strlen($vendor->vendors_suburb)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>sub";
$string_vendor .= $vendor->vendors_suburb;
}
if (strlen($vendor->vendors_city)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= $vendor->vendors_city;
}
if (strlen($vendor->vendors_zone_id)>0) {
if ($string_vendor!='' and !(strlen($vendor->vendors_city)>0)) $string_vendor .= "";
if (strlen($vendor->vendors_city)>0) $string_vendor .= ', ';
$string_vendor .= tep_get_zone_code(223, $vendor->vendors_zone_id, $string_vendor) . ' ';
}
if (strlen($vendor->vendors_postcode)>0) {
$string_vendor .= $vendor->vendors_postcode;
}
if (strlen($vendor->vendors_telephone)>0) {
$string_vendor .= '<BR> ' . $vendor->vendors_telephone;
}
if (strlen($vendor->vendors_url)>0) {
$string_vendor .= "<BR><a href='" . $vendor->vendors_url ."' target='_blank'>" . $vendor->vendors_url . "</a>";
}
echo $string_vendor . "<br><br>";
}
}
?>
Now I'm not exactly sure how the zone id thing works, but that obviously has something to do with it. What I DO know is that all us based states are zone 223, and anything else would be considered international. So maybe some kind of if or not statement? But I'm not sure how to get it to work. Any suggestions are much appreciated. Thanks!
<?php
if(isset($_POST['view_all']))
{
switch($_POST['view_all'])
{
case "state_asc":
$query = tep_db_query("SELECT * FROM `vendors` ORDER BY `vendors_state` ASC");
break;
case "international_asc":
$query = tep_db_query("SELECT * FROM `vendors` WHERE `vendors_country_id` != '223' ORDER BY `vendors_company` ASC");
break;
default:
$query = tep_db_query("SELECT * FROM `vendors`");
}
# replace the following echo with your actual query and output code:
$vendor_query = $query;
# loop through each row returned by query
while($vendor = mysql_fetch_object($vendor_query))
{
$string_vendor = '';
if (strlen($vendor->vendors_company)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= "<b>" . $vendor->vendors_company . "</b>";
}
if (strlen($vendor->vendors_firstname)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= "<b>" . $vendor->vendors_firstname . "</b> ";
}
if (strlen($vendor->vendors_lastname)>0) {
if ($string_vendor!='' and !(strlen($vendor->vendors_firstname)>0)) $string_vendor .= "<BR>";
$string_vendor .= "<b>" . $vendor->vendors_lastname . "</b>";
}
if (strlen($vendor->vendors_street_address)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= $vendor->vendors_street_address;
}
if (strlen($vendor->vendors_suburb)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>sub";
$string_vendor .= $vendor->vendors_suburb;
}
if (strlen($vendor->vendors_city)>0) {
if ($string_vendor!='') $string_vendor .= "<BR>";
$string_vendor .= $vendor->vendors_city;
}
if (strlen($vendor->vendors_zone_id)>0) {
if ($string_vendor!='' and !(strlen($vendor->vendors_city)>0)) $string_vendor .= "";
if (strlen($vendor->vendors_city)>0) $string_vendor .= ', ';
$string_vendor .= tep_get_zone_code(223, $vendor->vendors_zone_id, $string_vendor) . ' ';
}
if (strlen($vendor->vendors_postcode)>0) {
$string_vendor .= $vendor->vendors_postcode;
}
if (strlen($vendor->vendors_telephone)>0) {
$string_vendor .= '<BR> ' . $vendor->vendors_telephone;
}
if (strlen($vendor->vendors_url)>0) {
$string_vendor .= "<BR><a href='" . $vendor->vendors_url ."' target='_blank'>" . $vendor->vendors_url . "</a>";
}
echo $string_vendor . "<br><br>";
}
}
?>
Now I'm not exactly sure how the zone id thing works, but that obviously has something to do with it. What I DO know is that all us based states are zone 223, and anything else would be considered international. So maybe some kind of if or not statement? But I'm not sure how to get it to work. Any suggestions are much appreciated. Thanks!