Submit Your Article Forum Rules

Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Help Needed with PHP Logic

  1. #1
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327

    Help Needed with PHP Logic

    I need help understanding... PHP. The application is Yii but I need guidence on the PHP logic so I will know where to look for solutions and what to try.

    The goal is to offer visitors a total estimate for the items they select.

    The form is set with a multiple select list Box and I want to reflect the items selected on the page, as they are selected, with the total time estimate, mulitplied by the hour rate to equal the job estimate.

    I have a table on the form set up to display the selected items in one <td> and to reflect the total hrs of the items in another <td>, the rate p/hr in another <td>, and yes, another <td> for the total job Estimate.

    The form is working, it saves the selected items to the db column as a comma seperated string using a function afterFind to explode the db column. (I found that solution in a forum post.)

    The hrRate depends on the jobClass they select. There is a pre-populated table for those.

    The item timeEstimate is in the pre-populated serviceItem table.

    I thought to begin by getting the items selected to echo into the <td> but have failed, and I am wondering if that is really where I should start.

    How should this task be approached? What steps do I need to consider?

  2. #2
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760
    If you want to display the information on the page as the user makes selections, wouldn't you just use Javascript to do that? Where does PHP come in?
    Dynamic Software Development
    www.activeminds.ca

  3. #3
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    You bring up a good point Dave.

    I assumed the solution to be PHP because the site is a Yii framework application. Out of all of the post I have read so far, for anything I have searched for, I do not recall ever seeing a javascript solution for anything.

    Due to my lack of programming experience I am stuck, not knowing which steps to take and need guidence, whether it's js or php.

  4. #4
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,793
    Are you generating a new page in response to the form submission, or are you updating the current page? This will make a difference, since the latter will require AJAX, which is JavaScript (as the J denotes).

  5. #5
    WebProWorld MVP DaveSawers's Avatar
    Join Date
    Dec 2006
    Location
    Lunenburg, Nova Scotia, Canada
    Posts
    760
    Quote Originally Posted by Clicken View Post
    Out of all of the post I have read so far, for anything I have searched for, I do not recall ever seeing a javascript solution for anything.
    Huh? Javascript is the client side scripting language used by EVERYBODY for EVERYTHING.

    I'm not generally a fan of frameworks. They tend to add bloat and complications and make it difficult to customize things when you need to.

    If you're getting into this kind of detail, you need to understand programming or get a programmer to help you. Presumably one that has worked with Yii (so not me).
    Dynamic Software Development
    www.activeminds.ca

  6. #6
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    AJAX Validation is enabled. Upon the form submission the page refreshes and there is a flash message indicating it was successful. The info is reflected in the database. This is all working.

    However I want to give the visitor an estimate of the selections as they are being selected. So if they add to the selection or take away from the selction this will be reflected in the on page total before they sumbit.

    The following code puts the multiple selection into a single db table column. Would it be logical or possible to use the afterfind function below for two purposes? Could it also be used to relect selections on the page? I have tried to assign a variable and then echo but I get an error that the variable is unassigned.

    Code:
    	public $selection;
    
    //explode your db column named selection and put result into your virtual as comma seperated string */
    	public function afterFind()
    	{
    
      		$this->selection=explode(',',$this->selection);
    			return true;
    
    		
    	}
    
    	/*implode your selection */
    	public function beforeSave()
    	{
      		$this->selection=implode(',',$this->selection);
    			return true;
    	}

  7. #7
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    Quote Originally Posted by DaveSawers View Post
    Huh? Javascript is the client side scripting language used by EVERYBODY for EVERYTHING.

    I'm not generally a fan of frameworks. They tend to add bloat and complications and make it difficult to customize things when you need to.

    If you're getting into this kind of detail, you need to understand programming or get a programmer to help you. Presumably one that has worked with Yii (so not me).
    Thanks Dave, I can appreciate your response. My request for guidence at the Yii site has yet to get a response, for what ever reason I don't know.

    I am trying to understand programming and Yii offers a working application to learn with. It is a slow process, one step at a time. I have completed an application for a friend which utilizes simple forms. This application is for personal use and the form is more complicated, so I am asking for a programmmers generous guidence.

    Any PHP solution could be applied with Yii, I just don't know what the logic is for what I want to accomplish.

  8. #8
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,793
    Can the rate data be stored in the form, itself, in named fields? If so, then any item selected can automatically have a calculated estimate appear as soon as it is selected. AJAX wouldn't be needed, and only a tiny client side script would do the trick.

    You could still use a server side rate table to help generate the form and populate the rate fields (label and rate) (PHP) so updates would only ever need to be done to the table, and not the form. The table wouldn't have to be in the database, but a simple stored array in an include file.

    It would help if you could share the form with us (HTML) and the rate table. One can whip up an example page if we have something to work with on our end.

  9. #9
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    The db table jobClass has three columns: classId, className, hrRate there are hidden fields on the form for the values which are not user input.
    After further digging, I found this 'Helper Class' for javascript http://www.yiiframework.com/doc/api/1.1/CJavaScript
    Code:
    		<!-- STEP ONE -- job class  -->
    
    <div class="row">
    		<?php echo $form->labelEx($ServiceRequest,'className'); ?>
    		<?php echo $form->dropDownList($ServiceRequest,'className',$ServiceRequest->classOptions,  array('empty' => ('Select Job Type' ))); ?></p>
    		<?php echo $form->error($ServiceRequest,'className'); ?>
    
    </div><!-- eof step one -->
    
    		<!-- STEP TWO -- selection listbox -->
    
    <div class="row">
    		<?php echo $form->labelEx($ServiceRequest,'selection'); ?>
    		<?php echo CHtml::activeListBox($ServiceRequest, 'selection',
    			CHtml::listData(ServiceItem::model()->findAllbySql(
                    'SELECT itemId, CONCAT(itemId, ". ", itemName) as listBoxData FROM serviceItem'),'itemId', 'listBoxData'), array('empty'=>'shift-key select multiple','prompt'=>'Select All that Apply', 'multiple'=>'multiple','style'=>'width:auto; height:138px;' )); ?>
    		<?php echo $form->error($ServiceRequest,'selection'); ?>
    </div>
    </div><!-- eof step two -->
    
    		<!-- step three visitor info and comments, captcha were removed for breivity -->
    
    		<!-- HIDDEN FIELDS for calculations -->
    <div class="row">
    
    		<?php echo $form->hiddenField($VisitorInfo,'submitDate'); ?>
    		<?php echo $form->hiddenField($ServiceRequest,'hrRate',array('size'=>5,'maxlength'=>5)); ?>
    		<?php echo $form->hiddenField($ServiceRequest,'totalEstTime',array('size'=>5,'maxlength'=>5)); ?>
    		<?php echo $form->hiddenField($ServiceRequest,'jobEst',array('size'=>5,'maxlength'=>5)); ?>
    
    </div><!-- eof hidden fields -->
    
    <div class="row buttons">
    		<?php echo CHtml::submitButton($ServiceRequest->isNewRecord ? 'Send Request' : 'Save'); ?>
    </div>
    
    
    		<!-- ESTIMATE DISPLAY TABLE -->
    
    <TABLE summary="This table represents the estimated charges for services selected on the Service Request Form. Total estimated time multiplied by the hour rate.">
    <CAPTION>Service Estimate</CAPTION>
    <TR>
       <TH id="t1">Items</TH>
       <TH id="t2">Time Est</TH>
    
    <TR>
       <TD headers="t1"><? echo $ServiceRequest->model($SelectedItem); ?></TD>
       <TD headers="t2">totalEstTime</TD>
    <TR>
       <TH id="t1">Hour Rate</TH>
       <TH id="t2">Total Est</TH>
    
    <TR>
       <TD headers="t1">hrRate</TD>
       <TD headers="t2">jobEst</TD>
    
    </TABLE>
    
    <?php $this->endWidget(); ?>
    </div>
    and,... thanks WG, for your efforts!

  10. #10
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,793
    HTML Code:
      <TD headers="t1">hrRate</TD>
      <TD headers="t2">jobEst</TD>
    Might be where the snag is.

    PHP Code:
      <TD headers="t1"><?php echo $hrRate ?></TD>
      <TD headers="t2"><?php echo $jobEst ?></TD>
    Just feeling my way around...

    - - - Updated - - -

    Or possibly something like this:

    PHP Code:
      <TD headers="t1"><?php hrRate(); ?></TD>
      <TD headers="t2"><?php jobEst(); ?></TD>

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •