Xtremer360 Posted May 7, 2011 Share Posted May 7, 2011 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 } ?> Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/ Share on other sites More sharing options...
efficacious Posted May 7, 2011 Share Posted May 7, 2011 my first suggestion would be to separate the PHP from the display code.. makes it very difficult to follow. I'm not sure but it seems like some vars are not in loops that should be or vice versa.. very messy. Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211825 Share on other sites More sharing options...
Xtremer360 Posted May 7, 2011 Author Share Posted May 7, 2011 Hmm okay. Anyone else have any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211826 Share on other sites More sharing options...
efficacious Posted May 7, 2011 Share Posted May 7, 2011 whats the HTML source of this look like.. namely the drop box sections? Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211827 Share on other sites More sharing options...
Xtremer360 Posted May 7, 2011 Author Share Posted May 7, 2011 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 --> Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211828 Share on other sites More sharing options...
efficacious Posted May 7, 2011 Share Posted May 7, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211829 Share on other sites More sharing options...
Xtremer360 Posted May 7, 2011 Author Share Posted May 7, 2011 Thanks for noticing that but that didn't help. Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211830 Share on other sites More sharing options...
Xtremer360 Posted May 7, 2011 Author Share Posted May 7, 2011 Any other suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211988 Share on other sites More sharing options...
Drummin Posted May 7, 2011 Share Posted May 7, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211997 Share on other sites More sharing options...
Xtremer360 Posted May 7, 2011 Author Share Posted May 7, 2011 But what is it that's going to tell it to get it to send back the ID of the award and get its awardType Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1211998 Share on other sites More sharing options...
Xtremer360 Posted May 9, 2011 Author Share Posted May 9, 2011 Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/235752-if-statement-inside-of-a-while-loop/#findComment-1212653 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.