Re: SQL Query - Using variable from another SQL Query
| From: | Matthew Ferry | Date: | Mon, 12 Feb 2007 18:43:51 +0000 |
| Subject: | Re: SQL Query - Using variable from another SQL Query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-43065@lists.php.net to get a copy of this message | ||
Thanks Everyone...
After I sent that...I got thinking about doing both queries in one statement.
So thats what I did.
Its working fine...
Here is the updated code:
<?php
$todays_year = date("Y");
$todays_month = date("m");
$todays_day = date("d");
$tstamp = mktime(0, 0, 0, $todays_month, $todays_day, $todays_year);
$events = mysql_query("SELECT DISTINCT * FROM egw_cal, egw_cal_dates WHERE
egw_cal.cal_category='501'
and egw_cal_dates.cal_start > '$tstamp' and egw_cal.cal_id=egw_cal_dates.cal_id",
$db);
if ($event = mysql_fetch_array($events)) {
echo "<center>\n";
echo "<HR>\n";
do {
echo "<B><Font
Face='Times'>$event[cal_title] - $event[cal_location]</Font></B>\n";
echo "<BR>\n";
$start = date('F jS\, Y \a\t g:ia', $event[cal_start]);
echo "Starting Date/Time: $start";
echo "<BR>\n";
echo "<BR>\n";
echo "$event[cal_description]";
echo "<BR>\n";
echo "<HR>\n";
} while ($event = mysql_fetch_array($events));
} else {
echo "No Public Events Are Currently Scheduled...";
}
?>
----- Original Message -----
From: "Matthew Ferry" <mferry@retailautomation.biz>
To: <php-db@lists.php.net>
Sent: Monday, February 12, 2007 11:14 AM
Subject: [PHP-DB] SQL Query - Using variable from another SQL Query
Hello Everyone....
Got a simple / stupid question.
Worked on this all night. I'm over looking something very basic here.
The query "event_time" brings back the calendar id for each event that is pending in the
future.
ie.... 12, 13, 14, 26 (There could be 100 of them out there)
The second query "events" needs to meet both reqirements.
1 - cal_category='501'
2 - cal_id= a number from the "event_time" query
I think i need to do a loop inside of a loop
Thanks...
Matt
Here is my code:
<?php
$todays_year = date("Y");
$todays_month = date("m");
$todays_day = date("d");
$tstamp = mktime(0, 0, 0, $todays_month, $todays_day, $todays_year);
$event_time = mysql_query("SELECT cal_id FROM egw_cal_dates where cal_start > $tstamp",
$db);
$events = mysql_query("SELECT * FROM egw_cal WHERE cal_category='501' and
cal_id='$event_time'\n", $db);
if ($event = mysql_fetch_array($events)) {
echo "<center>\n";
echo "<HR>\n";
do {
echo "<B><Font
Size='10'>$event[cal_title] - $event[cal_location]</B></Font>\n";
echo "<BR>\n";
echo "$event[cal_description]";
echo "<BR>\n";
echo "<HR>\n";
} while ($event = mysql_fetch_array($events));
} else {
echo "No Public Events Are Currently Scheduled...";
}
?>