Jump to content

Solved: Mysql Query


samerhannoun

Recommended Posts

Hi guysI have the following Scenario Loading Postal Code : User Enter this value Unloading Postal Code: User Enter this valueConsider the up lines are the html screennow every postal code regarding to a specific zone for example112, 114, 132 (zone1)113,115, 129 (zone2)now each zone have loading and unloading price, for examplezone1, loading price: 10, unloading price: 499zone2, loading price: 20, unloading price: 699if the user enter 2 values for the same zone, for example zone1, the result should be: 10+499=509if the user enter 2 values for different zones, for example, from zone1 to zone 2the result should be: loading zone1 + unloading zone2 10 + 699 = 709 and there are anther choice: loading zone 2 and unloading zone1 the result: 20 +499 = ... what is the solution for this cases I can't sleep hahah

Link to comment
Share on other sites

Store the zones in a database, and look up what they selected to get the values you're looking for. Each record in the table should be a zone with things like ID and name, plus the other values you want to track.

Link to comment
Share on other sites

justsomeguy the god father of this forumthank you for your replayok I will create a database table zone_id, zone_name,postal, loading, unloading the problem How can I decide or expect the order of the user input because this is a very important factor to calc. something So I will query the 2 input of the user using OR operatorthen I should take the loading cost for the first variable and unloading price for the second variable.I do the following $q=mysql_query("select loading,unloading from zones where postal="$firstInput" or postal="$secondInput")Now I should retrieve 2 records with loading and unloading costs. what I need take the loading price for the first record and the unloading price for the second onehow can I do that?or make 2 query the first one take the loading price and second one take the unloading price thank you again

Link to comment
Share on other sites

Two queries would work. If you want to get them both with one query, you'll need to use something like this:

$load = $unload = 0;$q=mysql_query("select loading,unloading from zones where postal='$firstInput' or postal='$secondInput'");while ($row = mysql_fetch_assoc($q)){  if ($row['postal'] == $firstInput)	$load = $row['loading'];  if ($row['postal'] == $secondInput)	$unload = $row['unloading'];}if ($load == 0 || $unload == 0){  echo 'load or unload was not found.';}

Link to comment
Share on other sites

Hi ,, Thank you for your replay I try this code, but something wrong happened with me with following code

while ($row = mysql_fetch_assoc($q)){  if ($row['postal'] == $firstInput)	$load = $row['loading'];  if ($row['postal'] == $secondInput)	$unload = $row['unloading'];}

in thats code, if the user enter 2 values match the criteria for the if statement, loading and unloading vars will take the value of the last record retrieved from database!! thank you again

Link to comment
Share on other sites

Hi guysthis is the solution of this case: firstly let me describe the database table zonesTable (ZoneName,loading,Unloading)postalsTable(ZoneName,postal).in the query we should make 2 instance for the tow tablezoneTable 1.ZoneTable loading2.ZoneTable unloading and so on for the postals table to take the loading form the first table and take the unloading form the second one and the query is :

SELECT zl.zone zone_loading, zl.loading, zu.zone zone_unloading, zu.unloadingFROM postals pl, postals pu, zones zl, zones zuWHERE pl.postal = firstInput AND 	  pu.postal = secindInput AND	  zl.zone = pl.zone AND	  zu.zone = pu.zone

thank you all

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...