Jump to content

Foreach loops (I think)


Xtremer360

Recommended Posts

My goal here is to have it foreach group from the DB it'll create a new frameset with the groupName as the legend and then under each of those it will create another foreach for each of the fields inside of that group that has a enabled value of 0 from the db.  Both queries work correctly. I just get trouble writing foreach loops and I'm not sure how this one is going to work out.

 

<?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' ];

$biofieldsQuery = "
    SELECT 
        fields.*,
        groups.* 
    FROM 
        fields 
        INNER JOIN groups 
            ON fields.groupID = groups.ID 
    WHERE 
        groups.styleID = '" . $styleID . "' AND fields.styleID = '" . $styleID . "' AND groups.enabled = 0 AND fields.enabled = 0";
$biofieldsResult = mysqli_query ( $dbc, $biofieldsQuery ); // Run The Query
$row = mysqli_fetch_array( $biofieldsResult, MYSQL_ASSOC );
$groupName = $row[ 'groupName' ];

?>

<script type="text/javascript">
$(document).ready(function() {

});
</script>

<!-- Title -->
<div id="title" class="b2">
<h2>Character Management</h2>
<!-- TitleActions -->
<div id="titleActions">
	<!-- ListSearch -->
	<div class="listSearch actionBlock">
		<div class="search">
			<label for="search">Recherche</label>
			<input type="text" name="search" id="search" class="text" />
		</div>
		<div class="submit">
			<button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button>
		</div>
	</div>
	<!-- /ListSearch -->
</div>
<!-- /TitleActions -->
</div>
<!-- Title -->

<!-- Inner Content -->
<div id="innerContent">

    <form action="#" id="bioForm" >
    	<fieldset>
    		<legend><?php echo $groupName; ?></legend>
            <div class="field required">
    			<label for="matchType">Match Type Name</label>
    			<input type="text" class="text" name="matchType" id="matchType" title="Match Type Name"/>
    			<span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span>
    		</div>
            	<input type="submit" class="submit" name="submitMatchType" id="submitMatchType" title="Submit Match Type" value="Submit Match Type"/>
    	</fieldset>
    </form>

</div>
<!-- /Inner Content -->

Link to comment
Share on other sites

Here's my updated code. I have it displaying all the groups correctly however what I need it to do is display the correct fields that are enabled for each of those fields and not sure to complete this.

 

<?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 . "' AND groups.enabled = 0
    ORDER BY 
        groups.ID";
$groupsResult = mysqli_query ( $dbc, $groupsQuery ); // Run The Query


$fieldsQuery = "
    SELECT 
        fields.* 
    FROM 
        fields 
    WHERE 
        fields.styleID = '" . $styleID . "' AND fields.groupID = '" . $groupID . "' AND fields.enabled = 0";
$fieldsResult = mysqli_query ( $dbc, $fieldsQuery ); // Run The Query

?>

<script type="text/javascript">
$(document).ready(function() {

});
</script>

<!-- Title -->
<div id="title" class="b2">
<h2>Character Management</h2>
<!-- TitleActions -->
<div id="titleActions">
	<!-- ListSearch -->
	<div class="listSearch actionBlock">
		<div class="search">
			<label for="search">Recherche</label>
			<input type="text" name="search" id="search" class="text" />
		</div>
		<div class="submit">
			<button type="submit" id="search-button" class="button"><strong><img src="img/icons/search_48.png" alt="comments" class="icon "/></strong></button>
		</div>
	</div>
	<!-- /ListSearch -->
</div>
<!-- /TitleActions -->
</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>";
                
                echo "</fieldset>";
            }  
        ?>
        <input type="submit" class="submit" name="submitMatchType" id="submitMatchType" title="Submit Match Type" value="Submit Match Type"/>
    </form>

</div>
<!-- /Inner Content -->

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.