[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Replace Numeric Variable w/ Alpha-Numeric Variable

Posted on 2007-11-23
10
Medium Priority
?
492 Views
Last Modified: 2013-12-12
A form (attached) passes various shipping values to a session variable on the checkout page. Once the form passes the shipping values (i.e. 03) to the checkout page; I lose the textual alpha-numeric value (i.e. Ground). I want to display the textual value on the checkout page. What's the best way to replace the created SESSION variable integer with the text version from the previous form? I know of various ways to accomplish this - but which way is best and most efficient?
<select name="UPS_Service" id="UPS_Service">
        <option value="03" selected="selected">Ground</option>
        <option value="12">3 Day Select</option>
        <option value="02">2nd Day Air</option>
        <option value="59">2nd Day Air AM</option>
        <option value="13">Next Day Air Saver</option>
        <option value="01">Next Day Air</option>
        <option value="14">Next Day Air Early AM</option>
      </select>

Open in new window

0
Comment
Question by:EMB01
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
10 Comments
 
LVL 4

Expert Comment

by:simonkin
ID: 20339723
Hi,

Why not make a table of value and option pairs in your MySQL database.

Then do a MySQL lookup for the text option for the shipping value..
0
 
LVL 14

Author Comment

by:EMB01
ID: 20339754
I'd rather keep it hardcoded; just because these values will never be modified.
0
 
LVL 4

Expert Comment

by:simonkin
ID: 20339783
Alright,

Try some elseif statements...


<?php
 
    if ($_SESSION["shipping_value"] == 03) {
 
          $shipping_text = "Ground";
 
    } elseif ($_SESSION["shipping_value"] == 12){
 
          $shipping_text = "3 Day Select";
 
    } // and so on...
 
?>

Open in new window

0
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

 
LVL 14

Author Comment

by:EMB01
ID: 20339812
Isn't there a better way to do it with arrays?
0
 
LVL 28

Expert Comment

by:gamebits
ID: 20339931
Any reason why you use integer for the value submited instead of a text value

<option value="Ground" selected="selected">Ground</option>
0
 
LVL 14

Author Comment

by:EMB01
ID: 20340066
Yes, because the UPS Shipping Quote API requires variable integers such as 03, 12, etc.
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 300 total points
ID: 20340462
You can use a switch case statement:


<?php
	switch($_SESSION["shipping_value"])
	{
		case "03":
			{
				$mytext = "Ground";
				break;
			}
			
		case "12":
			{
				$mytext = "3 Day Select";
			}
			
		// etc........
		
	}
?>

Open in new window

0
 
LVL 21

Assisted Solution

by:nizsmo
nizsmo earned 300 total points
ID: 20340469
Alternatively you can use javascript.

Simple demonstration here:
<select name="UPS_Service" id="UPS_Service">
        <option value="03" selected="selected">Ground</option>
        <option value="12">3 Day Select</option>
        <option value="02">2nd Day Air</option>
        <option value="59">2nd Day Air AM</option>
        <option value="13">Next Day Air Saver</option>
        <option value="01">Next Day Air</option>
        <option value="14">Next Day Air Early AM</option>
</select>
 
<script type="text/javascript">
function show(){
var theContents = document.getElementById('UPS_Service')[document.getElementById('UPS_Service').selectedIndex].innerHTML;
window.alert(theContents);
}
</script>
 
<input type="button" onclick="show();" value="What is Selected?">

Open in new window

0
 
LVL 20

Assisted Solution

by:steelseth12
steelseth12 earned 75 total points
ID: 20340691
You do

$array_alpha = array("03"=>"Ground","12"=>3 Day Select,etc);

$_SESSION["array_alpha"] = $array_alpha;

Once the form is submited you can access the name simply by doing

$name = $_SESSION["array_alpha"][$_POST["UPS_Service"]]
0
 
LVL 14

Author Closing Comment

by:EMB01
ID: 31410669
I modified the code to:
<?php
      switch($_SESSION["shipType"])
      {
            case "03":
                  print "Ground";
                  break;
            case "12":
                  print "3 Day Select";
                  break;
            case "02":
                  print "2nd Day Air";
                  break;
            case "59":
                  print "2nd Day Air AM";
                  break;
            case "13":
                  print "Next Day Air Saver";
                  break;
            case "01":
                  print "Next Day Air";
                  break;
            case "14":
                  print "Next Day Air Early AM";
                  break;
      }
?>
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for …
WooCommerce is becoming the most powerful e-commerce plugin for Wordpress. And why not. The platform comprises of numerous core plugins that may come in handy, powerful options to make your website development task much easier.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question