Well, I'm sure I could have explained all that better.
I opted for the second choice, persevered, and have it up and running, so far so good. Now users can upload photos, files, links, news stories and contact details, and assign them to specific web-pages, via html/php forms in the back-end.
PHP code in the sidebar of the public pages selects any data assigned to the page and displays it with appropriate xhtml.
I'm now faced with another problem: the 'edit' pages - where users can change the data (eg, new phone number for a contact), and/or the web-pages assigned to it.
So this is an html/php form displaying the data already held in the database in editable fields (no problem there). Also all the available public webpages laid out in a grid of checkboxes (created by querying the 'pages' table on the database).
The problem is here: getting a 'checked' value added to the correct checkboxes, so users can see where data is already appearing.
This is the code that creates the checkbox layout:
PHP Code:
// 'pageID' is the autoincrementing index, 'tag' is a one word description
$query = " SELECT pageID, tag
FROM pages
ORDER BY pageID ASC";
$result = @mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
echo "
<span><input type='checkbox' name='tags[]' value='$row[0]'
class='checkbox' /> <label class='forcheckbox'>$row[1]</label></span>\n";
}
mysql_free_result( $result )
And this will select the webpages already chosen for the particular data, in this case, a link to an external webpage:
PHP Code:
/* 'support' table cross references the indices of the various data tables
with the index of the 'pages' table, and gives each association a 'supportID'
- $uid is the ID of the data being edited, passed in the url
(eg editLink.php?uid=19 */
$query = " SELECT page_id
FROM support
WHERE link_id=$uid";
I've tried combining the two with joins, but I either get too many checkboxes or too few, I'm thinking that this can't be done with joins. So now I'm trying to split the 2 parts up, and then bring them together. My idea was to insert a $status variable into the checkbox code and have it return either 'checked' or '', but I can't figure out how.
This is probably the nearest I got:
PHP Code:
// this one selects only the pages assigned to the data, but 'checks' them
$query = " SELECT pageID, tag, page_id
FROM pages
LEFT JOIN support
ON pages.pageID=support.page_id
WHERE support.link_id=$uid
ORDER BY pageID ASC";
$result = @mysql_query ($query);
while ($row = mysql_fetch_array ($result, MYSQL_NUM)) {
if ($row[2] != $row[0]) {
$status = ''; }
else { $status = 'checked'; }
echo "
<span><input type='checkbox' name='tags[]' value='$row[0]' class='checkbox'
$status /> <label class='forcheckbox'>$row[1]</label></span>\n";
}
mysql_free_result( $result )
Any ideas? In short, I'm lookin for a checkbox list of all pages, with the appropriate ones already checked.
Bookmarks