Glenskie Posted April 9, 2014 Share Posted April 9, 2014 im trying to check if the account is = to c but its erroring out and displays a blank page. $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root"> '. if ($account == "c") { .' <li> <a href="/stats.php">Dashboard</a> </li> '. } .' Quote Link to comment Share on other sites More sharing options...
Solution gizmola Posted April 9, 2014 Solution Share Posted April 9, 2014 You can't concatenate a logical block onto a string. Instead, you should end your string, then evaluate the block and append to the string as needed. $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root">'; if ($account == "c") { $user .= '<li> <a href="/stats.php">Dashboard</a> </li>'; } Please look into templating, even if that is simply via includes, as well as alternative PHP syntax. PHP already allows you to intermingle PHP and HTML, and with heavy HTML like this, the approach you are taking is difficult to read and maintain. Quote Link to comment Share on other sites More sharing options...
X5HOST Posted April 9, 2014 Share Posted April 9, 2014 Hi Glenskie, It looks like you're trying to add an 'if' statement whilst declaring a variable, this will return an error (or blank page with errors in the log). I would recommend the following: if ($account == 'c') { $variable = ' <li> <a href="/stats.php">Dashboard</a> </li>'; } else { $variable = ''; } $user = '<script type="text/javascript" src="'.$actual_link.'/js/submenu.js"></script><div class="dropdown"> <a class="account" > <span>'.$username.'</span> </a> <div class="submenu" style="display: none; "> <ul class="root"> '.$variable ; Kind Regards, Jason Moore 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.