It's me with the funfair database again! Having more issues. Basically I am trying to create a 'daily report' page, where it shows the rides we have ridden today, and how many times we've ridden those specific rides to date, showing something like this:
Day Four
Big Wheel: 3 (4)
Ghost Train: 5 (10)
Table is currently set up like this:
rides_id | rides_date | rides_one | rides_two | rides_three | rides_four | rides_five
This is the code for the ridecount.php page, and everything works exactly how it should. The $rideid and $ridename are there so that I can use the same calling pages (get_rides_today.php and get_rides_total.php without having to have a different page for each ride)
<?php $day=5 ;?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
DAY FOUR - attempting to use if-else statement<br>
<font size="2">
<?php $rideid=rides_one;$ridename='Big Wheel';?><?php include('get_rides_today1.php'); ?> <?php include('get_rides_total1.php'); ?>
<?php $rideid=rides_two;$ridename='Dodgems';?><?php include('get_rides_today1.php'); ?> <?php include('get_rides_total1.php');?>
<?php $rideid=rides_three;$ridename='Helter Skelter';?><?php include('get_rides_today1.php'); ?> <?php include('get_rides_total1.php'); ?>
<?php $rideid=rides_four;$ridename='Waltzers';?><?php include('get_rides_today1.php'); ?> <?php include('get_rides_total1.php'); ?>
<?php $rideid=rides_five;$ridename='Ghost Train';?><?php include('get_rides_today1.php'); ?> <?php include('get_rides_total1.php'); ?>
</font>
</body>
</html>
The get_rides_today1.php page is also working fine, calling only the rides that have had values entered for the day, as specified by the $day on the ridecount.php page. This is the correctly working code for the get_rides_today1.php:
<html>
<head><title>Get menu</title></head>
<body>
<?php
$rs = @mysql_connect( "localhost", "user1", "######" );
$rs = @mysql_select_db( "rides" );
$sql = "select $rideid from rides where rides_id = $day and $rideid >= 1";
$rs = mysql_query( $sql );
while( $row = mysql_fetch_array( $rs ) )
{
?>
<br><b><?php echo ($ridename);?>:</b> <?php echo $row["$rideid"];?>
<?php } ?>
</body>
</html>
The page that I am having issues with is the get_rides_total1.php. Originally I had the daily report showing every ride and how many times it had been ridden and it's total so far, regardless of whether it had been ridden that day. Preferably, I want to avoid that, and have the report show only the rides that have been ridden that day and their totals to date.
Basically, using the 'if else' statement, I am trying to call a sum() of the entire ride, but have the entry displayed only if the entry in the ride column on that specific day is higher than 0, so that the only results displayed on the report page are the rides that have been ridden that day plus their running total in brackets.
I am unsure how to go about specifying the second part (only when ride >= 0 section. This is the code I have at the moment, but it is returning 'Nothing'. (Evenutally I will replace the 'Nothing' with '' so nothing shows, unless there is an easier way to achieve that!):
<html>
<head><title>Get menu</title></head>
<body>
<?php
#connect to mysql
$rs = @mysql_connect( "localhost", "user1", "######" );
#specify database
$rs = @mysql_select_db( "rides" );
#create the query
$sql = "select sum($rideid) from rides where rides_id <= $day and $rideid >=1";
#execute the query
$rs = mysql_query( $sql ) or die( 'Query Failed: ' . mysql_error() );
while( $row = mysql_fetch_array( $rs ) )
{
?>
<?php
$dis = $rideid;
if ($dis > 0 )
{ echo ('($row["sum($rideid)"])');
//code to execute if the equal to if statement
} else
{ echo ('(Nothing)');
//code to execute in all other cases
}
?>
<?php } ?>
</body>
</html>
Okay, well I hope that makes some reasonable sense to someone! Feel free to ask any questions about the set up if the above doesn't make sense. I'm sure that more experienced programmers out there could come up with a much simpler way of achieving all this, but I'm still learning, and working from what I know at the moment! Anyway, all help greatly welcomed!!!