Re: mixing HTML and PHP code

From: Date: Sat, 13 Jan 2001 22:07:04 +0000
Subject: Re: mixing HTML and PHP code
References: 1 2 3 4 5 6  Groups: php.general 
Request: Send a blank email to php-general+get-34414@lists.php.net to get a copy of this message
"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): ------------ <? 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. -- _ Iván Sánchez Ortega "MR" /|/| |_> (eme)(erre)(punto)(arroba)wanadoo.es / | | | \ / | \ No, mamá, no toques ese cab#@@%%## [NO CARRIER]

« previous php.general (#34414) next »