Solved

I'm getting a conflict on inline styles with php.

Posted on 2011-03-11
6
252 Views
Last Modified: 2012-05-11
I have a script that parses some db data and creates nested lists for a side menu. One function adds each list item to an output variable. When I include an inline style I cannot get the variable written to the screen - don't know if variable is just not created or it's not written. If I don't include the inline style, it writes to the screen just fine.

Here's the function without the inline style. This adds to the variable fine and writes to the screen fine:

function add_nav_level($key,$val,$level_nbr, $end){
	global $id_nbrs;
	//ADD EACH OF THIS LEVEL TO THE OUTPUT
	$id_name = "ul_id" . $key;	  
   	$output = "<li><a href='#' class='sub_nav' onClick=\"javascript:jchangeY('" . $id_name . "');\">". $val . "</a>";
	$id_nbrs[$level_nbr][] = $id_name;
	if ($level_nbr < $end){
		$dis_style = "style='display:none;'";
		$output .= "<ul id='" . $id_name ."'>";
		}
	else{
		$output .= "</li>";
		}
	return $output;
	}

Open in new window


And the below code is the same function with the inline style inserted. This will not write to the screen:

function add_nav_level($key,$val,$level_nbr, $end){
	global $id_nbrs;
	//ADD EACH OF THIS LEVEL TO THE OUTPUT
	$id_name = "ul_id" . $key;	  
   	$output = "<li><a href='#' class='sub_nav' onClick=\"javascript:jchangeY('" . $id_name . "');\">". $val . "</a>";
	$id_nbrs[$level_nbr][] = $id_name;
	if ($level_nbr < $end){
		$dis_style = "style='display:none;'";
		$output .= "<ul id='" . $id_name ."' style='display:none;'>";
		}
	else{
		$output .= "</li>";
		}
	return $output;
	}

Open in new window


Any clue what the conflict is and how I can get around it?

denewey
0
Comment
Question by:denewey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 5

Expert Comment

by:wmadrid1
ID: 35113348
Wat do you mean wit "inline style"?

wit the line  
$output .= "<ul id='" . $id_name ."' style='display:none;'>";

style='display:none;'
make that nothing been printed to screen
try changing it to:

$output .= "<ul id='" . $id_name ."' style='display:inline;'>";
0
 

Author Comment

by:denewey
ID: 35113472
I don't want anything to be displayed. I want it to be not displayed so that later with a javaScript function I can display it.  But it should be viewable when I view source, and it isn't.

The issue is that when I include that in the output variable, the content of the variable disappears. It's not viewable in source or anywhere.
0
 
LVL 3

Expert Comment

by:designsevolved
ID: 35113606
I tried it and your function works correctly for me.

However, I would switch your single and double quotes around. Double quotes always cause trouble because they interpret some of the php within them. I would only use double quotes when you have to for the desired effect. In your case there is no need. Switch them to make sure there isn't any conflict like this:

function add_nav_level($key,$val,$level_nbr, $end){
	global $id_nbrs;
	//ADD EACH OF THIS LEVEL TO THE OUTPUT
	$id_name = 'ul_id' . $key;	  
   	$output = '<li><a href="#" class="sub_nav" onClick="javascript:jchangeY(\'' . $id_name . '\');">'. $val . '</a>';
	$id_nbrs[$level_nbr][] = $id_name;
	if ($level_nbr < $end){
		$dis_style = 'style="display:none;"';
		$output .= '<ul id="' . $id_name .'" style="display:none;">';
		}
	else{
		$output .= '</li>';
		}
	return $output;
	}

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:denewey
ID: 35113731
Thank you.

It was a problem at work and I won't be back there until Monday, so I'll let you know then if that works for me.
0
 

Accepted Solution

by:
denewey earned 0 total points
ID: 35153346
Although I thank designsevolved for his answer, it didn't resolve the matter, but his reply made me realize the problem was somewhere else (because he said it worked fine for him). Adding that piece of code made the string to long for another piece of code which caused the string to be emptied. So the matter is resolved.

thank you
0
 

Author Closing Comment

by:denewey
ID: 35178867
The problem was in another piece of the code that was not submitted with the original submission.
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
In this Micro Tutorial viewers will learn how to create a CSS image sprite (In a later tutorial, viewers will learn how to use CSS and HTML to create a navigation menu using this sprite) Open a new Photoshop document with a width of (Icon width)x(N…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question