Re: mixing HTML and PHP code

From: Date: Mon, 15 Jan 2001 01:13:41 +0000
Subject: Re: mixing HTML and PHP code
References: 1 2 3 4 5 6 7  Groups: php.general 
Request: Send a blank email to php-general+get-34526@lists.php.net to get a copy of this message
the horse is back from the dead! I can't resist: > From: IvanSanchez@wanadoo.es ("Iván Sánchez Ortega \"MR\"") > Newsgroups: php.general > Date: 13 Jan 2001 14:17:35 -0800 > Subject: Re: [PHP] mixing HTML and PHP code > > "Alex Black" ... >>> <? >>> connect_to_database(); >>> parse_query(); >>> execute_query(); >>> >>> echo "<TABLE>"; >>> >>> while (fetch_row_from_query()) >>> { >>> $output = data_from_fetched_row(); >>> $more_output = more_data_from_fetched_row(); >>> >>> echo "<TR><TD> $output </TD><TD> $more_output >>> </TD></TR>"; >>> >>> } >>> echo "</TABLE>"; >>> ?> >> >> Well, this may be a bit specific, but that is probably part of your > problem. >> You have no structure associated with your application design: >> >> what are you doing making a connection to a database on the same page you >> spit out the results from? > > Nonononono... that was just an example. My real code looks more like this > example: > > ------------- > <? > include "common_head.php"; > > echo "<SPAN CLASS='title'>Welcome to blah blah section</SPAN>"; > > echo > "<TABLE><TR><TD>Name</TD><TD>Email</TD></TR>"; > > $query=ociparse($conection,"select name,email from people where blah blah > blah"); > ociexecute($query); > while (ocifetch($query)) > { > $name=ociresult($query,"NAME"); > $email=ociresult($query,"EMAIL"); > > echo "<TR><TD>$name</TD><TD>$email</TD></TR>"; > > } > > ocifreecursor($query); // optional > > > include "common_footer.php"; > ?> > -------------- > > > In common_head.php i have the conect-to-database functions, and because the > way include() works, i can happily use $connection in the main code. It also > makes a login&password comprobation, getting data from cookies and the > stuff. > common_head.php also has a main component: the UPPER WEB DESIGN. That means > that the upper logo, left-side menus, CSS links, common javascript code and > stuff is also stored there. > > common_footer just has the bottom part of the design - bottom common links, > and lots of well measured </TABLE> closings. > > The trick is tell the web designer to work the main common design in > dreamweaver or so, then pick the HTML code, and separate it in "upper" and > "bottom"... in the middle of that you have the space to put whatever you are > spitting out from the DB. > > And aside from that, i don't have a one and only common_head.php ... i have > a separate plain common head, in plain HTML... the real common_head.php > should look like (definitively not real PHP sintax): right, and though this is not directly related to templating: I thik you would benefit greatly by introducing some system design (i.e. separate "layers" doing separate tasks) I don't like to do database connections when I've already output markup, what if something goes wrong, or I want to do a redirect, etc? I like to access functions in "DB Object" files - those functions return results in arrays which I can pass into markup. Makes the code a _helluvuh_ lot more maintainable. > ------------ > <? > connect_to_database(); > do_cookie_stuff(); // First of spitting any HTML, > // you get from cookies, make comprobations, > // and re-store cookies or whatever... > // This do_cookie_stuff can be a little hard. > > include "plain_html_head.php"; > ?> > ---------------- > > > That way, your dreamweaver expert can design the main design (better with > some stupid test text in the place of the spitted-out-from-database-data), > and you as PHPer only have to cut out the HTML code (not a really hard work) > into two parts. > > As i see, it can work perfectly this way. > > > How you format the spitted data and stuff is another matter.... but anyway, > getting the code that dreamweaver generates and implementing it shouldn't be > a real hard task. True, but why not just bitch at macromedia until they include support for PHP in ultradev? (plegh, visual authoring tools: a necessary evil) :) _a

« previous php.general (#34526) next »