Xtremer360 Posted April 14, 2011 Share Posted April 14, 2011 What I'm trying to figure out how to do is when its getting the content for the field it needs to get the ID of the field that way it can get the content of the field. I'm not sure what I'm doing wrong. <?php require ('php/bios.php'); ?> <script type="text/javascript" src="forms/edit/js/bios.js"></script> <!-- Title --> <div id="title" class="b2"> <h2>Character Management</h2> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <form action="#" id="bioForm" > <?php while ($row = mysqli_fetch_array($groupsResult, MYSQL_ASSOC)) { echo "<fieldset> <legend>" . $row['groupName'] . "</legend>"; $fieldsResult = mysqli_query ( $dbc, sprintf($fieldsQuery,$row['ID']) ); while ($row2 = mysqli_fetch_array($fieldsResult, MYSQL_ASSOC)) { echo "<div class=field required>"; if ($row2['inputType'] == "text") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<input type=text name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=text biofield title=" . $row2['fullName'] . " />"; } elseif ($row2['inputType'] == "textarea") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<textarea name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=textarea biofield title=" . $row2['fullName'] . " />"; } else { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=dropdown biofield title=" . $row2['fullName'] . " >"; echo "<option value= >None</option>"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; } $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ($charactersResult, MYSQLI_ASSOC)) { echo "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } echo "</select>"; } echo "</div>"; } echo "</fieldset>"; } ?> <fieldset> <input type="hidden" name="defaultCharID" id="defaultCharID" value="<?php echo $defaultCharID; ?>" /> <input type="submit" class="submit" id="editBio" title="Edit Bio" value="Edit Bio" /> </fieldset> </form> </div> <!-- /Inner Content --> <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php'); $defaultCharID = $_SESSION['defaultCharID']; $styleIDQuery = " SELECT characters.styleID FROM characters WHERE characters.ID = '" . $defaultCharID . "'"; $styleIDResult = mysqli_query ( $dbc, $styleIDQuery ); // Run The Query $row = mysqli_fetch_array( $styleIDResult, MYSQL_ASSOC ); $styleID = $row[ 'styleID' ]; $groupsQuery = " SELECT groups.* FROM groups WHERE groups.styleID = '" . $styleID . "' ORDER BY groups.ID"; $groupsResult = mysqli_query ( $dbc, $groupsQuery ); // Run The Query $fieldsQuery = " SELECT fields.* FROM fields WHERE fields.styleID = '". $styleID . "' AND fields.groupID = '%d' AND fields.statusID = 1"; $fieldContent = " SELECT fieldsContent.* FROM fieldsContent WHERE fieldsContent.characterID = '". $defaultCharID . "' AND fieldsContent.fieldID = = '". $fieldID ."'"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/ Share on other sites More sharing options...
Xtremer360 Posted April 15, 2011 Author Share Posted April 15, 2011 Any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1201862 Share on other sites More sharing options...
Xtremer360 Posted April 15, 2011 Author Share Posted April 15, 2011 I tired working on it but still at a loss at what I'm doing wrong in my code. Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202077 Share on other sites More sharing options...
mikosiko Posted April 15, 2011 Share Posted April 15, 2011 "is when its getting the content for the field it needs to get the ID of the field that way it can get the content of the field" ... what? explain what error do you get or what are you trying to do and which are the expected results... I just see 2 pieces of code without any connection... hard to help you in that way Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202088 Share on other sites More sharing options...
Xtremer360 Posted April 15, 2011 Author Share Posted April 15, 2011 I apologize. I'll try and rephrase in a better way. The connection between the two files is that the bottom block of code is the php/bios.php file which is included in the top block of code. I was just trying to separate php code from xhtml/css as much as I could. What happens is it gets the groups of the character and displays them each as a fieldset. it also inside the loop is it gets the ID of the group and queries the fields table with that groupID and returns all the fields that belong to each of those groups and performs a while loop to display each of those fields. What I'm trying to figure out how to do is with each fieldID is query the fieldContents table (fieldContentsQuery) and get the content from the content column (value for the input field) from the db and display it as the input fields value attribute. Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202097 Share on other sites More sharing options...
mikosiko Posted April 15, 2011 Share Posted April 15, 2011 analyze if, instead of have 2 separates queries for fields and fieldcontents a single query using a JOIN between the tables simplify your problem (it should) Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202109 Share on other sites More sharing options...
Xtremer360 Posted April 15, 2011 Author Share Posted April 15, 2011 Here's my updated code and now I'm not returning any results. All it shows is the Edit Bio Submit button. <?php require ('php/bios.php'); ?> <script type="text/javascript" src="forms/edit/js/bios.js"></script> <!-- Title --> <div id="title" class="b2"> <h2>Character Management</h2> </div> <!-- Title --> <!-- Inner Content --> <div id="innerContent"> <form action="#" id="bioForm" > <?php while ($row = mysqli_fetch_array($groupsResult, MYSQL_ASSOC)) { echo "<fieldset> <legend>" . $row['groupName'] . "</legend>"; $fieldsResult = mysqli_query ( $dbc, sprintf($fieldsQuery,$row['ID']) ); while ($row2 = mysqli_fetch_array($fieldsResult, MYSQL_ASSOC)) { echo "<div class=field required>"; if ($row2['inputType'] == "text") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<input type=text name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=text biofield title=" . $row2['fullName'] . " value=" . $row2['content'] . " />"; } elseif ($row2['inputType'] == "textarea") { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<textarea name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=textarea biofield title=" . $row2['fullName'] . " value=" . $row2['content'] . " />"; } else { echo "<label for=" . $row2['ID'] . ">" . $row2['fullName'] . "</label>"; echo "<select name=" . $row2['ID'] . " id=" . $row2['ID'] . " class=dropdown biofield title=" . $row2['fullName'] . " >"; echo "<option value= >None</option>"; if ($styleID == 1 || $styleID == 2 || $styleID == 6) { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID = 3 ORDER BY characters.characterName"; } else { $charactersQuery = " SELECT characters.ID, characters.characterName FROM characters WHERE characters.styleID IN (1,2,6) ORDER BY characters.characterName"; } $charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query while ( $row3 = mysqli_fetch_array ($charactersResult, MYSQLI_ASSOC)) { echo "<option value=" . $row3['ID'] . ">" . $row3['characterName'] . "</option>\r"; } echo "</select>"; } echo "</div>"; } echo "</fieldset>"; } ?> <fieldset> <input type="hidden" name="defaultCharID" id="defaultCharID" value="<?php echo $defaultCharID; ?>" /> <input type="submit" class="submit" id="editBio" title="Edit Bio" value="Edit Bio" /> </fieldset> </form> </div> <!-- /Inner Content --> <?php session_start(); // Access the existing session // Include the database page require ('../../inc/dbconfig.php'); $defaultCharID = $_SESSION['defaultCharID']; $styleIDQuery = " SELECT characters.styleID FROM characters WHERE characters.ID = '" . $defaultCharID . "'"; $styleIDResult = mysqli_query ( $dbc, $styleIDQuery ); // Run The Query $row = mysqli_fetch_array( $styleIDResult, MYSQL_ASSOC ); $styleID = $row[ 'styleID' ]; $groupsQuery = " SELECT groups.* FROM groups WHERE groups.styleID = '" . $styleID . "' ORDER BY groups.ID"; $groupsResult = mysqli_query ( $dbc, $groupsQuery ); // Run The Query $fieldsQuery = " SELECT fields.*, fieldsContent.* FROM fields INNER JOIN fieldsContent ON fields.ID = fieldsContents.fieldID WHERE fields.styleID = '". $styleID . "' AND fields.groupID = '%d' AND fields.statusID = 1"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202116 Share on other sites More sharing options...
mikosiko Posted April 15, 2011 Share Posted April 15, 2011 "analyze" != "just do it" - did you debug your code? - did you run the query alone (PhpMyadmin or Mysql)? ... it return results? - are you controlling that this $fieldsResult = mysqli_query ( $dbc, sprintf($fieldsQuery,$row['ID']) ); is not failing? that just for a start Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202128 Share on other sites More sharing options...
Xtremer360 Posted April 15, 2011 Author Share Posted April 15, 2011 I put this: echo $fieldsResult; right after the variable gets defined and it didn't echo anything? Quote Link to comment https://forums.phpfreaks.com/topic/233766-getting-the-content-of-the-field/#findComment-1202134 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.