Re: [PHP-DB] SQL Query - Using variable from another SQL Query
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: '$tstamp' and egw_cal.cal_id=egw_cal_dates.cal_id", $db); if ($event = mysql_fetch_array($events)) { echo "\n"; echo "\n"; do { echo "$event[cal_title]- $event[cal_location]\n"; echo "\n"; $start = date('F jS\, Y \a\t g:ia', $event[cal_start]); echo "Starting Date/Time: $start"; echo "\n"; echo "\n"; echo "$event[cal_description]"; echo "\n"; echo "\n"; } while ($event = mysql_fetch_array($events)); } else { echo "No Public Events Are Currently Scheduled..."; } ?> - Original Message - From: "Matthew Ferry" <[EMAIL PROTECTED]> To: 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: $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 "\n"; echo "\n"; do { echo "$event[cal_title]- $event[cal_location]\n"; echo "\n"; echo "$event[cal_description]"; echo "\n"; echo "\n"; } while ($event = mysql_fetch_array($events)); } else { echo "No Public Events Are Currently Scheduled..."; } ?>
Re: [PHP-DB] SQL Query - Using variable from another SQL Query
This is a join - Read up on them, they're very useful and don't require the overhead of a sub-query. SELECT egw_cal.* FROM egw_cal_dates LEFT JOIN egw_cal using (cal_id) where egw_cal_dates.cal_start > $tstamp AND egw_cal.cal_category = '501' -Micah On 02/12/2007 08:14 AM, Matthew Ferry wrote: 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: $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 "\n"; echo "\n"; do { echo "$event[cal_title]- $event[cal_location]\n"; echo "\n"; echo "$event[cal_description]"; echo "\n"; echo "\n"; } while ($event = mysql_fetch_array($events)); } else { echo "No Public Events Are Currently Scheduled..."; } ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL Query - Using variable from another SQL Query
Try this as your SQL. It should give you all the results, then you can use PHP to sort it all out. SELECT * FROM egw_cal WHERE cal_category='501' and cal_id in (SELECT cal_id FROM egw_cal_dates where cal_start > $tstamp) -TG = = = Original message = = = 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: $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 "\n"; echo "\n"; do echo "$event[cal_title]- $event[cal_location]\n"; echo "\n"; echo "$event[cal_description]"; echo "\n"; echo "\n"; while ($event = mysql_fetch_array($events)); else echo "No Public Events Are Currently Scheduled..."; ?> ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] SQL Query - Using variable from another SQL Query
Matthew Ferry wrote: 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: $tstamp", $db); This returns a mysql result set...not the actual data... search php.net for the function mysql_fetch_array or others to actually *get* the data. (Some good examples there will help you sort this out!) $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 "\n"; echo "\n"; do { echo "$event[cal_title]- $event[cal_location]\n"; echo "\n"; echo "$event[cal_description]"; echo "\n"; echo "\n"; } while ($event = mysql_fetch_array($events)); } else { echo "No Public Events Are Currently Scheduled..."; } ?> -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php