Submit Your Article Forum Rules

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 24

Thread: Help Needed with PHP Logic

  1. #11
    Member
    Join Date
    Sep 2005
    Posts
    39
    Hey Clicken,

    I would tend to agree with Dave about the need to learn programming. Programming is the bombbay, but it takes practice and experience to be productive. Are you running an existing website? Or, is this a new project?

    If there is a real need to have this functionality, then I would hire a programmer on oDesk or eLance to knock out this calculator function in a few minutes and be done with it. Move on with your business.

    If you reeeaaaallly would like to learn how make cool forms and functions on your website. Still... hire a programmer to fix the current problem. Then learn how to build a simple calculator in javascript.

    Programming PHP, js, forms, database config, is great. You can make some really cool stuff... IF you put in the time.

  2. #12
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    Hi Jermooski,

    Your comments are well taken but would you explain what it means to learn PHP if it is not practice and experience which teaches. Isn't what I am doing both of those things?

    How many programmers learned without asking questions or guidence from those who have already learned? Some just pick it up faster than others, and I may be slow at it but I am capable.

    If I hire a programmer then what will I have learned? Will I be forever dependent on them for my site's inner workings? I find great satisfaction when something I struggled to accomplish succeeds. When it comes to my site, I want to understand how it works.

    Putting in the time isn't a problem for me, I have been up all night reading and trying,... and this isn't the first time I have lost sleep for this cause, and no doubt it won't be the last.

    Yii offers a working basic application upon install, what better example would there be? MicroSoft offered FrontPage for people who didn't know html and it is what I used for my first site. It was through the fixxing of tons of errors, guided by the members of this forum, which helped me to gain the knowledge which I can now apply to Notepad and create.

    This is my second Yii application. The first one was simple, this one is just a little more complex and perhaps I will build onto this one with even more complexity as time goes on. Perhaps scheduling of jobs is something to look forward to.

    Thanks for stopping by, your comments were the push I needed just as I was getting discouraged!

  3. #13
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,788
    Okay, so that didn't work. Can we see the generated form for comparison to the PHP above? Might be able to take another blind stab at it... (JK). I'm learning too, but don't have Yii in front of me.

    Frameworks are like a contractors job box. They're not just tools for one trade, but for every trade. Your framework has helpers of all sorts that are just waiting to be called up. They won't do the logic, though, which is where you're stuck right now, @Clicken. Trouble for me, and possibly others is that we don't have the toolbox at our disposal and are seeing the logic followed through our own methods, not neatly threaded to the framework. I can see perfectly the logic and methodology I would apply, but that's from scratch, start to finish.

    That having been said, I still think we can help you once we see a little more of what you're working with. We may have some useful pointers that help you tie the pieces together, logic (yours) and 'primitives' (the frameworks toolbox).

  4. #14
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    After refining my search I found someone trying to do similar... and yes it is a Javascript solution.
    http://www.yiiframework.com/forum/in...-dropdownlist/

    I am going to change the Job Class selection from hard coded to generated from the db table, like the ServiceRequestSelection, now that I have learned to do it. (My 3 yr old grandson is with me today which will slow me down)
    Code:
    <div class="form">
    
    <form id="service-request-form" action="/msj/index.php/ServiceRequest/create" method="post">
    <div id="service-request-form_es_" class="errorSummary" style="display:none"><p>Please fix the following input errors:</p>
    <ul><li>dummy</li></ul></div>
    <div id="columncont">
    <div id="lwrap">
    
    	<div class="twocolbox">
    
    		<!--  step one class and pctype -->
    		<div class="detailbox">
    <p><span class="step">1.</span> Type of Service</p>
    			<div class="row">
    <p>Your location or leave it with us?<br />
    			<label for="ServiceRequest_className" class="required">Service Location <span class="required">*</span></label>			<select name="ServiceRequest[className]" id="ServiceRequest_className">
    <option value="">Select Job Type</option>
    <option value="1">On-Site</option>
    <option value="2">Drop-Off</option>
    </select></p>
    			<div class="errorMessage" id="ServiceRequest_className_em_" style="display:none"></div>			</div>
    
    			<div class="row">
    <p>What type of computer needs service?<br />
    			<label for="ServiceRequest_pcType">PC Type</label>			<select name="ServiceRequest[pcType]" id="ServiceRequest_pcType">
    <option value="">Select PC Type</option>
    <option value="MAC">MAC</option>
    <option value="DELL">DELL</option>
    <option value="Other">Other</option>
    </select></p>
    			<div class="errorMessage" id="ServiceRequest_pcType_em_" style="display:none"></div>			</div>
    		</div><!-- eof detailbox stepone -->
    	</div><!-- eof twocolbox -->
    
    	<div class="twocolbox">
    
    		<!-- detailbox steptwo -- selection listbox -->
    		<div class="detailbox">
    <p><span class="step">2.</span> Which Services Do You Need?</p>
    			<div class="row">
    			<label for="ServiceRequest_selection" class="required">Service Selection <span class="required">*</span></label><select multiple="multiple" style="width:auto; height:138px;" size="4" name="ServiceRequest[selection][]" id="ServiceRequest_selection">
    <option value="">Select All that Apply</option>
    <option value="">shift-key select multiple</option>
    <option value="1">1. Consultation</option>
    <option value="2">2. Diagnostics</option>
    <option value="3">3. Hook-up computer</option>
    <option value="4">4. Computer Set-up</option>
    <option value="5">5. Operating System Install</option>
    <option value="6">6. Software Install</option>
    <option value="7">7. Hardware Install</option>
    <option value="8">8. Virus Removal</option>
    <option value="9">9. Back-up</option>
    <option value="10">10. Restore</option>
    <option value="11">11. System Cleaning</option>
    <option value="12">12. Device Hook-up</option>
    <option value="13">13. Network System Configuration</option>
    <option value="14">14. Network User Configuration</option>
    <option value="15">15. Network Wireless Internet</option>
    <option value="16">16. Network VOIP Phone Adapters</option>
    <option value="17">17. Network Wired internet Access</option>
    <option value="18">18. Media Center Set-up</option>
    <option value="19">19. Network Media Center</option>
    </select>			<div class="errorMessage" id="ServiceRequest_selection_em_" style="display:none"></div>
    			</div>
    			<div class="spaceten"></div>
    		</div><!-- eof detailbox steptwo -->
    	</div><!-- eof twocolbox -->
    
    	<div class="spaceten"></div>
    
    	<!-- step three visitor info -->
    	<div class="twocolbox">
    		<div class="detailbox">
    <p><span class="step">3.</span> Your Contact Information</p>
    			<div class="row">
    			<p><label for="VisitorInfo_firstName" class="required">First Name <span class="required">*</span></label>			<input size="20" maxlength="20" name="VisitorInfo[firstName]" id="VisitorInfo_firstName" type="text" />			<div class="errorMessage" id="VisitorInfo_firstName_em_" style="display:none"></div></p>
    			</div>
    
    			<div class="row">
    			<p><label for="VisitorInfo_lastName" class="required">Last Name <span class="required">*</span></label>			<input size="20" maxlength="20" name="VisitorInfo[lastName]" id="VisitorInfo_lastName" type="text" />			<div class="errorMessage" id="VisitorInfo_lastName_em_" style="display:none"></div></p>
    			</div>
    
    			<div class="row">
    			<p><label for="VisitorInfo_phone" class="required">Phone <span class="required">*</span></label>			<input size="20" maxlength="30" name="VisitorInfo[phone]" id="VisitorInfo_phone" type="text" />			<div class="errorMessage" id="VisitorInfo_phone_em_" style="display:none"></div></p>
    			</div>
    
    			<div class="row">
    			<p><label for="VisitorInfo_zip" class="required">Zip <span class="required">*</span></label>			<input size="10" maxlength="10" name="VisitorInfo[zip]" id="VisitorInfo_zip" type="text" />			<div class="errorMessage" id="VisitorInfo_zip_em_" style="display:none"></div></p>
    			</div>
    			<div class="row">
    			<p><label for="VisitorInfo_email" class="required">Email <span class="required">*</span></label>			<input size="20" maxlength="60" name="VisitorInfo[email]" id="VisitorInfo_email" type="text" />			<div class="errorMessage" id="VisitorInfo_email_em_" style="display:none"></div></p>
    			</div>
    		</div><!-- eof detailbox step three -->
    	</div><!-- eof twocolbox -->
    
    	<!-- step four comments send -->
    	<div class="twocolbox">
    		<div class="detailbox">
    <p><span class="step">4.</span> Questions or Comments?</p>
    			<div class="row">
    			<p><label for="ServiceRequest_comments">Comments</label>			<textarea rows="5" cols="30" name="ServiceRequest[comments]" id="ServiceRequest_comments"></textarea>			<div class="errorMessage" id="ServiceRequest_comments_em_" style="display:none"></div></p>
    
    <p class="note">Fields with <span class="required">*</span> are required.</p>
    			</div>
    
    
    		<div class="row">
    		<label for="ServiceRequest_verifyCode">Verify Code</label>		<div>
    		<img id="yw0" src="/msj/index.php/serviceRequest/captcha?v=4fe9f0d2520a0" alt="" />		<input name="ServiceRequest[verifyCode]" id="ServiceRequest_verifyCode" type="text" />		</div>
    		<div class="hint">Please enter the letters as they are shown in the image above.
    		<br/>Letters are not case-sensitive.</div>
    		<div class="errorMessage" id="ServiceRequest_verifyCode_em_" style="display:none"></div>	</div>
    	
    
    	<!-- hidden fields -->
    			<div class="row">
    
    			<input name="VisitorInfo[submitDate]" id="VisitorInfo_submitDate" type="hidden" />			<input size="5" maxlength="5" name="ServiceRequest[hrRate]" id="ServiceRequest_hrRate" type="hidden" />			<input size="5" maxlength="5" name="ServiceRequest[totalEstTime]" id="ServiceRequest_totalEstTime" type="hidden" />			<input size="5" maxlength="5" name="ServiceRequest[jobEst]" id="ServiceRequest_jobEst" type="hidden" />			</div>
    	<!-- eof hidden fields -->
    
    
    
    			<div class="row buttons">
    			<input type="submit" name="yt0" value="Send Request" />			</div>
    
    		</div><!-- eof detailbox -->
    	</div><!-- eof twocolbox" -->
    <div class="spaceten"></div>
    <div><p>NOTE: The Mr. Screen Jeans<sup class="mark">TM</sup> online Service Request form is intended only as an estimate of service charges. Actual service charges may vary depending on factors which we are unaware of and out of our control.</p></div>
    
    </div><!-- eof lcolwrap -->
    
    <div id="rsidewrap">
    	<div class="spaceten"></div>
    <div id="estdisplay">
    <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">Item</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>
    
    </div><!-- eof estdisplay -->
    </div><!-- eof rcolwrap -->
    <div class="spaceten"></div>
    
    </div><!-- eof columncont -->
    </form>

  5. #15
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    UPDATE: The Job Class selection has been changed and is now populated from the database table. :clapping hands:

    The javascript from the link above has been successfully applied to the Service Selection, however, it displays multiple selected items in one line so that they all run together. Although I will not use it as it is, it was a good exercise for applying scripts. It gave me some trouble but I figured it out.
    Code:
    <?php Yii::app()->clientScript->registerScript(
          '#item_selection_box', '
       $("#ServiceRequest_selection").change(function() {
          var content = $("#ServiceRequest_selection option:selected").text();
          $("#item_selection_box").text(content);
       }); ');
    
    ?>

  6. #16
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    After more reading and contemplation I think this can work out so that all of the info needed for javascript to work will be on the page.

    I am going to change the job class selection back to a hard coded selection so that the select value will be the hrRate. It is a compromise so that I can move forward.

    The service items can be changed back to checkbox selections, some of them can be combined in order to save space. I could group them into catagories then apply the jQuery for the visitor to expand the section which is needed. The timeEstimate can be pulled into the row with the appropriate checkbox item.

    I will report back when finished with these changes...
    Last edited by weegillis; 06-30-2012 at 04:08 AM. Reason: repair typo

  7. #17
    Administrator weegillis's Avatar
    Join Date
    Oct 2003
    Posts
    5,788
    Just wondering, is <div class="spaceten"></div> actually a spacer gif? We see quite a few of those in the HTML template. Do they hold any content? Could you achieve the same spacing objective with a pseudo element, and not require the additional redundant div markup? It's a thought (a little removed from your logic question, but still part of the optimization process).

    I'm anxious to see your results. Do please let us have a peek at your test page?
    Last edited by weegillis; 06-30-2012 at 04:08 AM. Reason: took too long to update

  8. #18
    WebProWorld MVP williamc's Avatar
    Join Date
    Jul 2003
    Location
    On a really big hill in Kentucky
    Posts
    4,721
    Clicken: In a nutshell here is the process you want to follow (I am assuming you want to learn to do it yourself, so I am not pasting the coded solution):

    1. as the page loads initially you want to populate the $jobEst field at zero. this field should be inside a div that has a unique 'id='
    2: you have javascript (in the case of yii: jQuery based) that reads the select box's 'id=' to see when it is changed by a user.
    3: the jQuery code (javascript) will see the new value selected and send that via ajax to a backend script (likely php) and get a reply with the new jobEst number. (note: if a number greater than 0 was in the jobEst value, then jQuery has to send that along for calculation to be added to the new number selected also.)
    4: jQuery will repopulate the jobEst div with the new value.

    wash, rinse, repeat as required
    William Cross
    Web Development by Those Damn Coders
    Firearm Friendly Websites because our constitution matters

  9. #19
    WebProWorld MVP williamc's Avatar
    Join Date
    Jul 2003
    Location
    On a really big hill in Kentucky
    Posts
    4,721
    here is something to chew on tho, and it should work fine within Yii

    Code:
    /* watch for changes on <div id="ServiceRequest_selection"> */
    $("#ServiceRequest_selection").change(function() {
        /* make an ajax call to get our calculation to ajax/getCalculation.php */
        $.ajax( {
          type: "POST",
          url: 'ajax/getCalculation.php',
          key: "id",
          success: function(response) {
            /* if we got a response change the content in div id="resultField"></div> to the response */
            $('#resultField').html(response);
          }
        });
        return false;
      } );
    Last edited by williamc; 06-30-2012 at 10:57 AM.
    William Cross
    Web Development by Those Damn Coders
    Firearm Friendly Websites because our constitution matters

  10. #20
    WebProWorld MVP Clicken's Avatar
    Join Date
    Jul 2004
    Posts
    327
    Quote Originally Posted by WG
    Could you achieve the same spacing objective with a pseudo element, and not require the additional redundant div markup?
    Yes, I will correct that bad habit..

    Quote Originally Posted by WG
    I'm anxious to see your results. Do please let us have a peek at your test page?
    I hope you are not holding your breath! I said I was slow... and reconsidering the change because it causes much more problems. I haven't been able to work as much as I wanted,... Friday was my B-day so the kids kept me busy. Saturday was spent cleaning up from the mess they made on Friday. And now someone has asked for my help with a template which I would say no, except they are a dear friend and need help, URGENTLY. <sigh - don't we all.>

    I did however get to look into a little bit of the AJAX, since William has thrown that into the mix. It looks like jQuery. What I have gathered from a brief look into each, the difference appears to be that JQuery deals with the page elements and AJAX deals with server files.

    I tried to implement the code WC posted, but of course nothing happened...

    Code:
    <?php Yii::app()->clientScript->registerScript(
    	'#visitorSelected','
    	$("#ServiceRequest_selection").change(function()
    	{
    	    $.ajax( 
    		{
          			type: "POST",
          			url: "ajax/getCalculation.php",
         			key: "id",
          			success: function(response)
    			{
    
           			 $("#resultField").html(response);
          			}
        		});
       		 return false;
     	 } ');
    ?>
    I removed the other code which put the selected items in the display table thinking that may have interferred, but it still didn't show any change. I assigned the script a 'uniqueID' #visitorSelect, as instructed by the Yii docs. I created a div #resultField... hmmm. Guess I need to chew on that one a bit more... Oh, could it be that the values are missing in that ServiceRequestSelection. Well, there are the itemId numbers. The selection is a CONCATINATION of the itemID and the itemDescription, only the itemId numbers are reflected in the db table, not the description... still chewing.

    I searched to see what the ajax/getCalculation was about however I didn't find an exact answer, but of course my time has been interrupted by needy people!
    Quote Originally Posted by williamc
    1. as the page loads initially you want to populate the $jobEst field at zero. this field should be inside a div that has a unique 'id='
    2: you have javascript (in the case of yii: jQuery based) that reads the select box's 'id=' to see when it is changed by a user.
    3: the jQuery code (javascript) will see the new value selected and send that via ajax to a backend script (likely php) and get a reply with the new jobEst number. (note: if a number greater than 0 was in the jobEst value, then jQuery has to send that along for calculation to be added to the new number selected also.)
    4: jQuery will repopulate the jobEst div with the new value.
    3. The 'backend script' ... So, if I understand correctly, in Yii that would be something relating to Component. http://www.yiiframework.com/doc/api/1.1/CComponent
    Quote Originally Posted by Yiidoc
    CComponent implements the protocol of defining, using properties and events. ... An event is defined by the presence of a method whose name starts with 'on'. The event name is the method name. When an event is raised, functions (called event handlers) attached to the event will be invoked automatically.
    So the 'onSelect' of an item could trigger a function to get the timeEstimate of the item from the db table?

    <deap breath> I think I can, I think I can, I think I can...

Page 2 of 3 FirstFirst 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
  •