Page 4 of 6 FirstFirst ... 23456 LastLast
Results 31 to 40 of 58

Thread: IF / THEN statement using data from MySQL

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

    Default

    Hi,

    Thanks again for your reply - I agree that you both have interacted.

    The effiecient change has been applied and tested. That is really an efficiency change to something that already worked.

    I am not aware of any other example that has been presented in terms of script - unless I am missing something.

    My question - which query do I use and where do I put it in order for the counting to happen and effect the OPEN/ CLOSED status - when using the script below that showed your effieciency changes?

    Regards
    Rob

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

    Default

    This (from my post #19):
    PHP Code:
    // name of tournament you wish to count entries from
    // maybe from a form entry?
    $tournament '';

    //  count the total entries with that tournament name
    $c mysql_query("SELECT count(*) from `_Form_Nr_3` WHERE `I_wish_to_play` = '$tournament'"); 
    gets the count from the database. You have to pass which tournament you want to count in the $tournament variable (for example, $tournament = 'Glendower'; ).

    then,
    PHP Code:
    //  set "open" or "closed" based on that number
    $openORclosed $c >= 80 'Closed' 'Open'
    . This would have to be done before you get to the OPEN / CLOSED section, but otherwise, it's not critical where it goes.

    I hope that gets you going in the right direction.

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

    Default

    Thanks very much for the reply.

    I will now try it

    Regards
    Rob

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

    Default

    If the tournament name is not static it should be escaped as well.

    PHP Code:
    mysql_real_escape_string($tournament); 
    Do that between the $tournament declaration and the query.
    Corrections to my coding/thoughts welcome.

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

    Default

    Hi Guys,

    I have made changes like this

    PHP Code:
    <tr class="alt2">
    <td>GLENDOWER</td>
    <td>27 FEBRUARY 2011</td>
    <td>?</td>
    <?php
    // name of tournament you wish to count entries from
    // maybe from a form entry?
    $tournament 'GLENDOWER - 27/02/2011';
    //  count the total entries with that tournament name
    $c mysql_query ("SELECT count (*) from `_Form_Nr_4` WHERE `I_wish_to_play` = '$tournament'");
    //  set "open" or "closed" based on that number
    $openORclosed $c >= 80 'Closed' 'Open'
    <
    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 - Glendower - 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>
    ';
    ?>
    </tr>
    and it has no effect other than produce a White screen.

    However if I do the following , I am closer to achieving my desired result.

    PHP Code:
    <tr class="alt2">
    <td>GLENDOWER</td>
    <td>27 FEBRUARY 2011</td>
    <td>?</td>
    <?php
    // name of tournament you wish to count entries from
    // maybe from a form entry?
    $tournament 'GLENDOWER - 27/02/2011';
    //  count the total entries with that tournament name
    $c mysql_query ("SELECT count (*) from `_Form_Nr_4` WHERE `I_wish_to_play` = '$tournament'");
    if(
    $num_rows <= 13){
    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 - Glendower - 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>
    '
    ;
    }
    ?>
    </tr>
    If I change the value in the later case of 13 to 80 then the counting function does not seem to work.

    I have changed the value of 80 to 13 in this instance as I have already loaded 12 members. Giving me a live sample to work with.

    I have also put the 'tournament' name as it appears in the database under the field 'I_wish_to_play'

    It would be great if you guys can see what is the difference and advise?


    Regards
    Rob

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

    Default

    Two things.

    In your first code example, you have a typo. count (*) should be count(*) (with no space!). That's causing an error, and your query is returning false.

    In your second code example, you're making a comparison with an unset variable: $num_rows has no value at all (at least, it's not set in this example).

    in any case, I left out a line in my previous example: you need to fetch the result from the query before you make the comparison. Sorry for the confusion.
    PHP Code:
    $c mysql_query ("SELECT count(*) from `_Form_Nr_4` WHERE `I_wish_to_play` = '$tournament'"); 
    // add these two lines here:
    $c mysql_fetch_row($c);
    $c $c[0];
    // these lines take the result (a mysql resource)
    // and turn it into an array - something we can actually use
    // in php. The entry count is in the first index ( index 0 ).
    $openORclosed $c >= 80 'Closed' 'Open'

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

    Default

    Hi Adrian,

    I have tried your changes
    PHP Code:
    <tr class="alt2">
    <td>GLENDOWER</td>
    <td>27 FEBRUARY 2011</td>
    <td>?</td>
    <?php
    // name of tournament you wish to count entries from
    // maybe from a form entry?
    $tournament 'GLENDOWER - 27/02/2011';
    //  count the total entries with that tournament name
    $c mysql_query ("SELECT count(*) from `_Form_Nr_4` WHERE `I_wish_to_play` = '$tournament'");
    // add these two lines here:
    $c mysql_fetch_row($c);
    $c $c[0];
    // these lines take the result (a mysql resource)
    // and turn it into an array - something we can actually use
    // in php. The entry count is in the first index ( index 0 ).
    $openORclosed $c >= 10 'Closed' 'Open'
    <
    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 - Glendower - 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>
    ';
    }
    ?>
    </tr>
    This however causes the page to appear blank.

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

    Default

    You can't have html in the php unless you are echoing it. The simplest thing to do would be to use this...

    PHP Code:
    <tr class="alt2">
    <td>GLENDOWER</td>
    <td>27 FEBRUARY 2011</td>
    <td>?</td>
    <?php
    // name of tournament you wish to count entries from
    // maybe from a form entry?
    $tournament 'GLENDOWER - 27/02/2011';
    //  count the total entries with that tournament name
    $c mysql_query ("SELECT count(*) from `_Form_Nr_4` WHERE `I_wish_to_play` = '$tournament'");
    // add these two lines here:
    $c mysql_fetch_row($c);
    $c $c[0];
    // these lines take the result (a mysql resource)
    // and turn it into an array - something we can actually use
    // in php. The entry count is in the first index ( index 0 ). 
    $openORclosed $c >= 10 'Closed' 'Open';
    echo 
    "<td>";
    if (
    $openORclosed != 'Closed') {
    ?>
    <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 - Glendower - 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">
    <?php 
    } else {
    echo 
    $openORclosed;
    }
    ?>
    </td>
    </tr>
    Corrections to my coding/thoughts welcome.

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

    Default

    Thanks I will try this

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

    Default

    Hi Folks,

    Not much success in trying this - unfortunatly

    Regards
    Rob

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
  •