Re: MySQL and PHP question
Thanks for the info. I tried using mysql_free_result() and mysql_close($db) and opening the DB again for the second query with the same results. I haven't tried using a different variable for $result. - Original Message - From: "Steve Yates" <[EMAIL PROTECTED]> To: "MySQL List" <[EMAIL PROTECTED]> Sent: Wednesday, December 18, 2002 1:32 AM Subject: Re: MySQL and PHP question > On Wed, 18 Dec 2002 22:54:53 -0500, C. Reeve wrote: > >while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { > >$num1 = $line['number']; > >} > > Loop through the result and return the value from the last row? > Did you want "select sum(number) as SubTotal1 from table1 where > userid=$user1"? > > >$query "select number from table2 where userid=$user2"; > >$result = mysql_query($query) or die("Query failed"); > > You re-used the same variable $result. Offhand I would try > using a second variable, and/or using mysql_free_result() in between. > > - Steve Yates > - My hard disk is full! Maybe I'll try this message section thing. > > ~ Taglines by Taglinator - www.srtware.com ~ > > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: MySQL and PHP question
On Wed, 18 Dec 2002 22:54:53 -0500, C. Reeve wrote: >while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { >$num1 = $line['number']; >} Loop through the result and return the value from the last row? Did you want "select sum(number) as SubTotal1 from table1 where userid=$user1"? >$query "select number from table2 where userid=$user2"; >$result = mysql_query($query) or die("Query failed"); You re-used the same variable $result. Offhand I would try using a second variable, and/or using mysql_free_result() in between. - Steve Yates - My hard disk is full! Maybe I'll try this message section thing. ~ Taglines by Taglinator - www.srtware.com ~ - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: MySQL and PHP question
I've since deleted the code and did it another way. The code however went something like this. This is just a mock up (there is more being selected etc and there are some joins, but the syntax is exact). So what happens is the select statement with $user1 in it gets the proper values (the first one in the example), the other one doesn't, but if I change $user1 and $user2 around the second select will get the values. So on the surface it sounds like a problem with $user2, but I have run extensive tests and $user2 gets the proper values (they both come from a form). In another project I am doing, I tried a similar feat with totally different values and got the same results. This time I was trying to do one SELECT and one UPDATE. If anyone has any ideas it would be appreciated. Also, if there is a better way to do the following this would also be appreciated. $query "select number from table1 where userid=$user1"; $result = mysql_query($query) or die("Query failed"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $num1 = $line['number']; } $query "select number from table2 where userid=$user2"; $result = mysql_query($query) or die("Query failed"); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { $num2 = $line['number']; } $total = $num1 + $num2; mysql_query("UPDATE table3 SET total = '$total' WHERE userid=$user"); TIA - Original Message - From: "Steve Yates" <[EMAIL PROTECTED]> To: "MySQL List" <[EMAIL PROTECTED]> Sent: Tuesday, December 17, 2002 5:12 PM Subject: Re: MySQL and PHP question > On Wed, 18 Dec 2002 16:05:35 -0500, C. Reeve wrote: > > >I can not use two mysql queries in the same PHP file > > Please post code snippets, this is possible. > > - Steve Yates > - Burger Borg: We do it our way; yours is irrelevant. > > ~ Taglines by Taglinator - www.srtware.com ~ > > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php > > - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: MySQL and PHP question
I can... Hard to know why without more info but a starting point would be to turn on the query log in MySQL and see what queries it is receiving. _ Fraser Stuart Logistics IT 77-85Phone: +61 2 9335 1235 Roberts Rd Mobile: +61 419 233 732 Greenacre NSW [EMAIL PROTECTED] Australia 2190 www.toll.com.au _ | -Original Message- | From: C. Reeve [mailto:[EMAIL PROTECTED]] | Sent: Thursday, 19 December 2002 8:06 AM | To: MySQL List | Subject: MySQL and PHP question | | | Hi, | | Why is it that I can not use two mysql queries in the same PHP | file. I have | tried to do this several times trying to put my site together and have had | nothing but problems. | | The recent one is this: | | I use a SELECT statement to get some info from a table, then I modify that | info and use an UPDATE statement to update another table. The update does | not work (all variables used by PHP contain the proper values as does the | info selected from the table). | | I get no errors as it appears the update worked, but the table was not | updated. | | I have also found that I can not do two select statements in the same PHP | file, as the second one will not contain any data . The query | does not fail, | there is just no data. | | Any info is appreciated. | | TIA | | | | | | - | Before posting, please check: |http://www.mysql.com/manual.php (the manual) |http://lists.mysql.com/ (the list archive) | | To request this thread, e-mail <[EMAIL PROTECTED]> | To unsubscribe, e-mail | <[EMAIL PROTECTED]> | Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php | | - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: MySQL and PHP question
On Wed, 18 Dec 2002 16:05:35 -0500, C. Reeve wrote: >I can not use two mysql queries in the same PHP file Please post code snippets, this is possible. - Steve Yates - Burger Borg: We do it our way; yours is irrelevant. ~ Taglines by Taglinator - www.srtware.com ~ - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: MySQL and PHP question
> Why is it that I can not use two mysql queries in the same PHP file. You can, I assure you. > Any info is appreciated. Perhaps if you could provide your code? W/o it there is no way we can determine where the problem might be coming from. Chris - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
Re: MySQL and PHP Question
Adrian D'Costa wrote: > Hi, > > I have two tables city and country > +---+-+--+-+-++ > | Field | Type| Null | Key | Default | Extra | > +---+-+--+-+-++ > | id| int(5) | | PRI | 0 | auto_increment | > | city | varchar(35) | | MUL | || > | countryid | int(5) | | MUL | 0 || > +---+-+--+-+-++ > 3 rows in set (0.00 sec) > > mysql> desc country; > +-+-+--+-+-++ > | Field | Type| Null | Key | Default | Extra | > +-+-+--+-+-++ > | id | int(5) | | PRI | 0 | auto_increment | > | country | varchar(35) | | MUL | || > +-+-+--+-+-++ > 2 rows in set (0.00 sec) > > I am trying to write a php script that does the following. > In an html page I have two dropdowns one country which will get the data > from the country table and city which should get the data from the city > table based on the one selected from the country drop down. I do not want > to use a submit button. I use a javascript and using onChange pass the > country.id to the javascript but do not know how to pass it back to the > php script. Any pointers > You have to submit via javascript the country id whenever the dropdown selection changes. You have to be carefull using a hidden field so your php-script recognices when you pushed your form submition button or you just had changed your country. > > Adrian > > -- > === > Adrian D'Costa > [EMAIL PROTECTED] > www.pcsadvt.com > === > > - > Before posting, please check: >http://www.mysql.com/manual.php (the manual) >http://lists.mysql.com/ (the list archive) > > To request this thread, e-mail <[EMAIL PROTECTED]> > To unsubscribe, e-mail <[EMAIL PROTECTED]> > Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php
RE: MySQL and PHP Question
This is really a JavaScript problem if you don't want to use the submit button. Use PHP to load the values of both tables into a JavaScript array. Then write JS code that will change the contents of the City control based on what is selected in the country control. Not terribly difficult. Cal http://www.calevans.com -Original Message- From: Adrian D'Costa [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 06, 2001 12:01 AM To: [EMAIL PROTECTED] Subject: MySQL and PHP Question Hi, I have two tables city and country +---+-+--+-+-++ | Field | Type| Null | Key | Default | Extra | +---+-+--+-+-++ | id| int(5) | | PRI | 0 | auto_increment | | city | varchar(35) | | MUL | || | countryid | int(5) | | MUL | 0 || +---+-+--+-+-++ 3 rows in set (0.00 sec) mysql> desc country; +-+-+--+-+-++ | Field | Type| Null | Key | Default | Extra | +-+-+--+-+-++ | id | int(5) | | PRI | 0 | auto_increment | | country | varchar(35) | | MUL | || +-+-+--+-+-++ 2 rows in set (0.00 sec) I am trying to write a php script that does the following. In an html page I have two dropdowns one country which will get the data from the country table and city which should get the data from the city table based on the one selected from the country drop down. I do not want to use a submit button. I use a javascript and using onChange pass the country.id to the javascript but do not know how to pass it back to the php script. Any pointers Adrian -- === Adrian D'Costa [EMAIL PROTECTED] www.pcsadvt.com === - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php