Jump to content

[SOLVED] Help with logic please


makenoiz

Recommended Posts

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

 

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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........

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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 ?>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

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

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.