Hi folks,
can someone help me understand the meaning behind this snippet of
code:
$result = mysql_query('SELECT category_id,category_name FROM
gallery_category');
while($row = mysql_fetch_array($result)) {
$photo_category_list .= <<<__HTML_END
<option value="$row[0]">$row[1]</option>\n
__HTML_END;
}
I start to get confuse when the .=<<<_HTML_END bit start, how does
this work? I don't understand.
Thanks 7 1365
"dangerd" <du**********@breathe.comwrote in message
news:11*********************@n59g2000hsh.googlegro ups.com...
| Hi folks,
|
| can someone help me understand the meaning behind this snippet of
| code:
|
| $result = mysql_query('SELECT category_id,category_name FROM
| gallery_category');
| while($row = mysql_fetch_array($result)) {
| $photo_category_list .= <<<__HTML_END
| <option value="$row[0]">$row[1]</option>\n
| __HTML_END;
| }
|
| I start to get confuse when the .=<<<_HTML_END bit start, how does
| this work? I don't understand.
|
| Thanks
it's called a heredoc. i hate them, but others love them. essentially you
are breaking out of php code so that what is contained inbetween <<<__TAG
and __TAG can be written as if it were literal text. it is much more clear
to me to do:
$photo_category_list .= '<option value="' . $row[0] . '">' .
$row[1] .
"</option>\n";
but that's just me.
btw, wouldn't it make much more sense to make $row be $columns since the key
of the array points to a column/field and not a row of data?
On Apr 16, 11:47 am, "Steve" <no....@example.comwrote:
"dangerd" <duncanell...@breathe.comwrote in message
| I start to get confuse when the .=<<<_HTML_END bit start, how does
| this work? I don't understand.
|
| Thanks
it's called a heredoc.
Language reference for heredoc can be found here: http://us.php.net/manual/en/language...syntax.heredoc
In message <nS***********@newsfe04.lga>, Steve <no****@example.com>
writes
>"dangerd" <du**********@breathe.comwrote in message news:11*********************@n59g2000hsh.googlegr oups.com... | Hi folks, | | can someone help me understand the meaning behind this snippet of | code: | | $result = mysql_query('SELECT category_id,category_name FROM | gallery_category'); | while($row = mysql_fetch_array($result)) { | $photo_category_list .= <<<__HTML_END | <option value="$row[0]">$row[1]</option>\n | __HTML_END; | } | | I start to get confuse when the .=<<<_HTML_END bit start, how does | this work? I don't understand. | | Thanks
it's called a heredoc. i hate them, but others love them. essentially you are breaking out of php code so that what is contained inbetween <<<__TAG and __TAG can be written as if it were literal text. it is much more clear to me to do:
$photo_category_list .= '<option value="' . $row[0] . '">' .
$row[1] .
"</option>\n";
but that's just me.
btw, wouldn't it make much more sense to make $row be $columns since the key of the array points to a column/field and not a row of data?
Better still
$photo_category_list .= '<option value="' .
$row['category_id'] . '">' .
$row['category_name'] .
'</option>\n";
--
Steve Wright
| >btw, wouldn't it make much more sense to make $row be $columns since the
key
| >of the array points to a column/field and not a row of data?
| >
| >
| Better still
|
| $photo_category_list .= '<option value="' .
| $row['category_id'] . '">' .
| $row['category_name'] .
| '</option>\n";
|
optimally:
$photo_category_list .= '<option value="' .
$row['category_id'] .
'">' .
$row['category_name'] .
'</option>\n";
:)
"Steve" <no****@example.comwrote:
> btw, wouldn't it make much more sense to make $row be $columns since the key of the array points to a column/field and not a row of data?
That's an interesting question. mysql_fetch_array returns one "row" at a
time. But, even though the "thing" is one row of a database query, what
the thing contains are columns.
Personally, I always use $row, but I see your point.
--
Tim Roberts, ti**@probo.com
Providenza & Boekelheide, Inc.
Steve wrote:
optimally:
$photo_category_list .= '<option value="' .
$row['category_id'] .
'">' .
$row['category_name'] .
'</option>\n";
better still:
$photo_category_list = sprintf( '<option value="%s">%s</option>'."\n",
htmlentities($row['category_id']),
htmlentities($row['category_name'])
);
--
Toby A Inkster BSc (Hons) ARCS http://tobyinkster.co.uk/
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
"Toby A Inkster" <us**********@tobyinkster.co.ukwrote in message
news:ja************@ophelia.g5n.co.uk...
| Steve wrote:
|
| optimally:
| >
| $photo_category_list .= '<option value="' .
| $row['category_id'] .
| '">' .
| $row['category_name'] .
| '</option>\n";
|
|
| better still:
|
| $photo_category_list = sprintf( '<option value="%s">%s</option>'."\n",
| htmlentities($row['category_id']),
| htmlentities($row['category_name'])
| );
ok, you win. i actually think that is much more consice as you can see what
it is that you're after and how/where each input is used. i'll make note of
that.
:) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dhruva Hein |
last post by:
Hi. I am trying to understand a section of code written for Plone and I
am having problems understanding the Python syntax in a few of the
following lines.
I'd be grateful if someone could help...
|
by: What-a-Tool |
last post by:
Dim MyMsg
Set MyMsg = server.createObject("Scripting.Dictionary")
MyMsg.Add "KeyVal1", "My Message1"
MyMsg.Add "KeyVal2", "My Message2"
MyMsg.Add "KeyVal3", "My Message3"
for i = 1 To...
|
by: Beringer |
last post by:
I am trying to access some functionality of the underlying RichTextBox
control and am getting all mixed up with conversions of types. I know my
basic issue is not completely understanding...
|
by: Bail |
last post by:
I will have a exam on the oncoming friday, my professor told us that it
will base upon this program. i am having troubles understanding this
program, for example what if i want to add all the...
|
by: varkey.mathew |
last post by:
Dear all,
Bear with me, a poor newbie(atleast in AD)..
I have to authenticate a user ID and password for a user as a valid
Active Directory user or not. I have created the IsAuthenticated...
|
by: abico |
last post by:
Write a program that reads in a sequence of words and prints them in
reverse order.Using STACK.
|
by: drec |
last post by:
I am just learning Javascript and I would like to create a basic form
that gives me two options. This will be using either checkbox or radio
input type, however I would like the second option to...
|
by: gunimpi |
last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431
********************************************************
VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help
wanted...
|
by: souporpower |
last post by:
Hello All
I am trying to activate a link using Jquery. Here is my code;
<html>
<head>
<script type="text/javascript" src="../../resources/js/
jquery-1.2.6.js"</script>
<script...
|
by: Damien87 |
last post by:
Hi,
I have a .data file which is essentially just a text file with a bunch of numbers.
It's in the format "xx yy zzz abc
ccf fffd sss xxx
xx sss qq"
Basically it is a random amount of numbers...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |