Jump to content

Something wrong with my code.


Glenskie
Go to solution Solved by gizmola,

Recommended Posts

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>
'. } .'
Link to comment
Share on other sites

  • Solution

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.
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.