Hello, I have this link code: <a href="<?php if($row->pagetitle=="") { echo $this->config->item('url').'widget/edit/'.$row->widgetid; } else { echo $this->config->item('url').'widget/edit2/'.$row->widgetid; } ?>"><img src="<?php print $this->config->item('url').'images/edit.png'; ?>"/></a> Code (markup): "widgetid" is defined earlier, I basically need a php code that can check the database and to check in a certain table in the row of the defined widgetid for a value in another column, let's call it ZXC, whether the value in that row in that column is 1 or null, if 1 show the above script, if null hide it. I hope I've made it rather clear, tell me if you need more info and please help me out. Thanks!!
This should work: <?php if($row->ZXC==1) { ?> <a href="<?php if($row->pagetitle=="") { echo $this->config->item('url').'widget/edit/'.$row->widgetid; } else { echo $this->config->item('url').'widget/edit2/'.$row->widgetid; } ?>"><img src="<?php print $this->config->item('url').'images/edit.png'; ?>"/></a> <?php } ?> PHP:
1) it's stupid to be opening and closing PHP so much for no good reason. 2) 90% of the output results inside the IF are the same, so they don't belong inside a conditional. If the only thing different between the two conditons is 'edit' vs. 'edit2' -- those should be the only things inside that condition. 3) It's usually better to check for empty instead of =='' 4) if you're gonna have null as one of the conditions, test for isset so it's not tossing a warning in your logs. <?php if (isset($row->ZXC)) { echo ' <a href="',$this->config->item('url'),'widget/',( empty($row->pagetitle) ? 'edit/' : 'edit2/' ),$row->widgetid,'"> <img src="',$this->config->item('url'),'images/edit.png" alt="edit" /> </a>'; } ?> Code (markup): Outer if for the new var seeing if it's not-null, single echo statement handling the ENTIRE output with no dipping in and out of PHP like a script-tard, delimited echo instead of string additions, evaluation instead of an if statement inside the output with the only thing the output changing being the parts that are ACTUALLY different.