Jump to content

If statement inside of a while loop


Xtremer360

Recommended Posts

After it goes through the while loop its supposed to take the ID of the first one in the loop and find out its awardType and then with the awardType variable go through the the if statement. After it displays it the code that fits the awardType variable then it gets the second item in the while loop and then with the ID of the second item takes it back to get the  awardType and then goes back through the if statement again. I'm not sure what I'm doing wrong. As of right now all its doing is displaying its awardName and a blank dropdown.

 

<?php

session_start(); // Access the existing session

// Include the database page
require ('../../inc/dbconfig.php');l

$userID = $_SESSION['userID'];

$statusQuery = "
    SELECT 
        * 
    FROM 
        statuses";
$statusResult = mysqli_query ( $dbc, $statusQuery ); // Run The Query 

$awardQuery = "
    SELECT
        awards.ID,
        awards.awardName,
        awards.awardType
    FROM
        awards";
$awardResult = mysqli_query ( $dbc, $awardQuery ); // Run The Query
$row = mysqli_fetch_array ( $awardResult, MYSQL_ASSOC );

$awardType = $row[ 'awardType' ];

$charactersQuery = "
    SELECT 
        characters.ID, 
        characters.characterName 
    FROM 
        characters
    ORDER BY 
        characters.characterName";
$charactersResult = mysqli_query ( $dbc, $charactersQuery ); // Run The Query

$matchQuery = "
    SELECT
        eventSegments.ID,
        eventSegments.segmentTitle
    FROM
        eventSegments
        INNER JOIN events
            ON eventSegments.eventID = events.ID
    WHERE
        DATE_FORMAT(events.bookingDate,'%Y') = DATE_FORMAT(curdate(),'%Y')";
$matchResult = mysqli_query ( $dbc, $matchQuery ); // Run The Query


?>

 

 

<fieldset>
	<legend>Nominees</legend>
        <?php 
        mysqli_data_seek( $awardResult, 0 );
        while ( $row = mysqli_fetch_array ( $awardResult, MYSQL_ASSOC ) ) { ?>
        <?php if ($awardType == 'Singular') { ?>
        <div class="field required">
		<label for="charactersDrop"><?php echo $row['awardName']; ?></label>
		<select class="dropdown" name="charactersDrop" id="charactersDrop" title="Characters Drop">
                <option value="">- Select -</option>
               <?php
                    while ( $row = mysqli_fetch_array ( $charactersResult, MYSQL_ASSOC ) ) { 
                        print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";
                    }
                ?>
            </select>
            <input type="button" value="Add Character" class="" onclick="HandlerCharacters()"/>
            <ul id="characterList">
            </ul>
            <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>
        <? } else { ?>
        <div class="field required">
		<label for="events"><?php echo $row['awardName']; ?></label>
		<select class="dropdown" name="events" id="events" title="Events for <?php echo date("Y") ?>">
                <option value="">- Select -</option>
               <?php
                    while ( $row = mysqli_fetch_array ( $matchResult, MYSQL_ASSOC ) ) { 
                        print "<option value=\"".$row['ID']."\">".$row['segmentTitle']."</option>\r";
                    }
                ?>
            </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>
            <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>
        <?php } ?>
        <?php } ?>

Link to comment
Share on other sites

Okay well it works but it only shows the all the awards and has them all as the second part of the if loop even though most of them should be inside the first part of the if statement.

 

    
<script type="text/javascript" src="forms/addnew/js/awardsshow.js"></script>

<!-- Form -->
<form action="#" id="awardsshowForm" >
<fieldset>
	<legend>Add New Awards Show</legend>
        <div class="field required">
		<label for="date">Date</label>
		<input type="text" class="text" name="date" id="date" title="Date" readonly="readonly"/> 
            <span style="margin-left: -36px;" 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 id="datepicker"></div>
        </div>
        <div class="field required">
		<label for="statusID">Status</label>
            <select class="dropdown" name="statusID" id="statusID" title="Status">
                <option value="">- Select -</option>
                <option value="1">Active</option>

<option value="2">Inactive</option>
            </select>
		<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>
</fieldset>
    <fieldset>
	<legend>Nominees</legend>
                        <div class="field required">

		<label for="events">Match of the Year</label>
		<select class="dropdown" name="events" id="events" title="Events for 2011">
                <option value="">- Select -</option>
                           </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>
            <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>
                                <div class="field required">
		<label for="events">Best Singles Performer</label>
		<select class="dropdown" name="events" id="events" title="Events for 2011">
                <option value="">- Select -</option>
                           </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">

            </ul>
            <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>
                                <div class="field required">
		<label for="events">Best Manager of the Year</label>
		<select class="dropdown" name="events" id="events" title="Events for 2011">
                <option value="">- Select -</option>

                           </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>
            <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>
                                <div class="field required">
		<label for="events">Best Woman of the Year</label>

		<select class="dropdown" name="events" id="events" title="Events for 2011">
                <option value="">- Select -</option>
                           </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>
            <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>

                                <div class="field required">
		<label for="events">Best Finisher</label>
		<select class="dropdown" name="events" id="events" title="Events for 2011">
                <option value="">- Select -</option>
                           </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>

            <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>
                                <div class="field required">
		<label for="events">Best New Sensation of the Squared Circle</label>
		<select class="dropdown" name="events" id="events" title="Events for 2011">
                <option value="">- Select -</option>
                           </select>

            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>
            <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>
                                <div class="field required">
		<label for="events">Best Tag Team of the Year</label>
		<select class="dropdown" name="events" id="events" title="Events for 2011">

                <option value="">- Select -</option>
                           </select>
            <input type="button" value="Add Match" class="" onclick="AddMatch()"/>
            <ul id="matchList">
            </ul>
            <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="hidden" name="userID" id="userID" value="1" />  
        <input type="submit" class="submit" name="submitAwardsShow" id="submitAwardsShow" title="Submit Awards Show" value="Submit Awards Show"/>

</fieldset>
</form>
<!-- /Form -->

<!-- Messages -->
<div class="message message-error">
    <h6>Required field missing</h6>
    <p>Please fill in all required fields. </p>
</div>
<div class="message message-success">
    <h6>Operation succesful</h6>

    <p>Arena was added to the database.</p>
</div>
<!-- /Messages -->

Link to comment
Share on other sites

this may be trivial but I think u need short hand php enable for this line to work.. I could be wrong.. but its worth a shot

 

<? } else { ?>

 

add the php in there...

 

<?php

 

 

you may also need to choose a unique name for each $row = mysqli_fetch.. line.. as each while loop seems to be embedded in the other..

this could be mixing up the values in an undesired way. idk man like i said confusing to read.

Link to comment
Share on other sites

Are you really putting all those line returns in your query?

session_start(); // Access the existing session
// Include the database page
require ('../../inc/dbconfig.php');
$userID = $_SESSION['userID'];
$statusQuery = "SELECT * FROM statuses";
$statusResult = mysqli_query ($dbc, $statusQuery); // Run The Query 

$awardQuery = "SELECT awards.ID, awards.awardName, awards.awardType FROM awards";
$awardResult = mysqli_query ($dbc, $awardQuery); // Run The Query
$row = mysqli_fetch_array ($awardResult, MYSQL_ASSOC);

$awardType = $row['awardType'];

$charactersQuery = "SELECT characters.ID, characters.characterName FROM  characters ORDER BY  characters.characterName";
$charactersResult = mysqli_query ($dbc, $charactersQuery); // Run The Query

$matchQuery = "SELECT eventSegments.ID, eventSegments.segmentTitle FROM eventSegments INNER JOIN events ON eventSegments.eventID = events.ID WHERE DATE_FORMAT(events.bookingDate,'%Y') = DATE_FORMAT(curdate(),'%Y')";
$matchResult = mysqli_query ($dbc, $matchQuery); // Run The Query

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.