SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class not working - New at it !

    Hi Ppl

    I have been programming php for a little while now. I'm not particularly great but I can get a job done.

    I thought I would try my hand at a class as someone asked me to create a survey. Now I know I could go and get a million scripts to do this but I wanted to use the opportunity to get me head around classes.

    I ahve the following but it will not work. Now maybe I am coming at it all wrong

    PHP Code:

     
    class survey {
            var 
    $question;
            var 
    $possible_answers 5;
            var 
    $question_number;
            
            
            function 
    createrow($question$possible_answers,$question_number) {
                
                
    $val "
                <tr>
                <td>
    $question_number</td><td>$question</td>
                "
    ;
                for ( 
    $i=1$i=5$i++) {
                
    $val.="<td><input name=\"Q$question_number\" type=\"radio\" value=\"$i\"></td>";
    *****
    ERROR RELATES TO THIS LINE***            
    }
    *****
    ERROR RELATES TO THIS LINE***            

                
    $val.="</tr>";
                return 
    $val;
            }
            function 
    createtable() {
                
    $val="<table>";
                
    $val .= $this->createrow($this->question$this->possible_answers,$this->question_number);
                
    $val .="</table>";
                echo 
    $val;
            } 
    With the call of
    PHP Code:
    include('survey.class.php');
    $table= new survey;
    $table->question='How big am I';
    $table->question_number=1;
    $table->createtable(); 
    But it is not working all i get is.
    Fatal error: Maximum execution time of 30 seconds exceeded in C:\www\webroot\mikeacton\functions\survey.class.php on line 17

    I dont know where I am going wrong. Any ideas please?/

    Thanks all.

    Keith

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Hi Keith,

    Your for loop is the issue, the middle segment is the conditional for another iteration and the one you posted always evaluates to true.

    Try:-
    PHP Code:
    for($i 0$i 5$i++)
    {
        
    #code

    *you see, it keeps looping whilst $i is less than 5.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Addict kivison's Avatar
    Join Date
    Dec 2004
    Location
    Whitley Bay, Tyne & Wear, UK
    Posts
    246
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Silverbullet

    Thank you!

    Cracked it!

    Couldnt see the wood for the trees on that one.

    You're a diamond North East Geeza!

    No doubt there will be more questions.

    Keith

  4. #4
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Ha, thanks.

    I'll keep an eye 'oot. As they say.
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.


Bookmarks

Posting Permissions

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