This will take some explaining so please bear with me...
To begin with there is a form that allows the user to post new information/articles to the public end of a website. Part of the form has a "Post to" section which allows the user to post a single bit of information to multiple parts or sections of a website.
This part of the form has two checkboxes, namely "Home" and "Gaming". So for arguments sake we had an article with the title "MS unifies Windows and Xbox gamers online" the user might want to post that information to both the "Home" and "Gaming" sections of the site, so they decide to tick both the checkboxes.
The structure of each checkbox looks like so:
Upon submitting, each checkbox that is ticked, has its value inserted into the table responsible for retrieving the information/article from the database. If both are checked then obviously two records are made and either one depending on its Post To value is displayed on the corresponding section of the site. This works fine, the problem comes when retrieving the information from the database when the user (any admins) needs to edit the entry.Code:The variables are had from records held in a "post Location" table which holds the information on what parts of the site the user can post information to e.g below: $postId could be "1" $postLocation could be "Home" <input type=\"checkbox\" name=\"postTo[]\" value=\"$postId\" />$postLocation
What I want to happen is when the information/article is chosen to be edited the user sees what "Post To" checkboxes are currently ticked. The idea is that if the user made the mistake of posting information to the gaming section of a site instead of the home page they can go in, un-tick the gaming checkbox and update record and then that record will no longer be viewable via the gaming section of the site.
What I can't do 100% successfully is retrieve the data from the database and show what checkboxes are ticked. I can semi do it but not 100%. I have tried all sorts over the last week to get this working but I can't find a solution to it.
Below is the pure and simple crux of what I am trying to do. I know it does not work, is lacking security anderror capture features or any proper working structure, it is just to show you what it is I am trying to do.
The part that does the business of doing what I want to do:Code:TABLE STRUCTURE: -------------------------------- Table: post_to_tab ptd_id : ptd_location 1 : Home 2 : Gaming -------------------------------- Table: articleData_tab postTo_id : article_id 1 : 23 2 : 23 -------------------------------- Note: the article_id corresponds to the id of the actual textual information which is stored in another table which in this scenario is not important. There are other fields in the articleData_tab, but I am concentrating on the relevant parts.
I know it's a lot to take in and understand someone elses work, but I was just wondering if any of you knew what it was I was trying to do and if you could guide me in the right direction. I appreciate any efforts towards reading and giving input on this problem I seem to have.Code:$aId = $_GET['aId'] //e.g. page.php?aId=23 $getPostToData = @mysql_query("SELECT ptd_id, ptd_location FROM post_to_tab") $getArticleData = @mysql_query("postTo_id FROM articleData_tab WHERE article_id='$aId'") while ($foundPTD = mysql_fetch_array($getPostToData) && $foundGAD = mysql_fetch_array($getArticleData)) { $ptd_id = $foundPTD['ptd_id']; $ptd_loc = $foundPTD['ptd_location']; $postTo_id = $foundGAD['postTo_id']; if($ptd_id == $postTo_id) { echo "<input type=\"checkbox\" name=\"postTo[]\" value=\"$postTo_id\" checked="checked\" />$ptd_loc\n"; } else { echo "<input type=\"checkbox\" name=\"postTo[]\" value=\"$postTo_id\" />$ptd_loc\n"; } }


LinkBack URL
About LinkBacks
Reply With Quote
