Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Help with if loop

Options
  • 18-01-2009 12:14am
    #1
    Registered Users Posts: 3,875 ✭✭✭


    EDIT -- Sorry I should have said in title this is for a mysql database and I am writing the code in php and html for the webpage.


    Hello I want to create an if loop so people can only sign up for an event if its not full

    this is the code to see the max no of particmy code for finding the max no of participants

    <?php echo $row_chosencourse;

    and this is how I find the total amount already signed up

    <?php echo $totalRows_alreadyregisteres ?>


    I want an if loop basically where it is

    <?php
    if ( <?php echo $totalRows_alreadyregisteres ?> < <?php echo $row_chosencourse; ) {
    echo "hi";
    }
    ?>


    How do I do this properly?
    is it possible

    is it possible if I put the values in textfields first and if so how?
    or can you create variables in html?

    cheers for any help,
    thank you.


Comments

  • Registered Users Posts: 927 ✭✭✭decob


    You know you're outputting to the screen within your 'loop'

    should be...
    <?php
    if ( $totalRows_alreadyregisteres <= $row_chosencourse['Max Student Number'] ) {
    echo "hi";
    }
    ?>
    


  • Closed Accounts Posts: 8,866 ✭✭✭Adam


    +1

    you need to brush up on your syntax, once you have opened the php braces (<?php) you don't need to open them again.

    after that, you're only comparing the variables behind the scene, you don't need to echo them to do this, echo is for outputting data to the web page.


  • Closed Accounts Posts: 18,163 ✭✭✭✭Liam Byrne


    There's also no such thing as an "if loop".

    The if statement does one thing or another, once.

    Think of it as going left or right at a junction; you only do one and you don't go back to do the other.

    if ($left_road_blocked) {
    go left;
    } else {
    go right;
    }

    So for your app...

    if ( $totalRows_alreadyregisteres < $row_chosencourse ) {
    // code to add the record to the database goes here
    echo "Thank you for registering for this course";
    } else {
    echo "Sorry, that course is full.";
    }

    As stated above, the "echo" is what appears in the viewer's browser window, so that should be a meaningful statement to tell them what happened.


  • Registered Users Posts: 3,875 ✭✭✭ShoulderChip


    cheers for all the help,

    I knew the syntax was wrong but every thing I tried to change it was not working out.

    it seems a bit silly now

    when I had it right I was doing < and not <= so I was never going to get there.


Advertisement