Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Trouble getting all three to work...


lilqhgal

Recommended Posts

I have a contrib running that lets you search a vendors list by zip code. That part works great. I also have adapted it to query the same database and display the results in either ascending or decending results by the state and/or by the company name. AND, I also have another search form implimented that queries the same database and searches by keyword. Everything works if I have it on seperate pages. I would like to combine all three of them on one page. But when I do so, I keep getting invalid result resource errors. I know it's something simple. Can anybody help me? Here's the code:

 

<?php
/*
 $Id: vendor.php,v 1.0 2004/01/08 00:00:01 hobbzilla Exp $

 osCommerce, Open Source E-Commerce Solutions
 http://www.oscommerce.com

 Copyright (c) 2003 osCommerce

 Released under the GNU General Public License
*/

function great_circle_distance($lat1,$lat2,$lon1,$lon2)
{
/* Convert all the degrees to radians */
$lat1 = deg_to_rad($lat1);
$lon1 = deg_to_rad($lon1);
$lat2 = deg_to_rad($lat2);
$lon2 = deg_to_rad($lon2);

/* Find the deltas */
$delta_lat = $lat2 - $lat1;
$delta_lon = $lon2 - $lon1;

/* Find the Great Circle distance */
$temp = pow(sin($delta_lat/2.0),2) + cos($lat1) * cos($lat2) * pow(sin($delta_lon/2.0),2);
$EARTH_RADIUS = 3956;
$distance = $EARTH_RADIUS * 2 * atan2(sqrt($temp),sqrt(1-$temp));

return $distance;
}

function deg_to_rad($deg)
{
$radians = 0.0;
$radians = $deg * M_PI/180.0;
return($radians);
}

function StrToN($n, $l) {
$aux = "" . $n;
$ret = "";
for ($i=1; $i <= $l-strlen($aux); $i+=1)
	$ret .= "0";
return $ret . $aux;
}




 require('includes/application_top.php');
 require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_VENDOR);

 if (sizeof($navigation->snapshot) > 0) {
$origin_href = tep_href_link($navigation->snapshot['page'], tep_array_to_string($navigation->snapshot['get'], array(tep_session_name())), $navigation->snapshot['mode']);
$navigation->clear_snapshot();
 } else {
$origin_href = tep_href_link(FILENAME_DEFAULT);
 }

 $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : (isset($HTTP_POST_VARS['action']) ? $HTTP_POST_VARS['action'] : NULL));
 $error = false;

 if (tep_not_null($action)) {
switch ($action) {
  case 'submit':
  case 'select':
	$postcode = (isset($HTTP_GET_VARS['postcode']) ? $HTTP_GET_VARS['postcode'] : NULL);
	$page = (isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : '1');

	if (strlen($postcode) < ENTRY_POSTCODE_MIN_LENGTH) {
	  $error = true;
	  $messageStack->add('vendor', ENTRY_POST_CODE_ERROR);
	}

	break;
  case 'process':
	if (!tep_session_is_registered('customer_id')) {
	  $navigation->set_snapshot();
	  tep_redirect(tep_href_link(FILENAME_LOGIN, '', 'SSL'));
	}

	$options = explode("|", $option_vendor);
	$customer_vendors_id = tep_db_prepare_input($options[0]);
	$vendors_affiliate_id = tep_db_prepare_input($options[1]);
	tep_session_register('customer_vendors_id');
	tep_session_register('vendors_affiliate_id');

	tep_db_query("update " . TABLE_CUSTOMERS . " set customers_vendors_id = '" . (int)$customer_vendors_id . "' where customers_id = " . (int)$customer_id);

	$messageStack->add_session('account', SUCCESS_ACCOUNT_UPDATED, 'success');
	tep_redirect(tep_href_link(FILENAME_ACCOUNT, '', 'SSL'));
	break;
}
 }

 $breadcrumb->add(NAVBAR_TITLE, tep_href_link(FILENAME_VENDOR));

 $result_ar = mysql_fetch_assoc($result);

?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>"> 
<title><?php echo TITLE;?></title>
<base href="<?php echo (($request_type == 'SSL') ? HTTPS_SERVER : HTTP_SERVER) . DIR_WS_CATALOG; ?>">
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<?php include('includes/form_check.js.php'); ?>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->

<!-- body //-->
<table border="0" width="100%" cellspacing="3" cellpadding="3">
 <tr>
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- left_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_left.php'); ?>
<!-- left_navigation_eof //-->
</table></td>
<!-- body_text //-->
<td width="100%" valign="top"><table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
	<td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="0">
	  <tr>
		<td class="pageHeading"><?php echo HEADING_TITLE; ?></td>
		</tr>
	</table></td>
  </tr>
<?php
 if ($action == 'submit' || $action == 'select') {
$vendors_array = array();
if ($error == false) {
  $postcode5 = StrToN($postcode, 5);
  echo $postcode5;

  if (strlen($postcode5) > 0) $zip1_query = tep_db_query("select * from " . zipData . " where zipcode='" . $postcode5 . "'"); else $zip1_query = tep_db_query("select * from " . zipData . "'");
  $zip1 = tep_db_fetch_array($zip1_query);

  $sql_zips = "select v.vendors_id, z.zipcode, z.lon, z.lat from " . vendors . " v, " . zipData . " z where z.zipcode = v.vendors_postcode and v.vendors_status='1'";
  $zips_query = tep_db_query($sql_zips);

  while ($zip2 = tep_db_fetch_array($zips_query)) {
	$the_distance = great_circle_distance($zip1['lat'], $zip2['lat'], $zip1['lon'], $zip2['lon']);
	if ($the_distance < MAX_VENDOR_RADIUS) {
	  $vendors_array[] = array('vendors_id' => $zip2['vendors_id'],
							   'distance' => $the_distance);
	}
  }
}
if (count($vendors_array) > 0) {
  foreach ($vendors_array as $val) {
   $sortarray[] = $val['distance'];
  }
  array_multisort($sortarray,$vendors_array);
}

$listing_split = new splitVendorPageResults($vendors_array, MAX_DISPLAY_VENDOR_RESULTS);
?>
  <tr>
	<td colspan="2"><table border="0" width="100%" cellspacing="0" cellpadding="0">
<?php
if ($action == 'select') {
?>
	  </form>
<?php
}
?>
	</table></td>
  </tr>
<?php
 }
?>
  <tr>
	<td width="197" valign="top">




	<table width="197" border="0" cellpadding="0" cellspacing="0">
 <tr>
<td><img src="images/slice_sets/2/top_left.jpg" width="25" height="67"></td>
<td background ="images/slice_sets/2/top_background.jpg" valign="bottom" align="center" width="100%"><p class="newinfoBox_top1">Search by Zip</p>
	<p class="smallText"> Enter Your Zip Code: </p></td>
<td><img src="images/slice_sets/2/top_right.jpg" width="25" height="67"></td>
 </tr>
 <tr>
<td background ="images/slice_sets/2/left_background.jpg"></td>




<td bgcolor="#ECE6E8">		  <?php echo tep_draw_form ('list_vendor', tep_href_link(FILENAME_VENDOR, '', 'SSL'),'get', 'onSubmit="return check_form(list_vendor);"') . tep_hide_session_id() . tep_draw_hidden_field('action', (tep_not_null($action) ? $action : 'submit')); ?>
	   <?php echo tep_draw_input_field('postcode', '', 'size="10" maxlength="5" class="input_box"'); ?>
		<?php echo tep_image_submit('button_go.gif', IMAGE_BUTTON_CONTINUE); ?></form>
</td>
<td background ="images/slice_sets/2/right_background.jpg"></td>
 </tr>
 <tr>
<td valign="top"><img src="images/slice_sets/2/bottom_left.jpg" width="25" height="160"></td>
<td height="160" style="background-image:url(images/slice_sets/2/bottom_background.jpg); background-repeat: repeat-y"></td>
<td valign="top"><img src="images/slice_sets/2/bottom_right.jpg" width="25" height="160"></td>
 </tr>
</table>





	<table width="197" border="0" cellpadding="0" cellspacing="0">
	  <tr>
		<td><img src="images/slice_sets/2/top_left.jpg" width="25" height="67"></td>
		<td background ="images/slice_sets/2/top_background.jpg" valign="bottom" align="center" width="100%"><p class="newinfoBox_top1">Search by Keyword </p>
			<p class="smallText"> Enter Your Keywords: </p></td>
		<td><img src="images/slice_sets/2/top_right.jpg" width="25" height="67"></td>
	  </tr>
	  <tr>
		<td background ="images/slice_sets/2/left_background.jpg"></td>
		<td bgcolor="#ECE6E8">
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="text" name="search" value="">
<input type="image" name="submit_key" value="" src="includes/languages/english/images/buttons/button_go.gif">
		</form>
		</td>
		<td background ="images/slice_sets/2/right_background.jpg"></td>
	  </tr>
	  <tr>
		<td valign="top"><img src="images/slice_sets/3/bottom_left.jpg" width="25" height="160"></td>
		<td height="160" style="background-image:url(images/slice_sets/3/bottom_background.jpg); background-repeat: repeat-y;"></td>
		<td valign="top"><img src="images/slice_sets/3/bottom_right.jpg" width="25" height="160"></td>
	  </tr>
	</table>
	<table width="197" border="0" cellpadding="0" cellspacing="0">
	  <tr>
		<td><img src="images/slice_sets/2/top_left.jpg" width="25" height="67"></td>
		<td background ="images/slice_sets/2/top_background.jpg" valign="bottom" align="center" width="100%"><p class="newinfoBox_top1">View All Dealers </p>
			<p class="smallText"> Sort by: </p></td>
		<td><img src="images/slice_sets/2/top_right.jpg" width="25" height="67"></td>
	  </tr>
	  <tr>
		<td background ="images/slice_sets/2/left_background.jpg"></td>
		<td rowspan="2" bgcolor="#ECE6E8" style="background-image:url(images/slice_sets/3/bottom_background.jpg); background-repeat: repeat-y;">
		<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<p align="center">
<input type="image" name="submit_all" value="state_asc" src="images/web/state-up.gif"><br>
<input type="image" name="submit_all" value="state_desc" src="images/web/state-down.gif"><br>
<input type="image" name="submit_all" value="company_asc" src="images/web/company-up.gif"><br>
<input type="image" name="submit_all" value="company_desc" src="images/web/company-down.gif"><br>
</p>
</form>


		</td>
		<td background ="images/slice_sets/2/right_background.jpg"></td>
	  </tr>
	  <tr>
		<td height="160" valign="top"><img src="images/slice_sets/3/bottom_left.jpg" width="25" height="160"></td>
		<td valign="top"><img src="images/slice_sets/3/bottom_right.jpg" width="25" height="160"></td>
	  </tr>
	</table></td>
	<td valign="top" class="main">   



<!-- SEARCH DEALERS BY ZIP -->	
		   <?php
if (count($vendors_array) > 0) {
  if ($messageStack->size('vendor') > 0) {
	echo $messageStack->output('vendor');
  }
  echo "<table border=0 width='100%' cellspacing='5' cellpadding='5'>\n";

  $sp_start = MAX_DISPLAY_VENDOR_RESULTS * ($page - 1);
  $sp_max = ($page < ceil(count($vendors_array)/MAX_DISPLAY_VENDOR_RESULTS)) ? MAX_DISPLAY_VENDOR_RESULTS + $sp_start : count($vendors_array) % MAX_DISPLAY_VENDOR_RESULTS + $sp_start;

  if ($action == 'select') {
	echo tep_draw_form ('select_vendor', tep_href_link(FILENAME_VENDOR, '', 'SSL'),'post', '') . tep_draw_hidden_field('action', 'process');
	echo "<tr valign='top'>\n";
	echo "<TD WIDTH='10%'>";
	echo "<input type=radio name='option_vendor' value='0|0' ";
	if ($customer_vendors_id == 0) {
	  echo "checked";
	}
	echo ">";
	echo "</td>";
	echo "<td width='90%' class='main'>";
	echo "<strong>" . TEXT_VENDOR_NOT_LISTED . "</strong>";
	echo "</TD>\n";
	echo "</tr>\n";
  }

  for ($i=$sp_start; $i < $sp_max; $i++) {
	  echo "<tr valign='top'>\n";

	  $vendor_query = tep_db_query("select vendors_id, vendors_company, vendors_firstname, vendors_lastname, vendors_street_address, vendors_postcode, vendors_city, vendors_state, vendors_url, vendors_affiliate_id, vendors_zone_id from " . vendors . " WHERE vendors_id='" . $vendors_array[$i]['vendors_id'] . "'");
	  if (mysql_num_rows($vendor_query)==0) continue;
		$vendor = mysql_fetch_object($vendor_query);

		@mysql_free_result($vendor_query);

		$string_vendor = '';

	  if (strlen($vendor->vendors_company)>0) {
		$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_url)>0) {
		$string_vendor .= "<BR><a href='" . $vendor->vendors_url ."' target='_blank'>" . $vendor->vendors_url . "</a>";
//		  $string_vendor .= "<a href='" . $vendor->vendors_url . "' target='_blank'>" . $string_vendor . "</a>";			
	  }

	  if (DISPLAY_VENDOR_DISTANCE == 'true') {
		$string_vendor .= '<BR>' . TEXT_DISTANCE . number_format($vendors_array[$i]['distance'], 1) . TEXT_MILES;
	  }



	  echo "<TD WIDTH='10%'>";
	  if ($action == 'select') {
		echo "<input type=radio name='option_vendor' value='" . $vendor->vendors_id . "|" . $vendor->vendors_affiliate_id . "' ";
		if ($customer_vendors_id == $vendor->vendors_id) {
		  echo "checked";
		}
		echo ">";
	  } else {
	  echo " ";
	  }

	  echo "</td>";
	  echo "<td width='90%' class='main'>";
	  echo $string_vendor;
	  echo "</TD>\n";
	  echo "</tr>\n";
  }
  echo "</table>\n";
} else {

	if ($messageStack->size('vendor') > 0) {
	   echo $messageStack->output('vendor');
	} else {
//		  echo TEXT_VENDOR_NOT_FOUND;

	if ($action == 'select') {
	  echo "<table border=0 width='100%' cellspacing=1 cellpadding=2>\n";
	  echo tep_draw_form ('select_vendor', tep_href_link(FILENAME_VENDOR, '', 'SSL'),'post', '') . tep_draw_hidden_field('action', 'process');
	  echo "<tr valign='top'>\n";
	  echo "<TD WIDTH='10%'>";
	  echo "<input type=radio name='option_vendor' value='0|0' ";
	  if ($customer_vendors_id == 0) {
		echo "checked";
	  }
	  echo ">";
	  echo "</td>";
	  echo "<td width='90%' class='main'>";
	  echo "<strong>" . TEXT_VENDOR_NOT_LISTED . "</strong>";
	  echo "</TD>\n";
	  echo "</tr>\n";
	  echo "</table>\n";
	}
  }
 }
?>
<!-- END SEARCH DEALERS BY ZIP -->





<!-- SEARCH DEALERS BY KEYWORD -->
	  <?php
if(isset($_POST['submit_key']))
{
 switch($_POST['submit_key'])
 {
case "submit":
  $query = tep_db_query("SELECT * FROM `vendors` WHERE `vendors_company` LIKE '%{$search}%'"); 
  break;
 }

$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) {
		  $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_url)>0) {
		  $string_vendor .= "<BR><a href='" . $vendor->vendors_url ."' target='_blank'>" . $vendor->vendors_url . "</a>";
		}

	  echo "<div class='main'>";
	  echo $string_vendor . "<br><br>";
	  echo "</div>";
	  }
}	  
?>
<!-- END SEARCH DEALERS BY KEYWORD -->






<!-- VIEW ALL DEALERS -->

<?php
//if(isset($_POST['submit_all']))
//{
 switch($_POST['submit_all'])
 {
case "state_asc":
  $query_all = tep_db_query("SELECT * FROM `vendors` ORDER BY `vendors_state` ASC");
  break;
case "state_desc":
  $query_all = tep_db_query("SELECT * FROM `vendors` ORDER BY `vendors_state` DESC");
  break;
case "company_asc":
  $query_all = tep_db_query("SELECT * FROM `vendors` ORDER BY `vendors_company` ASC");
  break;
case "company_desc":
  $query_all = tep_db_query("SELECT * FROM `vendors` ORDER BY `vendors_company` DESC");
  break;
//	default:
//	 $query = tep_db_query("SELECT * FROM `vendors`");
 }
//}
//else
//{
//$query_all = " ";
//}
$vendor_query_all = $query_all;
	  # loop through each row returned by query
	  while($vendor = mysql_fetch_object($vendor_query))		  
	  {
		$string_vendor = '';

		if (strlen($vendor->vendors_company)>0) {
		  $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_url)>0) {
		  $string_vendor .= "<BR><a href='" . $vendor->vendors_url ."' target='_blank'>" . $vendor->vendors_url . "</a>";
		}

		echo $string_vendor . "<br><br>";
	  }

?> 		
<!-- END VIEW ALL DEALERS -->

</td>
  </tr>
</table></td>
<!-- body_text_eof //-->
<td width="<?php echo BOX_WIDTH; ?>" valign="top"><table border="0" width="<?php echo BOX_WIDTH; ?>" cellspacing="0" cellpadding="2">
<!-- right_navigation //-->
<?php require(DIR_WS_INCLUDES . 'column_right.php'); ?>
<!-- right_navigation_eof //-->
</table></td>
 </tr>
</table>
<!-- body_eof //-->

<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
<br>
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...