Log in

View Full Version : IF / THEN statement using data from MySQL



Rob (SA)
10-16-2010, 11:57 AM
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

bluewalrus
10-16-2010, 07:20 PM
Based on what you've posted...



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

Rob (SA)
10-16-2010, 08:44 PM
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

bluewalrus
10-16-2010, 10:02 PM
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

traq
10-17-2010, 03:42 PM
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.


$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.

Rob (SA)
10-17-2010, 05:29 PM
Hi guys,

I have done something like this which will help on this page (http://www.gnjgf.co.za/Glacier_payfast.php)


<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 (http://www.gnjgf.co.za/Glacier_watflip.php) 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.

Rob (SA)
10-24-2010, 06:20 AM
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

$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 > 0 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($words, 1, $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


<!------------------------------------------------------------------>
<! 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

bluewalrus
10-24-2010, 03:02 PM
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.

Rob (SA)
10-24-2010, 03:45 PM
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

bluewalrus
10-24-2010, 04:03 PM
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


$quey1="select * from _Form_Nr_3 ORDER BY `i_wish_to_play` ASC, `surname` ASC ";

to


$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.

Rob (SA)
10-24-2010, 05:13 PM
Hi,

The query should be against each tournaments name "I_wish_to play" is the field heading listing the tournament name.

Players can enter more than one event but only enter an event once.

Once the specific tournament has reached a field size of 80 - the function "CLOSED" should effect.

The second script is theone that does the counting per tournament and I thought this would be more suitable?

Your ideas are welcomed - Thank you

traq
10-24-2010, 05:46 PM
... Not sure if mysql requires the '' around columns.

they're not single quotes ( ' ), they're backtics ( ` ). They tell MySQL that the value is a proper name of a column or table, and not a keyword (e.g., if -for some reason- you had a column named SELECT or LIMIT:
"SELECT select FROM table WHERE limit=2 LIMIT 1";
-- doesn't work
SELECT `select` FROM `table` WHERE `limit`=2 LIMIT 1";
-- works fineof course, a better solution is to not use keywords as column names, but it's good practice... I suppose it could happen by accident sometime, if a new keyword were introduced, or something).

Rob, I'm having a hard time following some of this. Can you show me the structure (column names, types, description of info contained) of your database table?

Rob (SA)
10-24-2010, 06:28 PM
Hi,

Thanks for the reply.

I have treid to create a zip file but the size is 411Kb of the structure of my MYSQL table.

Not sure of another method I can use here.

Regards
Rob

Rob (SA)
10-24-2010, 06:37 PM
Hi Folks,

The form and the counter works fine as can be veiwed on this page (http://www.gnjgf.co.za/Glacier_watflip.php)

What I need is for a script that will recognise the value (number) calculated on the table seen left on the link presented above.

This page is dynamic in nature however the page (http://www.gnjgf.co.za/Glacier_payfast.php) that requires this script is static in nature.

I hope this provides some clarity.

Regards
Rob

bluewalrus
10-24-2010, 06:53 PM
We need to know the names of the tables being used and the columns/relation between them.

Thanks Traq didn't know the exact usage of the `s. I don't name my tables or columns with keywords or at least haven't yet.

Rob (SA)
10-24-2010, 07:05 PM
Hi,

There is only one table being used . . ."_Form_Nr_3"

This form comprises of all information submitted from this page (http://www.gnjgf.co.za/Glacier_entryform.php)

The field headings are as per the entry form.

"Handicap" is the Handicap of the player
"I_wish_to_play" is the tournament name
"surname" is the surname of the player

The only difference is that the new database will be "_Form_Nr_4"

I hope this helps

bluewalrus
10-24-2010, 08:33 PM
So you have table _Form_Nr_3 which contains the following columns?



Name
Surname
Date of Birth
Cell Phone
Home Phone
Work Phone
Email
SAJGF_Division
Personal_Division
Handicap


Is SAJGF_Division the tournament name?

I think you should redo the table into 3 tables. This layout is going to be hard to work with once you get a lot of data in there unless this is not how it is set up.

Rob (SA)
10-24-2010, 09:38 PM
Hi,

The information you have there is correct.

There is also the option on this form to select a tournament and this appears under the column "I_wish_to_play"

SAJGF_Divison is combobox where the divison the players belongs to resides. There are 13 divisions.

This is set up already and has worked in previous events - the only thing required is the script to get the OPEN and CLOSED function to operate when the number of players for each tournament reaches 80.

The page has been setup and the script will have to be slightly difdferent for each tournament.

If it can be done dynamically then that would be wow but I dont have that much time unfortunatly.

traq
10-24-2010, 11:08 PM
Rob,

Unfortunately, linking to your live pages is not very helpful in this case. All of the PHP and MySQL action is happening on your server, and we can not see any of it from the web.

If you already have a script that counts entries (as seen in the "total entries" box on this page (http://www.gnjgf.co.za/Glacier_watflip.php)), then I'm not sure what the problem is here. Is there some reason you can't use that same code again on your other page?

(I would assume it's something like this)


// 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'");

// set "open" or "closed" based on that number
$openORclosed = $c >= 80 ? 'Closed' : 'Open';

// if there were 80 entries, then $openORclosed would hold the value "Closed"
// if there were fewer, $openORclosed would hold the value "Open".



Thanks Traq didn't know the exact usage of the `s. I don't name my tables or columns with keywords or at least haven't yet.
I generally don't either, though there are some times when it makes a lot of sense for your column to be named "limit" or "set" or something. I think the main reason is forward-compatibility.

Rob (SA)
10-24-2010, 11:28 PM
Hi,

The page wher ethis script is to work is statci and there is quite a bit of reptition.

Folk like yourself would know how I can incorpoarte this count option to the page. I dont have that experiance yet.

If this is the method then I will try it as a query in this page like you suggest but I do need advice.

Ther are 30 tournaments - so am i understanding that this script will then be included to each row that I have created, just with another tournament name in it?


<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>
';
}
?>
</tr>

<tr class="alt2">
<td>GLENDOWER</td>
<td>27 FEBRUARY 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 - 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>

traq
10-25-2010, 02:28 PM
basically, yes.

however, this:
<?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 - 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>
'; would be more efficient like this:

$openORclosed = $num_rows >= 80 ? 'CLOSED' : 'OPEN';

echo '<td><font style="font-size:11px" color="Red" face="Arial">'.$openORclosed.'</td>';

if($openORclosed = 'CLOSED'){
echo '<td>&nbsp;</td>';
}else {
echo '
<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>
';

(BTW, these pages are dynamic, because PHP is creating them with different values depending on the situation. "static" means they never change.)

bluewalrus
10-25-2010, 02:59 PM
If 2 users (a & b) come to your page and load this page when there are 79 users entered you will receive 81 entries for that tournament.

User A loads register page and it loads open because 79 entries are there.
User A loads another tab and googles something.
User B loads register page (while User A is googling) and it loads open because 79 entries are there.
User A submits the forum to become the 80th register.
User B submits and becomes the 81 register.

To stop this you will also need this conditional statement on the submission process page as well, before executing the SQL (insert).

Rob (SA)
10-25-2010, 03:23 PM
Hi Guys,

Thanks for the replies.

In reply - the rush to enter is not too much of a problem as we have a reserve of 16 places built into each event.

The events take place throughout the year and thus if you are 79 or 80 is not going to be to much of a problem.

It is really the masses that always wake up late - to enter that we want to prevent from messing around with a rather structured environment.

Know that we have a more efficient method of rewittting the code - I just need help with the code that will count and then bring about the closed status.

Regards
Rob

traq
10-25-2010, 07:39 PM
... I just need help with the code that will count and then bring about the closed status.

Actually, that's one of the things that's a little confusing - you say you all you need help with is the code for counting the entries, but then in other posts you say you already have the code that counts the number of entries.

I just want to make sure I'm not missing any details about your question that might be important.

Rob (SA)
10-25-2010, 07:48 PM
Hi,

I understand.

On my page (http://www.gnjgf.co.za/Glacier_watflip.php) the script counts the amount of entries that have been received per tournament.

My challenge is I do not know how to do this on the script reflected below.

Secondly the number - which is now 12 is the number that is critical (as the entries grow)

The script I am trying to develop is thus something that will recognise that number and thus cause the OPEN and CLOSED effect.

I hope this helps

traq
10-26-2010, 02:58 AM
so, your desired workflow looks like this:

page 1 counts the number of entries.

page 1 displays the number of entries.

page 2 checks page 1 to get the count.

page 2 uses the count to determine if a particular tournament is open or closed.

??

if so, you should know that it will be complicated, inefficient, and unreliable. page 2 should check the database on its own, and open or close the tournament based on that.

Rob (SA)
10-26-2010, 03:53 AM
Hi,

I will try explain as you have presented it:

Page 2 (http://www.gnjgf.co.za/Glacier_entryform.php) - is the entryform and this is th epage where all data for the player is entered.This information is then sent to the Database (MySQL)


Page 1 (http://www.gnjgf.co.za/Glacier_payfast.php) - is a page where the transaction (OPEN)(CLOSED) is to happen. This is in fact the first page as you will not be able to enter, press the (PAY NOW ) button if the tournament is (CLOSED). This page directs to the Page 2 on selction of the PAY NOW button.

In this link (Page 1) you are normally directed to the payment option (Page 4) and then to the entry form (Page 2). The players will thus select page 1, be directed to the payment system, on payment then only can they enter (Page 2)

Page 3 (http://www.gnjgf.co.za/Glacier_watflip.php) - is a page which shows all the entries and where a script is that currently counts the amount of entries per event and also lists the players that have enterd in alphabetical order per event. No addtional work is required on this page or on page 2. It is only the idea (EXAMPLE) of counting that I have presented to give you guys perhaps some idea of how the counting was happeing , so that you could think a way around the same process to happen on PAGE 1.

The script I am looking for must thus be on page 1 and if it is done using a query then I need to make that query work for 30 differrent instances as their are only 30 tournaments due to method I have adopted here (Page 1) not being effecient, I agree (My knowledge of writting PHP has limited me here)..

I hope this helps

Regards
Rob

traq
10-26-2010, 02:34 PM
I see.

It looks like the answers we've given ought to work with the way you have things set up. Post back if you have any problems. good luck

Rob (SA)
10-26-2010, 02:39 PM
Hi,

Thanks for the replies.

I am in need of help wit the script - the majority of our discussions is to understand what pages do - in context to my project.

Please help with the script if you can

Regards
Rob

traq
10-27-2010, 01:29 AM
Bluewalrus and myself have given you quite a few suggestions and examples. I don't think you're lacking anything, as far a concept or coding goes.

Have you tried out any of our examples? What further questions do you have?

Rob (SA)
10-27-2010, 03:54 AM
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

traq
10-27-2010, 08:25 PM
This (from my post #19):

// 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,


// 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.

Rob (SA)
10-27-2010, 08:32 PM
Thanks very much for the reply.

I will now try it

Regards
Rob

bluewalrus
10-27-2010, 11:47 PM
If the tournament name is not static it should be escaped as well.


mysql_real_escape_string($tournament);

Do that between the $tournament declaration and the query.

Rob (SA)
10-28-2010, 04:28 AM
Hi Guys,

I have made changes like this


<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.


<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

traq
10-28-2010, 08:05 PM
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.

$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';

Rob (SA)
11-03-2010, 07:37 PM
Hi Adrian,

I have tried your changes

<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.

bluewalrus
11-03-2010, 07:52 PM
You can't have html in the php unless you are echoing it. The simplest thing to do would be to use this...



<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>

Rob (SA)
11-04-2010, 09:06 AM
Thanks I will try this

Rob (SA)
11-08-2010, 07:48 PM
Hi Folks,

Not much success in trying this - unfortunatly

Regards
Rob

Rob (SA)
11-13-2010, 08:10 AM
Hi Folks,

In trying the options presented I have created three examples that differ slightly from one another.

Howver if I change the value of say 80 to 100 or 80 to 10, no change occurs which means that the counting portion is not working.

Advice here would be welcome

bluewalrus
11-15-2010, 11:56 PM
Works for me without a DB, must be a problem with your db query.

To test it load your page with ?v=10 then ?v=1



<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];
$c = $_GET['v'];
// 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>

Rob (SA)
11-20-2010, 06:55 AM
Hi,

Thanks for your reply.

Am I correct in understanding then that I must substitute 'v' with 10 or 'v' with 1 to do the test?

Regards
Rob

bluewalrus
11-20-2010, 03:57 PM
No, v is the get request so...

Load
http://www.site.com/page.php?v=1

This should display the form. Then load
http://www.site.com/page.php?v=10


This should display closed.

Rob (SA)
11-20-2010, 05:29 PM
Hi,

Cant seem to log into your two pages ( ERROR 404 )and view what you have tried to show

Regards
Rob

traq
11-20-2010, 08:54 PM
those are example URLs, not actual links. He's demonstrating the ?get=variable syntax ( ?v=10 )

Rob (SA)
11-20-2010, 09:16 PM
Hi Folks,

Thanks very much for the rplys.

I have tried the inclusion as requested - no change

Regards
Rob

bluewalrus
11-20-2010, 10:13 PM
I don't know what you mean by no change, can you be more specific. It shows closed for both, it shows the form for both, the page is blank, it shows the form and open? Please tell us what you are doing, what the response is, and what the response should be.

Rob (SA)
11-21-2010, 07:07 AM
Hi,

The changes I refer to are what I would expect to see following the inclussion of the additional scripts.

In veiwing a test page (http://www.gnjgf.co.za/Glacier_payfasttest.php) the status of the page remians the same in terms of OPEN / CLOSED which to me indicates that the information is not being retrieved from MySQL. (This is my veiw and could be wrong)

The response as the entries happen is that the number of entires increase, thus the number changes until the ideal number of 80 is achieved. For this trial I have redueced the number to ten or one inrder for the open / closed status to be effected sooner.

If the status is closed the "PAY NOW" button should not appear in the enter column.

It should only appear when the "OPEN" status is in effect.

I hope this helps in answering your questions.

I would also like to say thanks for enduring in finding a solution.

Regards
Rob

bluewalrus
11-22-2010, 02:19 AM
I see open, open blue, and closed how are these being set? The open blue are the only ones with the pay now button, correct?

Rob (SA)
11-22-2010, 03:30 AM
Hi,

The Open (blue) and Closed (red) is the visual effect desured as the Pay now button only shows on Open (blue).

I have included the PHP below of what I have done for the first couple of rows.

Each one is slightly different as I am trying different options to work.

I have put a new column in "Total Entered" so that I can see the total amout of players entering and then hopefully also confirm that the scipt we are using infact gets the value required.

At this stage I am not sure it is getting the correct value or whether it gets the value at all.

Regards
Rob


</style>
</head>

<body>
<table id="customers">
<tr class="th">
<td> </td>
<div><font style="font-size:16px" color="#5A6A83" face="Arial">UPCOMING TOURNAMENTS ARE LISTED BELOW</font></div></button>
</tr>

<tr>
<th>HOST</th>
<th>GOLF COURSE</th>
<th>DATE</th>
<th>DAY</th>
<th>TOTAL ENTERED</th>
<th>ENTRY STATUS</th>
<th>ENTER</th>

</tr>

<tr class="alt2">
<td>HETTIE ELS</td>
<td>KEMPTON PARK</td>
<td>05 JANUARY 2011</td>
<td>WEDNESDAY</td>
<td>*</td>
<?php

$connect = mysql_connect("localhost", "e****_****", "*****") or
die ("Hey loser, check your server connection.");
mysql_select_db("e****_Members");

// name of tournament you wish to count entries from
// maybe from a form entry?
$tournament = 'KEMPTON PARK - 05/01/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];
$c = $_GET['v'];

// 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 >= 1 ? 'Closed' : 'Open';
echo "<td>";
if ($openORclosed != 'Open') {

?>
<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">
<?php
} else {
echo $openORclosed;
}
?>
</tr>

<tr class="alt">
<td>THE GOLF SCHOOL OF EXCELLENCE</td>
<td>GLENDOWER</td>
<td>27 FEBRUARY 2011</td>
<td>?</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];
$c = $_GET['v'];

// 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 >= 1 ? 'Closed' : 'Open';
echo "<td>";
if ($openORclosed != 'Open') {
?>

<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;
}
?>

</tr>



<tr class="alt2">
<td>?</td>
<td>GARDENER ROSS</td>
<td>27 MARCH 2011</td>
<td>?</td>
<td>*</td>
<?php
// name of tournament you wish to count entries from
// maybe from a form entry?
$tournament = 'GARDENER ROSS - 27/03/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);
if($c >= 0){
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 - Gardener Ross - 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>

Rob (SA)
11-22-2010, 03:46 AM
If I change the < or > sign in the
if($c >= 1) but not the value the I can get the Open (Blue) or Closed (Red) to change as is veiwed on the l ink (http://www.gnjgf.co.za/Glacier_payfasttest.php)

That is th eonly change I make to get this change hence my belief that the value of 80 is not being read.

Regards
Rob

bluewalrus
11-22-2010, 04:40 AM
I recommend knowing the data you are working with before working with it.

echo $c; and see if the value is what it should be.

Also this $c = $_GET['v']; shouldn't be there anymore that was an example to demonstrate the c value was processing correctly.

traq
11-22-2010, 05:56 AM
$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.

It does not require single quotes ( ' ). Using them will mess things up. It is good practice, however, to use backticks ( ` ) around column names to distinguish them from normal SQL keywords (an unlikely confusion, but good practice anyway).

I don't know about using ORDER BY on both columns. At best, the first one wouldn't matter (the second one would override it), and at worst, it might cause an error.

Do you know for certain that you are getting a result from your query?

Try echo $c bluewalrus beat me to it or var_dump($c); and see what it returns. If nothing, try echo mysql_error();

Rob (SA)
11-22-2010, 07:56 AM
Hi Guys,

Thanks for the replies and guidance into writting improved script.

The query is something I have used succesfully on other pages - however I will endevour to make improvements.

In terms of knowing which data I am working with - I am sure which data it is as i have recovered similar data on a page which is veiwable at this link (http://www.gnjgf.co.za/Glacier_watflip.php)

I will try your other proposals.

Regards
Rob

Rob (SA)
11-22-2010, 06:08 PM
Hi,

I have included the - echo $c; and it does pick up the value as per the MySQL database.

In my file, the value should appear between <td>*</td> however this would then be before the value of $c is determined.

Please could you advise how I can get the value of $c to appear under this column in the table?



<tr class="alt2">
<td>HETTIE ELS</td>
<td>KEMPTON PARK</td>
<td>05 JANUARY 2011</td>
<td>WEDNESDAY</td>
<td>*</td>

bluewalrus
11-22-2010, 06:17 PM
Do the query first then


<tr class="alt2">
<td>HETTIE ELS</td>
<td>KEMPTON PARK</td>
<td>05 JANUARY 2011</td>
<td>WEDNESDAY</td>
<td><?php echo $c;?></td>

Rob (SA)
11-22-2010, 06:42 PM
Hi,

Thanks - some progress - this effectively doe sthe task of putting the $c value into the column but now all the columns are jumbled - that is the order changed.

It is probably because I have put something in th ewrong place - can you advise that the "Pay Now" button appears at the end.


<tr class="alt2">
<?php

$connect = mysql_connect("localhost", "e****_r***", "*****") or
die ("Hey loser, check your server connection.");
mysql_select_db("eghfya_Members");

// name of tournament you wish to count entries from
// maybe from a form entry?
$tournament = 'KEMPTON PARK - 05/01/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 >= 1 ? 'Closed' : 'Open';
echo "<td>";

if ($openORclosed != 'Open')
{
?>
<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">

<?php
} else {
echo $openORclosed;
}
?>

<td>HETTIE ELS</td>
<td>KEMPTON PARK</td>
<td>05 JANUARY 2011</td>
<td>WEDNESDAY</td>
<td><?php echo $c;?></td>
</tr>