Logic Conundrum. [SOLVED]
Posted: Mon Jan 10, 2011 2:57 pm
Okay. Where to begin
I've thought/coded myself into a bit of a pickle here. Lets start with some pre-text.
I'm building a custom CMS that will enable users to create their own store fronts using my application. All data will be hosted on my server. I've coded the template engine and am working on the 'site settings' part of my application, basically where users control what goes where (every aspect of template is modular) and CSS styles.
I had originally coded it to only account for one CSS file for all pages, I have since re-thought that and made it two. The template engine opens up two CSS files with [%TAGS%] as value replacement place holders. One is style file is for global styles, like site colors, logo, etc... and the other is for local, per page, styles like column widths and spacings for that specific page. The site settings page should be composed of two parts then, global and local settings.
The database is normalized, so one table holds ALL of the placeholder tags with their respective id's, as such:
id, name
1, logo
2, body_color
3, left_width
and then another table holds all the value for said tags as such:
storeid, pageid, keyid, elementValue
1, 1, 1, image.png
1, 1, 2, #CCCCCC
1, 1, 3, 400px
keyid is the relative id for the placeholder tag from table 1.
The code that I originally wrote, which reads all the tags from table 1 and then vales from table 2 is this:
Then I use some JS to display the form fields nicely on the site settings page. The tricky part is keepings both the $keyNames array and $values array to have the same offsets, so that they match with a key/value pair. I know this is probably a horrible way to do this, but I don't know any better way. So some help here would be greatly appreciated.
If I continue on this tricky offset matching path, then the issue is that I need to separate the global style tags away from the local style tags. I'm not sure where the best place to do that would be, logically. I tried to code it into the top bit (query from keyNames) with no success, it just messes up my offset matching. And coding it into the bottom bit will most likely give me the same type of garbage.
I'm at my wit's end here.
I'm still very new to PHP, only about 3.5 months of real coding experience, so my logical/comp-sci thinking isn't as refined as it needs to be for an issue this complex. I hope what I wrote makes sense, it took me way to long to get these thoughts into words,
Thank you in advance.
I've thought/coded myself into a bit of a pickle here. Lets start with some pre-text.
I'm building a custom CMS that will enable users to create their own store fronts using my application. All data will be hosted on my server. I've coded the template engine and am working on the 'site settings' part of my application, basically where users control what goes where (every aspect of template is modular) and CSS styles.
I had originally coded it to only account for one CSS file for all pages, I have since re-thought that and made it two. The template engine opens up two CSS files with [%TAGS%] as value replacement place holders. One is style file is for global styles, like site colors, logo, etc... and the other is for local, per page, styles like column widths and spacings for that specific page. The site settings page should be composed of two parts then, global and local settings.
The database is normalized, so one table holds ALL of the placeholder tags with their respective id's, as such:
id, name
1, logo
2, body_color
3, left_width
and then another table holds all the value for said tags as such:
storeid, pageid, keyid, elementValue
1, 1, 1, image.png
1, 1, 2, #CCCCCC
1, 1, 3, 400px
keyid is the relative id for the placeholder tag from table 1.
The code that I originally wrote, which reads all the tags from table 1 and then vales from table 2 is this:
Code: Select all
//top bit
$query = mysql_query("SELECT id, name FROM keyNames") or die ("2 ".mysql_error());
$ki = 0;
$keyNames[] = '';
$keyid[] = '';
while($rowdata = mysql_fetch_array($query)) {
$keyid[$ki] = $rowdata[id];
$keyNames[$ki] = $rowdata[name];
$ki++;
}
// bottom bit
$keyCount = count($keyNames);
for ($i = 0; $i < $keyCount; $i++) {
$query = mysql_query("SELECT elementValue FROM sitesettings WHERE storeid='".$storeid."' AND keyid='".$keyid[$i]."' AND pageid='".$pageid."'") or die ("3 ".mysql_error());
$rowdata = mysql_fetch_array($query);
$values[$i] = $rowdata[elementValue];
}If I continue on this tricky offset matching path, then the issue is that I need to separate the global style tags away from the local style tags. I'm not sure where the best place to do that would be, logically. I tried to code it into the top bit (query from keyNames) with no success, it just messes up my offset matching. And coding it into the bottom bit will most likely give me the same type of garbage.
I'm at my wit's end here.
Thank you in advance.