Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post

    Value not returning

    I have the following code but I cannot get it to return a value.

    PHP Code:
              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(
    == $featured){$total_profit=$orders['final_price'] * $default_featured;}
              else if (
    == $featured) {$total_profit=$orders['final_price'] * $default_normal;}
              
            
              echo  
    $total_profit;
              echo 
    '<br>';
              
             } 
    If I do
    PHP Code:
     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.

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,042
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
     if($date >=$orders['featured_date_added'] and $date <= $orders['expires_date']){
              
    $featured 1; echo 'testing'}
               else [
    COLOR="Red"]{[/COLOR//you were missing an { here
                      
    $featured 2;
               } 

  • #3
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    So now I have the following function and still nothing is being returned
    PHP Code:
     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;
             
              } 

  • #4
    Regular Coder
    Join Date
    Aug 2006
    Posts
    311
    Thanks
    0
    Thanked 1 Time in 1 Post
    OK I figured out the problem that I was having I had to declare the function with a variable like this:

    PHP Code:
      $fea=check_featured($orders['id'],$orders['date']);
              
              
              
              if(isset(
    $fea)){echo 'it is returning';}
              if(
    == $fea){$total_profit=$orders['final_price'] * $default_featured;}
              else if (
    == $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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •