Help With Some PHP Code

Discussion in 'Web Design and Development' started by joro, Aug 19, 2009.

  1. joro macrumors 68020

    joro

    Joined:
    Jun 11, 2009
    Location:
    NOVA
    #1
    I am in the process of re-designing a client gallery site for my photography company and I'm having a bit of trouble getting a certain menu to display. This is a PHP file that is called by an include () tag in the index.php file.

    Basically the main menu is working but for some reason it's not showing the cart code even though there are products in the cart. I'm assuming this is the code that's most important:

    Code:
    <?php 
    		if(($ctotal > 0)OR($cartItems > 0)==true) {
    			if($ctotal > 0) {	
    print showPrice($ctotal)."  ";
    			}
    		printLinks(2, $ctotal, $cartItems);	
    	}
    
    	?>
    The problem is however, it's not printing anything on the page. I was worried that it may be something with the CSS; however, I can't even pull it up when I do a search of the source code that is generated off the PHP which means it's not showing up period. Does anyone know why this not working?

    The full PHP file is below.

    Code:
    <?php if(( $_SESSION['pc_client_login'] !== true) ||  ($_SESSION['pc_client_id'] == NULL )) 
    
    { 
    	printLinks(3, $ctotal, $cartItems);
    	} else {
    
    	printLinks(4, $ctotal, $cartItems);
    }
    
    ?>
    
    <?php 
    function printLinks($location, $ctotal, $cartItems) {
    	global $tr,$setup, $addOnFeature;
    	$links = whileSQL("pc_menu_links", "*", "WHERE link_location='$location'  AND link_status='1' ORDER BY link_order ASC ");
    	while($link = mysql_fetch_array($links)) {
    		if($link['link_text_field'] == "store_top_link") {
    			if(isset($addOnFeature['accessories'])) { 
    				$cs = doSQL("pc_acc_settings", "*", "");
    				if($cs['store_status'] == "1") {
    					 if($lc> 0) { print "    "; } $lc++;
    					print "<li><a href=\"";  if($_REQUEST['action'] == "payment") { print $setup['url']."/"; } print "".$link['link_url']."\">".$cs['store_top_link']."</a>";
    				}
    			}
    		} else {
    			 if($lc> 0) { print "    "; } $lc++;
    			if(!empty($link['link_text_field'])) { print "<li><a href=\"";  if($_REQUEST['action'] == "payment") { print $setup['url']."/"; } print "".$link['link_url']."\">".$tr[$link['link_text_field']]; } else {  print "<a href=\"".$link['link_url']."\">".$link['link_text']; } print "</a>";
    		}
    	}
    }
    ?>
    
    <?php 
    	if(!function_exists(photoCartIncluded)) { die("Direct file access denied"); }
    
    	if((( $_SESSION['pc_client_login'] == true) AND  ($_SESSION['pc_client_id'] !== NULL ))OR(($ctotal > 0) OR ($cartItems>0))==true){ ?>
    	
    	<?php if(( $_SESSION['pc_client_login'] == true) AND  ($_SESSION['pc_client_id'] !== NULL ) == true) { 
    	$client = doSQL("pc_clients", "*", "WHERE client_id='".$_SESSION['pc_client_id']."' ");
    	if(!empty($client['client_id'])) {
    		updateSQL("pc_clients", "client_last_active=NOW(), client_ip='".$_SERVER['REMOTE_ADDR']."'  WHERE client_id='".$client['client_id']."' ");
    	}
    print "</ul><br><br><h1>My Menu</h1><ul>";
    	printLinks(1, $ctotal, $cartItems);	
    	}
    
    	?>
    	
    	<?php 
    		if(($ctotal > 0)OR($cartItems > 0)==true) {
    			if($ctotal > 0) {	
    print showPrice($ctotal)."  ";
    			}
    		printLinks(2, $ctotal, $cartItems);	
    	}
    
    	?>
    	
    
    
    	<?php } ?>
    
    <?php
     if(customerLoggedIn()) {
    	$ctotal = doSQL("pc_customer_credits", "SUM(credit_amount) AS tot", "WHERE credit_customer='".$_SESSION['pc_client_id']."' ");
    	if($ctotal['tot']>0) { ?>
    	<div class=tables>
    	 <?php 
    		$credit_message = str_replace("[CREDIT_AMOUNT]",showPrice($ctotal['tot'])."", "".$tr['credit_statement']."");
    		print $credit_message;
    		?>
    	 </div>
    	<?php } ?>
    <?php } ?>
     
  2. rowsdower macrumors 6502

    Joined:
    Jun 2, 2009
    #2
    Code:
    if(($ctotal > 0)OR($cartItems > 0)==true) {
    			if($ctotal > 0) {	
    print showPrice($ctotal)."  ";
    			}
    This won't print anything if $ctotal <= 0. Maybe the items in the cart don't have a price or the price is zero?

    Code:
    printLinks(2, $ctotal, $cartItems);
    From the printLinks function:
    Code:
    $links = whileSQL("pc_menu_links", "*", "WHERE link_location='$location'  AND link_status='1' ORDER BY link_order ASC ");
    This won't return anything if there are no links in your database with the location you passed in (2 in this case), or if there are links but their status is not 1. Do the links exist in your database?
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    The ==true part on that if statement is unnecessary. I also generally use || for an or, rather than OR.
    PHP:
    if (($ctotal 0) || ($cartItems 0)) {
    Haven't looked at the other code yet.
     
  4. joro thread starter macrumors 68020

    joro

    Joined:
    Jun 11, 2009
    Location:
    NOVA
    #4
    Everything in the cart has a price, I've also verified that it is showing a $ amount greater than 0.00. I'm going to look into the second part about the DB although they should be there because it shows fine when I remove the PHP modifications I've done on this page. Thanks for the help!
     

Share This Page