Jump to content

Getting the content of the field


Xtremer360

Recommended Posts

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 ."'";        

?> 

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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";

?> 

Link to comment
Share on other sites

"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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.