Jump to content

Recommended Posts

Not sure why it won't let me use the } else { statement. It gives me an error. I'm trying to make it so that if there is a parent_result > 0 then it displays the subcategory, if not it just moves to the next.

 

 

   $k2_sql = mysql_query("SELECT * FROM categories WHERE parent_id = 0");
   while ($k_result2 = mysql_fetch_array($k2_sql)){
   		$cat_id = $k_result2['categories_id'];


	  $parent_sql = "SELECT * FROM categories WHERE parent_id = ".$catpath;
	   $parent_query = mysql_query($parent_sql) or die(mysql_error());

	   $parent_result = mysql_num_rows($parent_query);
	  

   $k_sql = mysql_query("SELECT * FROM categories WHERE parent_id = 0");
   while ($k_result = mysql_fetch_array($k_sql)){
   		$cat_id = $k_result['categories_id'];
	$cat_parent = $k_result['parent_id'];
	$cat_sort = $k_result['sort_order'];

	$kk_sql = mysql_query("SELECT categories_name FROM categories_description WHERE categories_id = $cat_id");
	while ($kk_result = mysql_fetch_array($kk_sql)){
	$cat_name = $kk_result['categories_name'];
	}
	?><li><a href="shop.php?cPath=<?php echo $cat_id; ?>"><?php echo $cat_name; ?></a></li>
        <?php
}
$parents_cat_id = mysql_query("SELECT * FROM categories WHERE parent_id = ".$catpath)or die(mysql_error());
	   	$parents_cat_num = mysql_num_rows($parents_cat_id) or die(mysql_error());
		    while ($parent_c = mysql_fetch_array($parents_cat_id)){
			$new_parents_cat_id = $parent_c['categories_id'];
		$parent_cat_sql = mysql_query("SELECT * FROM categories_description WHERE categories_id = $new_parents_cat_id");
		if($parent_result > 0){	
		while ($p_c_s = mysql_fetch_array($parent_cat_sql)){
		$subcat_name = $p_c_s['categories_name']; 
		$subcat_id = $p_c_s['categories_id']; 
				echo '<span id="left_nav_sub"><li><a href="shop.php?cPath=' .$subcat_id . '">' .$subcat_name. '</a></li></span>';
		}
		}
		}
		} else {
		}

?>

Link to comment
https://forums.phpfreaks.com/topic/82686-ifelse-statement-syntax-problem/
Share on other sites

I commented them

and they balance in my Zend Studio

 

<?php
   $k2_sql = mysql_query("SELECT * FROM categories WHERE parent_id = 0");
   //start while 1
   while ($k_result2 = mysql_fetch_array($k2_sql)){
   		$cat_id = $k_result2['categories_id'];


	  $parent_sql = "SELECT * FROM categories WHERE parent_id = ".$catpath;
	   $parent_query = mysql_query($parent_sql) or die(mysql_error());

	   $parent_result = mysql_num_rows($parent_query);
	  

   $k_sql = mysql_query("SELECT * FROM categories WHERE parent_id = 0");
   //start while 2
   while ($k_result = mysql_fetch_array($k_sql)){
   		$cat_id = $k_result['categories_id'];
	$cat_parent = $k_result['parent_id'];
	$cat_sort = $k_result['sort_order'];

	$kk_sql = mysql_query("SELECT categories_name FROM categories_description WHERE categories_id = $cat_id");
	while ($kk_result = mysql_fetch_array($kk_sql)){
	$cat_name = $kk_result['categories_name'];
	}
	?><li><a href="shop.php?cPath=<?php echo $cat_id; ?>"><?php echo $cat_name; ?></a></li>
        <?php
} // end while 2
$parents_cat_id = mysql_query("SELECT * FROM categories WHERE parent_id = ".$catpath)or die(mysql_error());
	   	$parents_cat_num = mysql_num_rows($parents_cat_id) or die(mysql_error());
	   	   //start while 3
		    while ($parent_c = mysql_fetch_array($parents_cat_id)){
			$new_parents_cat_id = $parent_c['categories_id'];
		$parent_cat_sql = mysql_query("SELECT * FROM categories_description WHERE categories_id = $new_parents_cat_id");
		if($parent_result > 0){	
		//start while 4	
		while ($p_c_s = mysql_fetch_array($parent_cat_sql)){
		$subcat_name = $p_c_s['categories_name']; 
		$subcat_id = $p_c_s['categories_id']; 
				echo '<span id="left_nav_sub"><li><a href="shop.php?cPath=' .$subcat_id . '">' .$subcat_name. '</a></li></span>';
		} // end while 4
		} else {
			//if block of code here
		}
		} // end while 3
		} // end while 1

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.