kyleldi Posted April 10, 2009 Share Posted April 10, 2009 I don't know if this is even possible, and my many searches don't provide me with what i'm looking to find- but is it possible to essentially nest an IF statement inside another? Here's what i'm trying to do... I've got an IF statement that displays items based on the url variables 'category' and 'sub'. If a category exists, this code is initiated, showing the subcategories of that category. if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } The problem is, some categories don't have subcategories, and I want those categories to initiate a different code. Essentially I want to make it look for something in 'sub' before it displays the above code, and if there's nothing there, it displays this: echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); } Is this possible? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 You can nest if() to silly levels - just make sure you close them in the right order or it can get messy debugging. Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 At the risk of sounding totally ignorant, where would I start? I guess that's probably my biggest downfall right now. The recordset is pulling all necessary information to make the query, I just don't know how to write it up properly. Thank you! Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 Try and think it (the flow) through logically - draw on paper if thinking about it is a little tricky. I take it you want to perform that check inside that do() loop and show that bottom piece of code instead if the item in the loop doesn't have a subcategory? Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 Yes, it can actually check for a subcategory after the category is selected, and at that time it decides whether subcategories are to be displayed or to skip it. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 Something like this what you mean? if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { if (subcategoryexists) { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } else { echo 'no subcategory code here'; } } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 My code: if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } else { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //// This is the error line. } The error I'm getting is Parse error: syntax error, unexpected '}', expecting T_WHILE Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 That just means you've got a bracket in the wrong place - in this case one too early. You're closing the loop and not supplying the while part. After formatting it seems you're missing a second while part... if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } else { //2 echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //// This is the error line. } //2 } WHILE ***MISSING FROM HERE*** //1 } Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 I think this is what you may be looking for. if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { //2 echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } else { //2 //3 echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } //3 } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //1 } Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 Getting the same error, this time on a different line. Here's my entire code.. it's supposed to do one of three things. The last else is if no url variable is passed, the first if two variables, and the second checks for the subcategory. <?php if(isset($_GET['category']) && isset($_GET['sub'])){ echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); } else if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_cats['itemid'].'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_cats['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } else { //2 //3 echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } //3 } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //1 } else { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 Indenting your code is one of the best things you can do - makes debugging a whole lot easier. After I reformatted the code the error stood out a mile - try this: <?php if (isset($_GET['category']) && isset($_GET['sub'])) { echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); } else { if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_cats['itemid'].'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_cats['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } else { //2 //3 echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } //3 } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //1 } else { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } } ?> Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 It seems I had the wrong code pasted before, for one of my queries was messed up. I fixed it in your code and I still get an } parse error in the line below... <?php if(isset($_GET['category']) && isset($_GET['sub'])){ echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); } else if(isset($_GET['category'])){ echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_categories['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_categories['itemid'].'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_categories['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } else { //2 //3 echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } //3 } while ($row_rs_categories = mysql_fetch_assoc($rs_categories)); //1 } else { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //// This line fails } ?> Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 INDENT INDENT INDENT!!! <?php if(isset($_GET['category']) && isset($_GET['sub'])){ echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); } else { if (isset($_GET['category'])) { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_categories['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_categories['itemid'].'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_categories['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } else { //2 //3 echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } //3 } while ($row_rs_categories = mysql_fetch_assoc($rs_categories)); //1 } } else { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); //// This line fails } ?> Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 Sorry to be so frustrating :-\ Parse error: syntax error, unexpected T_ELSE longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } //3 } while ($row_rs_categories = mysql_fetch_assoc($rs_categories)); //1 } } else { /// Error is here. echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 You've got a double "else" there - take a look at the code and see where it needs to be edited. Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 The three "else" statements have to be there in order for the script to do one of three things, no? The first one checks for a subcat and echos what doesn't have a subcategory, the second echos what does, and the third displays the categories (all) when no category has been submitted via the url. Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 Would it be better to put an ISSET "" to tell the script the url variable is blank? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 Sorry for absence - went downstairs for a sandwich! All I'm saying is that the if() structure is malformed and you need to restructure it for it to work. You can't have: if (condition) { //something } else { //something } else { //something } If you need a structure like that you'll need to change an "else" into an "else if" with another condition: if (condition) { //something } else if (condition) { //something } else { //something } If you have a lot of conditions based on the same variable you can use switch() in place instead. Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 <?php if(isset($_GET['category']) && isset($_GET['sub'])){ echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); // User submits category & subcategory } else { if (isset($_GET['category'])) { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_categories['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_categories['itemid'].'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_categories['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } else { //2 //3 echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } while ($row_rs_categories = mysql_fetch_assoc($rs_categories)); //1 } } else { if ($row_rs_categories['sub']=='') { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } ?> Something like this? Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 You've still got two else's in there - I've marked them. I can't rewrite it for you because I don't know what you're trying to do <?php if(isset($_GET['category']) && isset($_GET['sub'])){ echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); // User submits category & subcategory } else { //1ST ELSE if (isset($_GET['category'])) { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_categories['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_categories['itemid'].'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_categories['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } else { //2 //3 echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } while ($row_rs_categories = mysql_fetch_assoc($rs_categories)); //1 } } else { //2ND ELSE if ($row_rs_categories['sub']=='') { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } ?> Quote Link to comment Share on other sites More sharing options...
kyleldi Posted April 10, 2009 Author Share Posted April 10, 2009 <?php if(isset($_GET['category']) && isset($_GET['sub'])){ echo '<h1><span class="red_upcap">'.ucwords($row_rs_subcategories['category']).' > '.ucwords($row_rs_subcategories['sub']).'</h1>'; do { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'"><img src="store/thumbs/'.$row_rs_subcategories['img_t'].'" alt="'.ucwords($row_rs_subcategories['category']).'" width="'.$row_rs_subcategories['img_t_x'].'" height="'.$row_rs_subcategories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_subcategories['itemid'].'" /></a></div>'; } while ($row_rs_subcategories = mysql_fetch_assoc($rs_subcategories)); // User submits category & subcategory } else if (isset($_GET['category'])) { echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_categories['category']).'</h1>' ; do { //1 if ($row_rs_categories['sub']=='N/A') { echo '<div class="categories"><a href="itemdetail.php?itemid='.$row_rs_categories['itemid'].'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="itemdetail.php?itemid='.$row_rs_categories['itemid'].'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } else { //2 //3 echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'"><img src="store/thumbs/'.$row_rs_categories['img_t'].'" alt="'.ucwords($row_rs_categories['category']).'" width="'.$row_rs_categories['img_t_x'].'" height="'.$row_rs_categories['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_categories['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_categories['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_categories['category']).'&sub='.str_replace(" ","+",$row_rs_categories['sub']).'">'.ucwords($row_rs_categories['sub']).'</a></div>'; } while ($row_rs_categories = mysql_fetch_assoc($rs_categories)); //1 } } else { //2ND ELSE echo '<h1><span class="red_upcap">C</span>ategory: '.ucwords($row_rs_cats['category']).'</h1>' ; do { echo '<div class="categories"><a href="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'"><img src="store/thumbs/'.$row_rs_cats['img_t'].'" alt="'.ucwords($row_rs_cats['category']).'" width="'.$row_rs_cats['img_t_x'].'" height="'.$row_rs_cats['img_t_y'].'" border="0" longdesc="store.php?category='.str_replace(" ","+",strtolower($row_rs_cats['category'])).'&sub='.str_replace(" ","+",strtolower($row_rs_cats['sub'])).'" /></a><br /> <a href="store.php?category='.str_replace(" ","+",$row_rs_cats['category']).'&sub='.str_replace(" ","+",$row_rs_cats['sub']).'">'.ucwords($row_rs_cats['sub']).'</a></div>'; } while ($row_rs_cats = mysql_fetch_assoc($rs_cats)); } ?> This matches your syntax above, correct? Yet I still get the same parse error. All i'm trying to do is let this page load the content based on the url variable. If the variable exists it does the first check for category and sub, if it doesn't find that it looks for just category, where it checks to see if there is anything in the 'sub' column. If there is, it outputs a picture w/ a hyperlink that includes the sub as a variable, if there's no sub in the column, it's supposed to output a picture w/ a hyperlink to the picture's details. Quote Link to comment Share on other sites More sharing options...
Yesideez Posted April 10, 2009 Share Posted April 10, 2009 Please, watch what brackets are being matched! I'm very sorry but it's late here and I'm going to have to let someone else take over. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.