PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
robscriven
Forum Newbie
Posts: 6 Joined: Sun Jan 08, 2006 5:38 pm
Post
by robscriven » Thu Jan 12, 2006 4:23 pm
Hi,
I've done the following if statement that checks the value of a student and then retrieves the corresponding row, all the field names are correct and are fine but it doesnt work...any ideas? the field type in the database is a varchar.
Thanks
- Rob
Code: Select all
<?php
if ($row_bookings['student_type'] == 'student'){
$bookingsum = $bookingsum + $row_bookings['student_price'];
}
if ($row_bookings['student_type'] == 'teacher'){
$bookingsum = $bookingsum + $row_bookings['teacher_price'];
}
if ($row_bookings['student_type'] == 'external'){
$bookingsum = $bookingsum + $row_bookings['external_price'];
}
?>
RobertGonzalez
Site Administrator
Posts: 14293 Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA
Post
by RobertGonzalez » Thu Jan 12, 2006 4:27 pm
Try a switch statement. And when you say they are not working, what do you mean?
Code: Select all
<?php
switch ($row_bookings['student_type'])
{
case 'student':
$bookingsum = $bookingsum + $row_bookings['student_price'];
break;
case 'teacher':
$bookingsum = $bookingsum + $row_bookings['teacher_price'];
break;
default:
case 'external':
$bookingsum = $bookingsum + $row_bookings['external_price'];
break;
}
BDKR
DevNet Resident
Posts: 1207 Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:
Post
by BDKR » Fri Jan 13, 2006 6:56 am
Another option is to dump the $row_bookings array before the test to make sure the 'student_price' element is there. print_r() is your freind.
duk
Forum Contributor
Posts: 199 Joined: Wed May 19, 2004 8:45 am
Location: London
Post
by duk » Fri Jan 13, 2006 12:19 pm
var_dump(); -> will help you
robscriven
Forum Newbie
Posts: 6 Joined: Sun Jan 08, 2006 5:38 pm
Post
by robscriven » Fri Jan 13, 2006 1:18 pm
I tried the switch and that's got it working and taken on board the other two suggestions. Thanks for your help guys.