close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 or 2018 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Custom Shipping calculations Ecart

Thread began 7/28/2014 10:09 am by birdscreen398247 | Last modified 8/07/2014 2:45 pm by Jason Byrnes | 901 views | 9 replies |

birdscreen398247

Custom Shipping calculations Ecart

I want to determine shipping rates based on weight and the left three digits of the zipcode. Rather than writing shipping rules for every combination, is there a simpler way to refer to an array? What is the function to grab the left three digits of the zipcode and what code is needed to grab a result from an array? Can someone point me to some sample code for doing something like this?

Sign in to reply to this post

Jason ByrnesWebAssist

use substr() to get the last 3 characters of a string:

$PostLast3 = substr($_POST["Postal_Code"], -3);


for arrays, see this page:


http://www.w3schools.com/php/php_arrays.asp

it should answer your question

Sign in to reply to this post

birdscreen398247

Thanks, but I need the first three digits, not the last three.

The array tutorial looks like it will answer my questions on arrays.

Sign in to reply to this post

Jason ByrnesWebAssist

ok, so use:
$PostFirst3 = substr($_POST["Postal_Code"], 0, 2);

also on w3schools is this page with details on the substr() function
http://www.w3schools.com/php/func_string_substr.asp

Sign in to reply to this post

birdscreen398247

substr works, but can't get result from recordset.

I cannot get my result page to display a result from a recordset based on a substring from the previous page. I can display that substring on the results page and when I test the recordset, it gives me a correct result, but it won’t display on the page.

I have two pages: an input page and a results page.

The Input Page has a form with a field “zipcode”.

The results page has a form that displays a substring of zipcode and the result of a recordset.

The recordset (on the results page) is as follows:

$colname_rsZipZones = "-1";
if (isset($_GET['substr($_POST["zipcode"],0,3)'])) {
$colname_rsZipZones = $_GET['substr($_POST["zipcode"],0,3)'];
}
mysql_select_db($database_BirdScreen, $BirdScreen);
$query_rsZipZones = sprintf("SELECT * FROM zipzones WHERE ZIPSTART = %s", GetSQLValueString($colname_rsZipZones, "text"));
$rsZipZones = mysql_query($query_rsZipZones, $BirdScreen) or die(mysql_error());
$row_rsZipZones = mysql_fetch_assoc($rsZipZones);
$totalRows_rsZipZones = mysql_num_rows($rsZipZones);
?>

I tried both a simple echo and also a text field. Both come up blank. (The echo of the substring works fine. It is the result from the recordset that does not display, although the "test" of the recordset works.)

<form name="form1" method="post" action="">

<p>Zip3: <?php echo substr($_POST["zipcode"],0,3); ?></p>
<p>
<input name="textfield" type="text" id="textfield" value="<?php echo $row_rsZipZones['ZONE']; ?>">
</p>

ZipZone: <?php echo $row_rsZipZones['ZONE']; ?>

</form>

What am I doing wrong? You can try the pages at http://www.birdscreen.com/TestSite/TestShipping.php

Sign in to reply to this post

Jason ByrnesWebAssist

the code for the variable in the recordset is wrong:
if (isset($_GET['substr($_POST["zipcode"],0,3)'])) {
$colname_rsZipZones = $_GET['substr($_POST["zipcode"],0,3)'];
}

which are you trying to use in the recordset? a URL variables or a POST variable, you cant use both which is what that code is trying to do.

Sign in to reply to this post

birdscreen398247

Still doesn't work

I deleted the recordset and recreated it. I selected "Form Variable" instead of URL Variable.

It now looks like this:


$colname_rsZipZones = "-1";
if (isset($_POST['substr($_POST["zipcode"],0,3)'])) {
$colname_rsZipZones = $_POST['substr($_POST["zipcode"],0,3)'];
}
mysql_select_db($database_BirdScreen, $BirdScreen);
$query_rsZipZones = sprintf("SELECT * FROM zipzones WHERE ZIPSTART = %s", GetSQLValueString($colname_rsZipZones, "text"));
$rsZipZones = mysql_query($query_rsZipZones, $BirdScreen) or die(mysql_error());
$row_rsZipZones = mysql_fetch_assoc($rsZipZones);
$totalRows_rsZipZones = mysql_num_rows($rsZipZones);

if (isset($_POST['substr($_POST["zipcode"],0,3)'])) {
$colname_rsZipZones = $_POST['substr($_POST["zipcode"],0,3)'];
}
?>

It still comes up blank.

Sign in to reply to this post

Jason ByrnesWebAssist

substr is inside the post variable name:
$_POST['substr($_POST["zipcode"],0,3)']

using the simple recordset interface, you cannot use functions like this, yu can only enter the variable name.

set it to use a URL variable named zipcode.

then add code before the recordset to set the URL variable:
<?php if(isset($_POST["zipcode"])) $_GET['zipcode'] = substr($_POST["zipcode"],0,3); ?>

Sign in to reply to this post

birdscreen398247

Thanks

Thanks. That worked.

Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...