...

View Full Version : Value not returning



Jacobb123
05-10-2008, 06:29 PM
I have the following code but I cannot get it to return a value.



function check_featured($prodID, $date){
$item = mysql_query("SELECT products_id, featured_date_added, expires_date FROM featured where products_id='$prodID'") or die(mysql_error());
$orders=mysql_fetch_array($item);
$num_rows=mysql_num_rows($item);
if($num_rows >0){
if($date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
$featured = 1; }
else $featured = 2;
}

if(!$date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
$featured = 2; }

return $featured;

}


$rates_query1 = "select * from products_commission where products_id = 999999";

$rates0 = tep_db_query($rates_query1);
$rates1 = tep_db_fetch_array($rates0);
$default_normal = '.0'.$rates1['normal_commission' ];
$default_featured = '.0'.$rates1['featured_commission' ];


//query product_orders to see if a product was featured and return total amount - fee taken

$product_orders=mysql_query("SELECT o.date_purchased as date,op.vendors_id,op.products_id as id ,op.orders_id,op.final_price FROM orders_products op, orders o WHERE op.vendors_id = {$_SESSION['login_vendor']} and op.orders_id = o.orders_id") or die(mysql_error());

while($orders=mysql_fetch_array($product_orders)){
check_featured($orders['id'],$orders['date']);

if($featured){echo 'it is set';}
if(1 == $featured){$total_profit=$orders['final_price'] * $default_featured;}
else if (2 == $featured) {$total_profit=$orders['final_price'] * $default_normal;}


echo $total_profit;
echo '<br>';

}

If I do
if($date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
$featured = 1; echo 'testing'}
else $featured = 2;
}
it outputs testing so my queries are ok. It just will not return the values and can't figure out why.

rafiki
05-10-2008, 06:39 PM
if($date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
$featured = 1; echo 'testing'}
else { //you were missing an { here
$featured = 2;
}

Jacobb123
05-11-2008, 05:39 AM
So now I have the following function and still nothing is being returned

function check_featured($prodID, $date){
$item = mysql_query("SELECT products_id, featured_date_added, expires_date FROM featured where products_id='$prodID'") or die(mysql_error());
$orders=mysql_fetch_array($item);
$num_rows=mysql_num_rows($item);
if($num_rows >0){
if($date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
$featured = 1; }
else {$featured = 2;}
}

if(!$date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
$featured = 2; }

return $featured;

}

Jacobb123
05-11-2008, 06:27 AM
OK I figured out the problem that I was having I had to declare the function with a variable like this:


$fea=check_featured($orders['id'],$orders['date']);



if(isset($fea)){echo 'it is returning';}
if(1 == $fea){$total_profit=$orders['final_price'] * $default_featured;}
else if (2 == $fea) {$total_profit=$orders['final_price'] * $default_normal;}


I was under the impression that when returned the value featured in the funciton that It would be treated as a super global and I would be able to declare it anywhere but apparently it doesn't work like that.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum