[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
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
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
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
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..."; } ?>
php-db@lists.php.net
I'm looping through an array and I did this: $rate =& $mydata[$prefix]; Now, in some cases $mydata[$prefix] wasn't set/defined, so I expected $rate to not be defined, or at least point to something that wasn't defined. Instead, PHP 5.1.6 set $mydata[$prefix] to nothing. If I had: $mydata[1] = 3; $mydata[3] = 2; $mydata[5] = 1; And did a loop from $i=1; $i++; $i<=5 I'd get: $mydata[1] = 3; $mydata[2] = ; $mydata[3] = 2; $mydata[4] = ; $mydata[5] = 1; Is this expected? A bug? Fixed in 5.2.0? I know I shouldn't set a reference to a variable that doesn't exist, but the expected result is a warning/error, not for PHP to populate an array. Beckman --- Peter Beckman Internet Guy [EMAIL PROTECTED] http://www.purplecow.com/ --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
php-db@lists.php.net
sry i don't get what u mean?? - Original Message - From: "Peter Beckman" <[EMAIL PROTECTED]> To: "PHP-DB Mailing List" Sent: Tuesday, February 13, 2007 8:29 AM Subject: [PHP-DB] Strange action with =& > I'm looping through an array and I did this: > > $rate =& $mydata[$prefix]; > > Now, in some cases $mydata[$prefix] wasn't set/defined, so I expected $rate > to not be defined, or at least point to something that wasn't defined. > > Instead, PHP 5.1.6 set $mydata[$prefix] to nothing. > > If I had: > > $mydata[1] = 3; > $mydata[3] = 2; > $mydata[5] = 1; > > And did a loop from $i=1; $i++; $i<=5 I'd get: > > $mydata[1] = 3; > $mydata[2] = ; > $mydata[3] = 2; > $mydata[4] = ; > $mydata[5] = 1; the reason mydata2 empty was because it don't have value in it!! full source plz why u don't try this $txt.=""; foreach($mydata as $nm=>$val){ $txt.="\n $nm = $val"; $txt2="\$mydata[$nm] = $val"; } $txt.=""; print $txt; > > Is this expected? A bug? Fixed in 5.2.0? I know I shouldn't set a > reference to a variable that doesn't exist, but the expected result is a > warning/error, not for PHP to populate an array. we should cross check again. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: [PHP-WIN] (DRW) Ordenar por fecha
english plz you know.. i'm not native with english.. but using english is very helpfull to me for solve your problem - Original Message - From: "Anuack Luna" <[EMAIL PROTECTED]> To: Sent: Friday, February 09, 2007 6:28 AM Subject: [PHP-WIN] (DRW) Ordenar por fecha > Hola Foreros > > Tengo la siguiente pregunta. > > Como puedo darle la orden a un juego de registro que me lo ordene por fecha? > > SELECT * > FROM mi_sitio_personal_menu > ORDER BY id DESC > > Si le digo Orden by fecha Desc... Me lo ordena por números, no por fecha. > > La fecha de la siguiente forma: "DIA/MES/AÑO" > > Alguna sugerencia... Adjunto database > > > -- > -- Estructura de tabla para la tabla `mi_sitio_personal` > -- > > CREATE TABLE `mi_sitio_personal` ( > `id` int(11) NOT NULL auto_increment, > `publico_privado` varchar(10) default '0', > `usuario` varchar(255) default NULL, > `fecha` varchar(100) default NULL, > `categoria` varchar(100) default NULL, > `pequena_comentario` text, > `comentario` text, > `archivo` varchar(255) default NULL, > PRIMARY KEY (`id`) > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ; > > -- > -- Volcar la base de datos para la tabla `mi_sitio_personal` > -- > > -- > PHP Windows Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
php-db@lists.php.net
On Tue, 13 Feb 2007, bedul wrote: sry i don't get what u mean?? I'm looping through an array and I did this: $rate =& $mydata[$prefix]; This is how you assign a variable by reference. $rate should be a reference to $mydata[$prefix], not a copy. If I change the value of $rate, the value of $mydata[$prefix] is also changed, and vice versa. Now, in some cases $mydata[$prefix] wasn't set/defined, so I expected $rate to not be defined, or at least point to something that wasn't defined. Instead, PHP 5.1.6 set $mydata[$prefix] to nothing. If I had: $mydata[1] = 3; $mydata[3] = 2; $mydata[5] = 1; And did a loop from $i=1; $i++; $i<=5 I'd get: $mydata[1] = 3; $mydata[2] = ; $mydata[3] = 2; $mydata[4] = ; $mydata[5] = 1; the reason mydata2 empty was because it don't have value in it!! full source plz why u don't try this $txt.=""; foreach($mydata as $nm=>$val){ $txt.="\n $nm = $val"; $txt2="\$mydata[$nm] = $val"; } $txt.=""; print $txt; Because I'm trying to point out a problem with PHP, where setting a reference when the other side is undefined or not set, PHP creates a reference to a previously non-existent array item, just by setting a reference. I don't think that should happen. Your code doesn't set anything by reference. Is this expected? A bug? Fixed in 5.2.0? I know I shouldn't set a reference to a variable that doesn't exist, but the expected result is a warning/error, not for PHP to populate an array. we should cross check again. I don't know what you mean. --- Peter Beckman Internet Guy [EMAIL PROTECTED] http://www.purplecow.com/ --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: SQL Query - Using variable from another SQL Query
I think you don't need to break this into two queries... this is really a SQL question, not a PHP question... Just do a "join" on the two tables: * where table1.cal_id = table2.cal_id and then have a where clause that does all your filtering: * and table1.Date > now() and table2.cal_category='501' Using SQL instead of code is almost always the right thing to do. Learning how to do more sophisticated queries will pay off big time in the long run... and good tutorials are widely and freely available... From: "Matthew Ferry" <[EMAIL PROTECTED]> To: Date sent: Mon, 12 Feb 2007 11:14:32 -0500 Subject: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: > > > $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 "\n"; > > echo "\n"; > > do { > > echo " Size='10'>$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..."; > > } > > ?> > >