Separating Html From Content.

liunx

Guest
I'm creating a site which I plan to be database driven in that all of the information pages will be pulled from mySQL. My thing is that I don't want to have to go into the HTML to edit things everytime I want to add a field to a page. <br /><br />What I'm doing a the moment is using three tables (well, three table types). One is a list of all of the pages on the site. One is a list of fields for the site (so that I can bring up field headers instead of having to use the column's name, which is usually cryptic). The last is the information page. Every page has it's own table like this last one. It is simply all of the info for the page (ie, the member table just has all of the member info for the member page on it).<br /><br />Here's how I'm using it (sorry if this is convoluted, I'll try to edit out the unimportant stuff, like the error checking)<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$rs2 = @mysql_query('SELECT * FROM '.$fieldtable.' WHERE page_id = '.$pageid); <br /><br />$i = 0;<br />while ($collist = mysql_fetch_array($rs2)) {<br /> ??#036;fielddesc[$i] = $collist['fieldtitle']; ?br /> ??#036;colname[$i] = $collist['col_name']; ?br /> ??#036;i++;<br />}<br /> ?br />$resultsMember = @mysql_query('SELECT * FROM ' .$membertable . ' WHERE id=\''.$id.'\''); ?????????????br />    <br />$memberInfo = mysql_fetch_array($resultsMember);<br />$num_columns = count($fielddesc);<br /><br />$strMember = '';<br /><br />$i = 0; //counter<br /><br />while ( $i < $num_columns ){<br /> ??#036;strMember .= $fielddesc[$i].' &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' .$memberInfo[$colname[$i]].'';<br />$strMember .= '<br />';<br /><br />$i++;<br />}<br />echo $strMember;<!--c2--></div><!--ec2--><br />Basically, what I'm doing is pulling the field titles that I want to appear to the enduser from the fields table. I'm then showing the memberInfo from that column. This works fine, but it's terrible for formatting. Is there a way to control formatting decently while keeping it generic?? Right now, the only way I see to control formatting for each field is to have something like if($memberInfo[$colname[$i]] == 'name'), then format the name a certain way. But that means I have to hardcode the name field. <br /><br />How do you guys handle keeping what is displayed separate from how you display it, or can it even be done like I want??<br /><br />*edit* <br />Example time. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> Here's the page I'm currently playing with (uses the code above). h**p://bohicagaming.com/staff/memberform/members.php?id=4<br /><br />See how it's all one long list of stuff? What I'd like to do is format the list so that the contact info, let's say, is separated or formatted differently from the rest so it stands out. I'm looking for a way to do this without having to hardcode those fields into the code. I really am not sure what I want can be done (or that I'm explaining it very well at all). I want to be able to use a form to edit this page later without having to touch the code basically. So what I'm looking for here is programming/database/design structure concepts as opposed to the code itself. Does that make any sense??<!--content-->
If I understand you correctly, then you are looking to have both the content and design driven off a database.<br /><br />Two suggestions: one would be to name your CSS styles the same as the field values in your one table so that when you are creating the table, it's a simple matter of adding a bit of code in the mix that says something like<br /><br />echo '<td class = ." . $memberInfo[$colname[$i]] . ">$memberInfo[$colname[$i]]</td>';<br /><br />I'm not sure if I formatted the above line correctly, but the concept is to use css names that match the field names in your table. The rest is done on it's own.<br /><br />The second way is a bit more involved and would require you to have a database table matching field values to css classes (or attributes, id, whatever) and throwing in extra code to match them up. Then, you modify the values in your table, rather than messing with html.<br /><br />Frankly, I like the first idea better, and I hadn't really thought of it until you asked this question. I plan to use it soon.<!--content-->
This is why I like this place. It never even crossed my mind to match the css classes with a table. That rocks. Now I just need a year to figure out all of this and how it should be coded. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/goof.gif" style="vertical-align:middle" emoid=":goof:" border="0" alt="goof.gif" /><!--content-->
 
Back
Top