makenoiz Posted February 7, 2009 Share Posted February 7, 2009 I have an html form in php page that is populated from mysql db.. 2 tables service_issue_categories +-----------+--------+------------+ | si_cats_id | si_cats_description | +-----------+--------+------------+ | 1 | Complaint | | 2 | Compliment | | 3 | Poor Appearance | | 4 | Great Appearance | +-----------+--------+------------+ service_issue_log +--------------------+----------------+-----------------------+----- | service_issue_log_id| service_issue_id | service_issue_log_desc |date +--------------------+----------------+-----------------------+----- | 1 | 2 | Very nice place | 2009-02-05 | 2 | 1 | Heater too hot | 2009-02-05 | 3 |4 | Was dressed great | 2009-02-05 +--------------------+----------------+-----------------------+----- I have success fully populated textarea boxes with service_issue_log.service_issue_log_desc but I need drop downs next to them with a list of all possible choices for service_issue_categories. si_cats_description but with the correct category as "selected" in the options drop down for that particular description. I can get the drop downs populated but I cant get the correct Categoery as the initial "selected" value in the drop down. Seems like this should be easy considering that I have everything else working just fine but I have spent 2 days on it and I know it just the way I have the logic of my PHP statements. Can any of you take a look and tell me if you can spot the issue right off. I would greatly appreciate it. ......... <?PHP $selDate = ($_GET['selDate'] != '')? $_GET['selDate']:$_POST['selDate']; // get the service issues based on date $query_svcIssues = "SELECT * from service_issue_categories , service_issue_log WHERE service_issue_log.si_date='".$selDate."' AND service_issue_log.service_issue_id=service_issue_categories.si_cats_id"; $result_svcIssues = mysql_query($query_svcIssues); if(mysql_num_rows($result_svcIssues) > 0) { // there are issue in db while($row_svcIssues = mysql_fetch_array($result_svcIssues)){ ?> <div class="field"><span class="label">Service Comments:<br /> </span><br> <span class="box"><input type="text" size="30" name="svcIssue_<?=$row_svcIssues['service_issue_log_id']; ?>" value="<?=$row['heading'];?>" /> <?php // form the service issue drop down boxes $options=""; // get the service issue cateories $query_svcIssueCats = "SELECT * from service_issue_categories"; $result_svcIssueCats = mysql_query($query_svcIssueCats); $row_svcIssueCats = mysql_fetch_array($result_svcIssueCats); while ($row_svcIssueCats = mysql_fetch_array($result_svcIssueCats)) { // while there are still categories $tblsvcissueid=$row_svcIssueCats['si_cats_id']; $tblsvcdescription=$row_svcIssueCats['si_cats_description']; //if the id of the category matches the id in our event list place as the selected in option list if ($row_svcIssueCats['si_cats_id'] = $row_svcIssue['service_issue_id'] ){ $isSelected = "selected"; } // close if $options.="<OPTION VALUE=\"".$tblsvcissueid."\" ".$isSelected.">".$tblsvcdescription; $isSelected = ""; } // close while ?> <SELECT NAME='si_category'> <OPTION VALUE=0>Choose <?=$options?> </SELECT> <span class="box"><textarea name="svcIssue_<?=$row_svcIssues['service_issue_log_id']; ?>" cols="50" rows="6"><?=$row_svcIssues['service_issue_log_description']; ?></textarea></span> </div> <?PHP } // end while........ Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/ Share on other sites More sharing options...
landavia Posted February 7, 2009 Share Posted February 7, 2009 i can't answer now.. but you logic must sharpen more btw.. u type $options.="<OPTION VALUE=\"".$tblsvcissueid."\" ".$isSelected.">".$tblsvcdescription; u should type $options.="<OPTION VALUE=\"".$tblsvcissueid."\" ".$isSelected.">".$tblsvcdescription."</option>"; try read your source (view source on browser).. u might notice something there Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756625 Share on other sites More sharing options...
makenoiz Posted February 7, 2009 Author Share Posted February 7, 2009 Thanks Ill make that change and see if it make a difference... thank you for the speedy reply... ........................ -- made the change but still no selected value on the drop downs for each service issue description. Thank you though Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756631 Share on other sites More sharing options...
sasa Posted February 7, 2009 Share Posted February 7, 2009 remove line $row_svcIssueCats = mysql_fetch_array($result_svcIssueCats); just before 2nd while loop Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756636 Share on other sites More sharing options...
makenoiz Posted February 7, 2009 Author Share Posted February 7, 2009 Removed it... and still no selected option on the drop downs. Thanks though.. Heres the new code with both of your changes: ......... <?PHP $selDate = ($_GET['selDate'] != '')? $_GET['selDate']:$_POST['selDate']; // get the service issues based on date $query_svcIssues = "SELECT * from service_issue_categories , service_issue_log WHERE service_issue_log.si_date='".$selDate."' AND service_issue_log.service_issue_id=service_issue_categories.si_cats_id"; $result_svcIssues = mysql_query($query_svcIssues); if(mysql_num_rows($result_svcIssues) > 0) { // there are issue in db while($row_svcIssues = mysql_fetch_array($result_svcIssues)){ ?> <div class="field"><span class="label">Service Comments:<br /> </span><br> <span class="box"><input type="text" size="30" name="svcIssue_<?=$row_svcIssues['service_issue_log_id']; ?>" value="<?=$row['heading'];?>" /> <?php // form the service issue drop down boxes $options=""; // get the service issue cateories $query_svcIssueCats = "SELECT * from service_issue_categories"; $result_svcIssueCats = mysql_query($query_svcIssueCats); while ($row_svcIssueCats = mysql_fetch_array($result_svcIssueCats)) { // while there are still categories $tblsvcissueid=$row_svcIssueCats['si_cats_id']; $tblsvcdescription=$row_svcIssueCats['si_cats_description']; //if the id of the category matches the id in our event list place as the selected in option list if ($row_svcIssueCats['si_cats_id'] = $row_svcIssue['service_issue_id'] ){ $isSelected = "selected"; } // close if $options.="<OPTION VALUE=\"".$tblsvcissueid."\" ".$isSelected.">".$tblsvcdescription."</option>"; $isSelected = ""; } // close while ?> <SELECT NAME='si_category'> <OPTION VALUE=0>Choose <?=$options?> </SELECT> <span class="box"><textarea name="svcIssue_<?=$row_svcIssues['service_issue_log_id']; ?>" cols="50" rows="6"><?=$row_svcIssues['service_issue_log_description']; ?></textarea></span> </div> <?PHP } // end while........ Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756638 Share on other sites More sharing options...
makenoiz Posted February 7, 2009 Author Share Posted February 7, 2009 I found it! if ($row_svcIssueCats['si_cats_id'] = $row_svcIssues['service_issue_id '] ){ $isSelected = "selected"; should have been if ($row_svcIssueCats['si_cats_id'] == $row_svcIssues['service_issue_id'] ){ $isSelected = "selected"; Add another = and remove extra space in $row_svcIssues['service_issue_id '] Thanks to those who jumped on this.... Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756657 Share on other sites More sharing options...
Errant_Shadow Posted February 7, 2009 Share Posted February 7, 2009 when it comes to things like "<?=$options?>" in the section "<SELECT NAME='si_category'> <OPTION VALUE=0>Choose <?=$options?> </SELECT>" shouldn't it read "<?php echo $options; ?>" I'm not sure how much of a difference it would make, but I'd use echos instead of turning php on and off <?PHP $selDate = ($_GET['selDate'] != '')? $_GET['selDate']:$_POST['selDate']; // get the service issues based on date $query_svcIssues = "SELECT * FROM service_issue_categories, service_issue_log WHERE service_issue_log.si_date='$selDate' AND service_issue_log.service_issue_id=service_issue_categories.si_cats_id"; $result_svcIssues = mysql_query($query_svcIssues); if(mysql_num_rows($result_svcIssues) > 0) { // there are issue in db while($row_svcIssues = mysql_fetch_array($result_svcIssues, MYSQL_ASSOC)){ echo '<div class="field"><span class="label">Service Comments:<br /> </span><br>'; echo '<span class="box"><input type="text" size="30" name="svcIssue_'.$row_svcIssues['service_issue_log_id'].'" value="'.$row['heading'].'" />'; // form the service issue drop down boxes $options=""; // get the service issue cateories $query_svcIssueCats = "SELECT * FROM service_issue_categories"; $result_svcIssueCats = mysql_query($query_svcIssueCats); while ($row_svcIssueCats = mysql_fetch_array($result_svcIssueCats, MYSQL_ASSOC)) { // while there are still categories $tblsvcissueid=$row_svcIssueCats['si_cats_id']; $tblsvcdescription=$row_svcIssueCats['si_cats_description']; //if the id of the category matches the id in our event list place as the selected in option list if ($row_svcIssueCats['si_cats_id'] == $row_svcIssue['service_issue_id'] ){ $isSelected = "selected"; } // close if $options.="<OPTION VALUE=\"".$tblsvcissueid."\" ".$isSelected.">".$tblsvcdescription."</option>"; $isSelected = ""; } // close while echo '<SELECT NAME="si_category"> <OPTION VALUE="0">Choose '.$options.' </SELECT>'; echo '<span class="box"><textarea name="svcIssue_'.$row_svcIssues['service_issue_log_id'].'" cols="50" rows="6">'.$row_svcIssues['service_issue_log_description'].'</textarea></span></div>'; } // end if ?> Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756664 Share on other sites More sharing options...
printf Posted February 7, 2009 Share Posted February 7, 2009 I myself would not keep repeating the same query, over and over again. If you know the first query return results, then load service_issue_categories table into an array and create your select using that array. That would be so much better then querying for the same result set over and over again... Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756778 Share on other sites More sharing options...
makenoiz Posted February 7, 2009 Author Share Posted February 7, 2009 HI thanks for both of your replies: Errant_shadow, I believe <?=$options?> is an echo. if you dont have the PHP in there, I believe its considered an echo. I think I read that somewhere. printf, they are actually two different querys, one has a WHERE in it so that Im pulling specific info based on the other table, the other is SELECT *, just so I can get all the categories for the options list in the form. Im not sure how I could select * catgeories, then pull only those records I need out of that array based on the Id. If you have a suggestion, Id love to hear it Thanks for your replies Quote Link to comment https://forums.phpfreaks.com/topic/144185-solved-help-with-logic-please/#findComment-756846 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.