Solved

How to display a functions data inside HEREDOC

Posted on 2016-11-27
2
33 Views
Last Modified: 2016-11-27
I am populating a dropdown with database records without using HEREDOC but I now want to do it with HEREDOC. Is is possible to edit this to display the contents of the function query or not? I assume I should remove the PHP tags from inside the HEREDOC but I just left them there so you can see the actual HTML.

$showData = <<<SHOWDATA

<div class="form-group">
<label>Select Categories</label>
<select multiple data-title="Multiple Select" name="cat_name" class="selectpicker" data-style="btn-info btn-fill btn-block" data-menu-style="dropdown-blue">
<?php list_categories_multiple($link); ?>
</select>
</div>	
SHOWDATA;
echo $showData;

Open in new window

0
Comment
Question by:Black Sulfur
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 350 total points
ID: 41903013
You can't: HEREDOC manages only variables. But you can do this:
$showData = <<<SHOWDATA
<div class="form-group">
<label>Select Categories</label>
<select multiple data-title="Multiple Select" name="cat_name" class="selectpicker" data-style="btn-info btn-fill btn-block" data-menu-style="dropdown-blue">
SHOWDATA;
$showData .= list_categories_multiple($link);
$showData .= <<<SHOWDATA
</select>
</div>	
SHOWDATA;
echo $showData;

Open in new window

1
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 150 total points
ID: 41903027
A smart design would create all of your variables in a PHP object instance of StdClass or your own preferred object, and then inject the variables into the HTML via the HEREDOC.  If you have a function that creates HTML statements and you need these injected into the output HTML document, you might want to consider redesigning the application using a Separation of Concerns.

A HEREDOC is just another way of writing a string variable as if you had double quotes.  
http://php.net/manual/en/language.types.string.php
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
calculated column 12 74
test if query has no results 2 19
PHP warning 4 30
how to use a function in heredoc 5 23
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
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 …

895 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now