[PHP] MySQL Query Result Question
I have the following query: $query = SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, cd.date, cd.id ; $query .= FROM (capacity_data as d LEFT JOIN interfaces as i ON d.interface = i.id) ; $query .= LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id ; $query .= WHERE i.router = '$cmts[$i]' AND cd.date = '$useDate' ; $query .= ORDER BY i.interface,cd.date DESC; if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($query) { //SSLT } The query itself runs just fine. However, I've run into a problem with the loop I've created. During one of the iterations, the query returns no data so during the subsequent loop the previous query's results is used in it's place. I do not want this to happen. What is the best way to destroy $result before I run the query? Robbert van Andel
RE: [PHP] MySQL Query Result Question
Shouldn't that be: while($data=mysql_fetch_array($result)) { //SSLT } NOTE: Added ) and changes $query to $result -Original Message- From: Van Andel, Robbert [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 3:21 PM To: [EMAIL PROTECTED] Subject: [PHP] MySQL Query Result Question I have the following query: $query = SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, cd.date, cd.id ; $query .= FROM (capacity_data as d LEFT JOIN interfaces as i ON d.interface = i.id) ; $query .= LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id ; $query .= WHERE i.router = '$cmts[$i]' AND cd.date = '$useDate' ; $query .= ORDER BY i.interface,cd.date DESC; if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($query) { //SSLT } The query itself runs just fine. However, I've run into a problem with the loop I've created. During one of the iterations, the query returns no data so during the subsequent loop the previous query's results is used in it's place. I do not want this to happen. What is the best way to destroy $result before I run the query? Robbert van Andel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL Query Result Question
Yes, your correction is actually what I have. So the problem I'm facing is that $result doesn't seem to empty when I run the query and nothing is returned by it. Robbert van Andel -Original Message- From: Bryan Lipscy [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 3:40 PM To: Van Andel, Robbert; [EMAIL PROTECTED] Subject: RE: [PHP] MySQL Query Result Question Shouldn't that be: while($data=mysql_fetch_array($result)) { //SSLT } NOTE: Added ) and changes $query to $result -Original Message- From: Van Andel, Robbert [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 3:21 PM To: [EMAIL PROTECTED] Subject: [PHP] MySQL Query Result Question I have the following query: $query = SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, cd.date, cd.id ; $query .= FROM (capacity_data as d LEFT JOIN interfaces as i ON d.interface = i.id) ; $query .= LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id ; $query .= WHERE i.router = '$cmts[$i]' AND cd.date = '$useDate' ; $query .= ORDER BY i.interface,cd.date DESC; if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($query) { //SSLT } The query itself runs just fine. However, I've run into a problem with the loop I've created. During one of the iterations, the query returns no data so during the subsequent loop the previous query's results is used in it's place. I do not want this to happen. What is the best way to destroy $result before I run the query? Robbert van Andel -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] MySQL Query Result Question
At 00:20 01.03.2003, Van Andel, Robbert said: [snip] I have the following query: $query = SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, cd.date, cd.id ; $query .= FROM (capacity_data as d LEFT JOIN interfaces as i ON d.interface = i.id) ; $query .= LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id ; $query .= WHERE i.router = '$cmts[$i]' AND cd.date = '$useDate' ; $query .= ORDER BY i.interface,cd.date DESC; if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($query) { //SSLT } [snip] Simply setting $result=null after the loop should do, or am I off topic? if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($result)) { //SSLT } $result = null; // could also use // unset($result); -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL Query Result Question
I had the same thought and it didn't work. I have verified that $cmts[$i] is a different value then the previous iteration, but the second time through the same data as the first time through is processed. I've even run the actually query that I echoed onto the page through phpMyAdmin and verified that I got nothing back. I don't know at this point. I'm at a loss. Robbert van Andel -Original Message- From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 3:51 PM To: Van Andel, Robbert Cc: [EMAIL PROTECTED] Subject: Re: [PHP] MySQL Query Result Question At 00:20 01.03.2003, Van Andel, Robbert said: [snip] I have the following query: $query = SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, cd.date, cd.id ; $query .= FROM (capacity_data as d LEFT JOIN interfaces as i ON d.interface = i.id) ; $query .= LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id ; $query .= WHERE i.router = '$cmts[$i]' AND cd.date = '$useDate' ; $query .= ORDER BY i.interface,cd.date DESC; if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($query) { //SSLT } [snip] Simply setting $result=null after the loop should do, or am I off topic? if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($result)) { //SSLT } $result = null; // could also use // unset($result); -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] MySQL Query Result Question
Thanks to everyone who responded. I've figured it out. One of those ID 10 T errors. I was not clearing some necessary variables further down in the loop. Robbert van Andel -Original Message- From: Van Andel, Robbert Sent: Friday, February 28, 2003 3:57 PM To: Ernest E Vogelsinger Cc: [EMAIL PROTECTED] Subject: RE: [PHP] MySQL Query Result Question I had the same thought and it didn't work. I have verified that $cmts[$i] is a different value then the previous iteration, but the second time through the same data as the first time through is processed. I've even run the actually query that I echoed onto the page through phpMyAdmin and verified that I got nothing back. I don't know at this point. I'm at a loss. Robbert van Andel -Original Message- From: Ernest E Vogelsinger [mailto:[EMAIL PROTECTED] Sent: Friday, February 28, 2003 3:51 PM To: Van Andel, Robbert Cc: [EMAIL PROTECTED] Subject: Re: [PHP] MySQL Query Result Question At 00:20 01.03.2003, Van Andel, Robbert said: [snip] I have the following query: $query = SELECT d.utilization, d.capacity_date, d.day, i.id, i.interface, cd.date, cd.id ; $query .= FROM (capacity_data as d LEFT JOIN interfaces as i ON d.interface = i.id) ; $query .= LEFT JOIN capacity_date as cd ON d.capacity_date=cd.id ; $query .= WHERE i.router = '$cmts[$i]' AND cd.date = '$useDate' ; $query .= ORDER BY i.interface,cd.date DESC; if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($query) { //SSLT } [snip] Simply setting $result=null after the loop should do, or am I off topic? if(!$result = mysql_query($query)) die(mysql_error()); while($data=mysql_fetch_array($result)) { //SSLT } $result = null; // could also use // unset($result); -- O Ernest E. Vogelsinger (\)ICQ #13394035 ^ http://www.vogelsinger.at/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php