get request (i think)

I’ve been stuck on this for ages and i really don’t know what i’m doing
i have this:

include “/diska/www/include/coa123-13-connect.php”;
$host=‘co-project.lboro.ac.uk’;
$dbName=‘coa123wdb’;
$dsn = “mysql://$username1:$password1@$host/$dbName”; //Data Source Name
require_once(‘MDB2.php’); //Just include this line into your program - you do not have to have the source in your directory
$db =& MDB2::connect($dsn); //Try to make a connection

if (PEAR::isError($db)) {
die($db->getMessage());
}

VARIABLES

$date = $_GET[“date”];
$catering_partysize = $_GET[“Party_Size”]; ##best not to use capitals
$catering_grade = $_GET[“catering”]; ##catering isn’t a good name for that (ambigious)
$flexible = $_GET[“flexible”];
if($flexible == ‘on’){
$flexible = ‘flexible’;
} else {
$flexible = ‘not flexible’;
}

echo “

you have chosen to be: $flexible

”;

$sql = "
SELECT *
FROM venue
INNER JOIN catering ON venue.venue_id = catering.venue_id
WHERE catering.grade = ‘{$catering_grade}’ AND venue.capacity >= ‘{$catering_partysize}’";

echo “

SQL to find venues with certain grade

$sql
”;

$db->setFetchMode(MDB2_FETCHMODE_ASSOC);

$res =& $db->query($sql);

if (PEAR::isError($res)) {
die($res->getMessage());
}

echo “

Into a Table

”;

echo "

";

while ($row = $res->fetchRow()) {
//var_dump($row);
echo "








";
}

echo "

venue_id name capacity weekend_price weekday_price licensed
“.$row[‘venue_id’].” “.$row[‘name’].” “.$row[‘capacity’].” “.$row[‘weekend_price’].” “.$row[‘weekday_price’].” “.$row[‘licensed’].”

"; echo "for $catering_partysize person(s)
";

$catering_date = explode(’/’,$catering_date);
$catering_date = $catering_date[2]."-".$catering_date[1]."-".$catering_date[0];

echo “on the $date
”;

//$date = explode(’/’,$date);
echo $date."";
$date = date(“Y-m-d”,strtotime($date));

//$date = $date[2]."-".$date[0]."-".$date[1];

$timestamp = strtotime($date);
$day = date(‘l’, $timestamp);

echo "DAY: $day ";
if ($day == ‘Saturday’ || $day == ‘Sunday’) {
$day = ‘0’;
} else {
$day = ‘1’;
}

echo “VAL: $day”;

if($flexible == ‘1’){
$dateneg = date(“Y-m-d”,strtotime(’-1 week’,$date));
$datepos = date(“Y-m-d”,strtotime(’+1 week’,$date));
$datesql = “AND date_booked BETWEEN ‘{$dateneg}’ AND ‘{$datepos}’)”;
} else {
$datesql = “AND date_booked = ‘{$date}’)”;
}

echo $date."\n".$datepos."\n".$dateneg."\n";

$sql = "
SELECT *
FROM venue
WHERE NOT EXISTS (SELECT *
FROM venue_booking
WHERE venue.venue_id = venue_booking.venue_id
$datesql ";

echo “

$sql
”;

$db->setFetchMode(MDB2_FETCHMODE_ASSOC);
$res =& $db->query($sql);

if (PEAR::isError($res)) {
die($res->getMessage());
}

echo "
<div style='width:500px;'>
	<table border= '1;'>
		<tr>
			<th>venue</th>
			<th>name</th>
			<th>price</th>
		</tr>";
		
while ($row = $res->fetchRow()) { 	

	echo "
		<tr>
			<td>".$row['venue_id']."</td>
			<td>".$row['name']."</td>";
			
			if($day == 0){
				$price = $row['weekend_price'];
				echo "<td>".$row['weekend_price']."</td>";
			} else {
				$price = $row['weekday_price'];
				echo "<td>".$row['weekday_price']."</td>";
			}
	echo "</tr>";
}

echo "</table></div>";

echo "<hr/>";

$sql = "
	SELECT * 
	FROM venue
	INNER JOIN catering ON venue.venue_id = catering.venue_id
	WHERE catering.grade = '{$catering_grade}' AND venue.capacity >= '{$catering_partysize}' AND  NOT EXISTS (
		SELECT *
		FROM   venue_booking
		WHERE  venue.venue_id = venue_booking.venue_id
		AND date_booked = '{$date}') ";
		
echo "<pre>$sql</pre>";

$db->setFetchMode(MDB2_FETCHMODE_ASSOC);

$res =& $db->query($sql);

if (PEAR::isError($res)) {
die($res->getMessage());
}

echo "
	<div style='width:500px;'>
	<table border= '1;'>
		<tr>
			<th> </th>
			<th>venue</th>
			<th>name</th>
			<th>price</th>
		</tr>";
		
while ($row = $res->fetchRow()) { 	

	echo "
		<tr>
			<td><input type='radio' value=".$row['venue_id']." id='hotel_chosen' name='hotel_chosen' onchange='hotel_chosen(this.value); newDoc()';></td>
			<td>".$row['venue_id']."</td>
			<td>".$row['name']."</td>";
			
			if($day == 0){
				$price = $row['weekend_price'];
				echo "<td>".$row['weekend_price']."</td>";
			} else {
				$price = $row['weekday_price'];
				echo "<td>".$row['weekday_price']."</td>";
			}
	echo "</tr>";
}

echo "</table></div>";

?>

which goes to the new page and is meant to get the results of the hotel that was chosen from the previous page

how do you use a get request to get the venue_id to pass through the url
do i need to do something on that page or on the new page?

Please try to use tags, it makes your code easier to read.

As for the question, say you have your url:

http://www.yoursite.com/yourpage.php?venue_id=319&page_id=venues

You would use get variables like so:

[PHP]
echo $_GET[‘venue_id’]; //This will pull the item = to venue_id in the URL
[/PHP]

You can also use:

[PHP]
$_REQUEST[‘venue_id’];
[/PHP]

Which will work as GET or POST.

Sponsor our Newsletter | Privacy Policy | Terms of Service