Jump to content

Solved: Mysql Query


samerhannoun
 Share

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

Edited by Rainjo
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

Edited by Rainjo
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...