Kevin,
That was helpful to teaching me a little about PHP, but it still doesn't work as I thought it might. I rewrote the function to something like this:
function getNoShipping($product){
$result = mysql_query(sprintf("SELECT * FROM defaultPrices where product = '%s'", $product), $GLOBALS["g_db"]);
if ($result) {
$myrow = mysql_fetch_array($result);
echo $myrow["ship"];
if ($myrow["ship"] == 1){
return "";
}elseif($myrow["ship"] == 0){
return "&shipping=0.00";
}else{
return "";
}
}
}
"&shipping=0.00" returns for all results. 🙁
Here is more info on this:
Starting with Web page, I'm attempting to call from here with a form element:
<?php
echo "<font size=\"1\"><b>Print this photo:</b></font><br>";
echo "<SELECT size=1 name=\"Product\" onChange=\"if(options[selectedIndex].value) window.open(options[selectedIndex].value)\">";
echo "<OPTION value=>Choose an Option </option>";
ButtonsForAllProducts($GLOBALS["id"], $gallery->album->fields["name"]);
echo "</select>";
?>
This call this function:
function ButtonsForAllProducts($picture, $album)
{
$result = mysql_query(sprintf("SELECT * FROM defaultPrices", $product), $GLOBALS["g_db"]);
if ($result) {
while ($myrow = mysql_fetch_array($result)) {
$ship = getNoShipping($product);
$productName = $myrow["product"];
$finalPrice = getFinalPrice($album, $GLOBALS["id"], $productName);
echo payPalProductButton($ship, $picture, $productName, $finalPrice);
echo " ";
}
} else {
// There are no products. Probably shouldn't output anything.
echo "Not for sale";
}
return TRUE;
}
Which calls getNoShipping and this function:
function payPalProductButton($ship, $picture, $product, $price)
{
if ($price == $GLOBALS["g_notForSale"]) {
return $product . "(n/a)";
} else {
return "<option value=\"https://www.paypal.com/cart/add=1&business="
.
$GLOBALS["g_paypalEmail"]
.
$ship
.
"&item_name="
.
$product
.
"+-+"
.
$picture
.
"&item_number=&amount="
.
sprintf("%01.2f", $price)
.
"\">"
.
$product
.
"($"
.
sprintf("%01.2f", $price)
.
")</option>";
}
}
The database is connected with an include:
include($GALLERY_BASEDIR . "mods/constants.php");
Which reads something like this (of course with working values:
$GLOBALS["g_dbUser"] = "username";
$GLOBALS["g_dbPassword"] = "password";
$GLOBALS["g_dbName"] = "database";
$GLOBALS["g_paypalEmail"] = "name%40domain.com";