Page 1 of 6 123 ... LastLast
Results 1 to 10 of 58

Thread: IF / THEN statement using data from MySQL

  1. #1
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default IF / THEN statement using data from MySQL

    HI Folks,

    I am in need of some help.

    I have data in MySQL and using that data wish to create an IF /THEN statement.

    I have players entering a golf tournament and when the number of entreis reach 80 I wish for a word to change from OPEN to CLOSED.

    I do not have experiance in PHP and thus am in need of help

    Regards
    Rob

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Based on what you've posted...

    PHP Code:
    If ($entries => 80) {
    echo 
    "Closed";
    } else {
    echo 
    "Open"

    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi Chris,

    Thanks for the reply.

    Thats seems quite simple enough.

    The challenge that I have is that I need for the entry form to count to "80" on 30 differing tournaments.

    The number is in MySQL and the place I want the script provided lies on another page.

    I think it sounds more complicated than it is - for guys that know.

    I look forward to your reply

    Regards
    Rob

  4. #4
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    I don't know how your DB is currently set up or what your current code looks like. You need to provide more data in your posts.

    Your DB should be set up something like this I'd assume. One table for the tournaments and the status of it. In another table call it users_to_tournaments and that will relate a users account with the tournament they registered for. The third table should already be set up, the users.

    Table Tournaments
    Tournament_ID#, Name, Users_registered, Date, Status
    30, Some_Tournament_Name, 80, Date 10/16/2010, Closed

    Table users_to_tournaments
    id, Tournament_id, user_id, registered_order
    1, 30, 290, 80

    Users
    user_id, first_name, last_name, email
    30, john, whatever, email@domain.com
    Last edited by bluewalrus; 10-16-2010 at 10:14 PM.
    Corrections to my coding/thoughts welcome.

  5. #5
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    If your DB setup is similar to what bluewalrus guesses, then you shouldn't have a problem counting on any tournament you like - you just need to identify which tournament you wish to count. That will determine how you select the entries that you count.

    PHP Code:
    $tID //  int: id number of tournament to count entries from; from a POST variable, or something
    $sql "SELECT count(*) FROM `users-to-tournament` WHERE `tournament-id` = $tID";
    $result mysql_query($sql); 
    (BTW, if all you're doing is assigning a status message, you can use a "shorthand" version of what bluewalrus posted:
    $status = $number_of_entries >= 80 ? 'Closed' : 'Open';
    )

    If we're missing what your problem is, please let us know.

  6. #6
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi guys,

    I have done something like this which will help on this page

    PHP Code:
    <tr class="alt">
    <td>KEMPTON PARK</td>
    <td>05 JANUARY 2011</td>
    <td>?</td>
    <?php
    if($num_rows >= 80){
    echo 
    '<td><font style="font-size:11px" color="Red" face="Arial">CLOSED</td>
    <td>&nbsp;</td>'
    ;
    }
    else {
    echo 
    '<td><b><font style="font-size:11px"  color="Blue" face="Arial">OPEN</b></td>
    <td><form action="https://www.payfast.co.za/eng/process" method="post"> 
    <input type="hidden" name="cmd" value="_paynow"> 
    <input type="hidden" name="receiver" value="junior@hayesgolf.co.za"> 
    <input type="hidden" name="item_name" value="Payment - Kempton Park - Glacier Series"> 
    <input type="hidden" name="item_description" value="payment"> 
    <input type="hidden" name="amount" value="120.00"> 
    <input type="hidden" name="return_url" value="http://www.gnjgf.co.za/entryform.php"> 
    <input type="hidden" name="cancel_url" value="http://www.gnjgf.co.za/Glacier_Main.html"> 
    <input type="submit" style="width:66px;height:20px;background-color:#B5CCE4;font-size:10px; font-family: arial, sans-serif;" value="PAY NOW"> 
    </td>

    The counting of the tournament entries is done on another page with the counting seen in the left hand table

    My challenge is now the following how to ge the two to talk with each other.

    I have a custom html but for some reason I am being limited now to the inputs in order to make the file complete.

  7. #7
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    I have some additional information that looks like this - and this information producess part of a table that shows the folk that have netered per tournament.

    PHP Code:
    <?php 

    $connect 
    mysql_connect("localhost""e****a_r***t""r****h") or 

    die (
    "Hey loser, check your server connection."); 

    mysql_select_db("eghfya_Members"); 

    $quey1="select * from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC "
    $result=mysql_query($quey1) or die(mysql_error()); 


    ?> 
    <!------------------------------------------------------------------> 
    <!           THIS SECTION CHANGES WHAT THE TABLE LOOKS LIKE         > 
    <!------------------------------------------------------------------> 
    <table border=1 width="85%" bordercolor="#D3E2FE" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" style="font-size:11px" cellspacing=0> 
    <!------------------------------------------------------------------> 
    <!                  THIS SECTION CHANGES THE MAIN HEADING           >  
    <!------------------------------------------------------------------> 
    <caption><b><font style="font-size:20px" color="#376091" face="Arial"> 
    </font><b><caption> 
    <!-------------------------------------------------------------------> 
    <!    THIS SECTION FETCHES THE INFORMATION FROM THE MYSQL TABLE      >   
    <!-------------------------------------------------------------------> 
    <?php 
    $counter 
    = array(); 
    $last_wish_to_play ""
    $firstNAsAString ""
    while(
    $row=mysql_fetch_array($result)){ 

    //---------------------------------------------------------------------------------------------------- 
    // THIS SECTION ADDS 3 EMPTY LINES IF THERE IS A SPLIT BUT ONLY AFTER SOME RECORDS HAVE BEEN DISPLAYED 
    //---------------------------------------------------------------------------------------------------- 
    if($i AND $row['i_wish_to_play'] != $last_wish_to_play

    echo 
    '<tr> 
    <td colspan="3">&nbsp;</td> 
    </tr>'


    //------------------------------------------------------ 
    //            THIS SECTION ADDS HEADINGS                 
    //------------------------------------------------------ 
    if ($row['i_wish_to_play'] != $last_wish_to_play) { 
    echo 
    '<tr> 
    <td colspan="3" align="center" bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>'
    .$row['i_wish_to_play'].'</b></font></td> 
    </tr>'

    echo 
    '<tr> 
    <td bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>FULL NAME</b></font></td> 
    <td align="center" bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>HANDICAP</b></font></td> 
    <td align="center" bgcolor="#376091"><font style="font-size:11px" color="#FFFFFF" face="Arial"><b>CELL NUMBER</b></font></td> 
    </tr>'



    echo 
    '<tr><td bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">'
    echo 
    '<option value="'.strtoupper($row['surname']).', '.strtoupper($row['name']).'">'.strtoupper($row['surname']).', '.strtoupper($row['name']).'</option>'

    echo 
    '</td><td align="center" bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">'
    echo 
    $row['my_handicap_is']; 

    echo 
    '</td><td align="center" bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">'
    echo 
    $row['cell_phone']; 

    if(
    $row['i_wish_to_play'] != $last_wish_to_play

    // the first n words to extract 
    $n 5
    // extract the words 
    $words explode(" "$row['i_wish_to_play']); 
    // chop the words array down to the first n elements 
    $firstN array_slice($words1$n-1); 
    // glue the 3 elements back into a spaced sentence 
    $firstNAsAString implode(" "$firstN); 

    if(!isset(
    $counter[$firstNAsAString])) 
    $counter[$firstNAsAString] = 0
    else 
    $counter[$firstNAsAString]++; 
    $last_wish_to_play $row['i_wish_to_play']; 

    $i++; 
     echo 
    '</td></tr>'



    echo 
    '</table>'

    ?>
    The other part which does the counting looks like this

    PHP Code:
    <!------------------------------------------------------------------> 
    <!                  THIS SECTION CHANGES THE MAIN HEADING           >  
    <!------------------------------------------------------------------> 
    <table> 
    <td colspan="2" width="25%" align="center" bgcolor="#376091"><font style="font-size:12px" color="#FFFFFF" face="Arial"><b>TOTAL ENTRIES</b></font></td> 
    </table> 
    <!--------------------------------------------------------------------> 
    <!  THIS SECTION COUNTS THE ROWS THAT ARE UNIQUE AND PROVIDES RESULT  >   
    <!--------------------------------------------------------------------> 
    <?php 
    echo '<table border=1 bgcolor=#B5CCE4 bordercolor="#FFFFFF" bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" cellspacing=0>'
    foreach(
    $counter as $key => $value

    echo 
    '<tr> 

    <td align="center" width="10%" bgcolor="#B5CCE4"><font style="font-size:12px" color="#000000" face="Arial"><b>'
    .$value.'</b></font></td> 
    <td colspan="2" width="65%" align="center" bgcolor="#B5CCE4"><font style="font-size:10px" color="#000000" face="Arial">'
    .$key.'</font></td> 
    </tr>'


    echo 
    '</table>'
    ?>
    My apologies if this is repated in another thread but hopefully it all comes together here and the other thread could be removed.

    The idea is to get the information determind in this second part - which really counts the number of participants to be effective in determing the 80th person and thus perform the task as set out in your original suggestion.

    I am sure those that now - like yourself will easily find solution.

    Regards
    Rob

  8. #8
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Where is the checking if the tournament has less than 80 players?

    I also wouldn't use

    select *
    I'd specify the columns needed so you aren't pulling extra information in.
    Corrections to my coding/thoughts welcome.

  9. #9
    Join Date
    May 2007
    Location
    South Africa
    Posts
    175
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Hi,

    I am not worried if there are less than 80 players.

    The limit is 80 as I want the row to perform an action showing"closed" once the limit is reached.

    In terms of the Select * option - I have already done the datbase and thus it would be a rather large task to change right now and I am limited to time unfortunatly.

    Regards
    Rob

  10. #10
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Okay, if there are less than 80 than allow registration else closed or are you trying to achieve something else?

    The select * is in your query string

    PHP Code:
    $quey1="select * from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC "
    to

    PHP Code:
    $quey1="select surname, i_wish_to_play  from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC "
    add any other columns you need. Not sure if mysql requires the '' around columns.
    Corrections to my coding/thoughts welcome.

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
  •