Web Hosting Talk







View Full Version : Adding PHP Variables?


kayz
12-30-2008, 03:00 PM
Hi guys i have a simple form where people register for their tickets which allows them to indicate how many additonal persons they are brining.
I was successfully able to add up the rows to display total registered users. However the additonal boxes are radio buttons up to 5. Each option is a "1,2,3,4,5" interger.
On the member list view i can see the list of registered users and i see how many people each person is brining male and female.
What i dont know how to do is add up all the additional female users and the additional male users they will be brining. So it should give me a total number of how many additional female members and male members that are coming?
There are two coloumns.. "additonal males" and "additional females", i want it to show me a total of all additonal users based on their gender.. something like.. "Additional female users coming = 10" the 10 being a $variable and the same for males.
Thats the most important thing first.. secondly if its possible i would like it to add the registered user to the male/female coloumn depending on their gender. So the registered user should be on the tally of either "Total Females Attending" or "Total Males Attending" based on their gender.
Here are parts of my form and code..
Registration form:
<tr>
<td>
Your Gender.
<br />
<input type="radio" name="male" value="male">Male
<input type="radio" name="female" value="female">Female
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
How many additional <b>"Male"</b> persons you are likely to bring.
<br />
<input type="radio" name="malepersons" value="none">Just myself&nbsp;&nbsp;
<input type="radio" name="malepersons" value="1 Male">1
<input type="radio" name="malepersons" value="2 Males">2
<input type="radio" name="malepersons" value="3 Males">3
<input type="radio" name="malepersons" value="4 Males">4
<input type="radio" name="malepersons" value="5 Males">5
</td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>
How many additional <b>"Female"</b> persons you are likely to bring.
<br />
<input type="radio" name="femalepersons" value="none">Just myself&nbsp;&nbsp;
<input type="radio" name="femalepersons" value="1 Female">1
<input type="radio" name="femalepersons" value="2 Females">2
<input type="radio" name="femalepersons" value="3 Females">3
<input type="radio" name="femalepersons" value="4 Females">4
<input type="radio" name="femalepersons" value="5 Females">5
</td>
</tr>
The registration processing into db:
$query = "INSERT INTO ticket_registration (firstname, surname, email, contact_no, malepersons, femalepersons, date)
VALUES('$firstname', '$surname', '$email', '$contact_no', '$malepersons', '$femalepersons', '$date')";
mysql_query($query) or die(mysql_error());
$ticketid = mysql_insert_id();
mysql_close();
Viewing Total Users Registered (but i dont know how to display the total number of additonal female/male registered. :(
<?php
$link = mysql_connect("localhost", "xxxxxx_ticket", "xxxxxx");
mysql_select_db("xxxxxx_etticket", $link);
$result = mysql_query("SELECT * FROM ticket_registration", $link);
$num_rows = mysql_num_rows($result);
echo "$num_rows";
?>
Any help would be much much appreciated.
Cheers

Eye4Designs
12-30-2008, 04:04 PM
$result = mysql_query("SELECT malepersons FROM ticket_registration" , $link);
this will select the number of malepersons in the entire ticket registration field...
I'm not sure i understand what your looking for...
if you want a specifi registered person malpersons you could do this
$result = mysql_query("SELECT malepersons FROM ticket_registration WHERE email=$email");
then you just need to throw that persons email into the fetch...
The above will only select the malepersons that are tied to the specific registered email...

kayz
12-30-2008, 05:37 PM
$result = mysql_query("SELECT malepersons FROM ticket_registration" , $link);
this will select the number of malepersons in the entire ticket registration field...
I'm not sure i understand what your looking for...
if you want a specifi registered person malpersons you could do this
$result = mysql_query("SELECT malepersons FROM ticket_registration WHERE email=$email");
then you just need to throw that persons email into the fetch...
The above will only select the malepersons that are tied to the specific registered email...
I will try that cheers, what i was asking later in my initial post was.. as it will be showing me the "total number of additional users" whether they are male or female, i was wondering to include the person "who registers" to be added to the male or female stats according to the gender they choose. As currently it is totalling the "additional users" that the registered user will be bringing which dosent include the person actually registering them... i hope that explains a little...
Cheers

Eye4Designs
12-30-2008, 06:16 PM
you can do it 2 ways...
Create another field for the registered person to select if they are male or female call it gender... It's much easier to use numbers
male = 1
female = 2
then use an if statement
$result = mysql_query("SELECT malepersons, gender FROM ticket_registration WHERE email=$email");
$arr = mysql_fetch_assoc($result);
$gender = $arr["gender"];
$maleguest = $arr["malepersons"];
function addgender($a = 0, $b = 0)
{
return ($a + $b);
}
if( $gender == 1 )
$finalcount = addgender(1 + $maleguest);
else
$finalcount = $maleguest;
can do the same for females just change the query in the fetch
Sorry this is just crude php i haven't really tested it so i may have a few mistakes... have to be fast or boss get's all worked up we browding forums