Re: [PHP-DB] Update multiple records
--- Jochem Maas [EMAIL PROTECTED] wrote: if (count($inds) 0 AND is_array($inds)) { $ind = '.implode(',', $inds).'; } looks like you want to do a select statement with $ind in the form of SELECT * FROM yourtable WHERE yourfield IN ($inds) Adding the IN clause did not help in any way. What I've been able to get so far is only the first record returned from the database (even though 2 exists) Using this result set it is picking up the correct user records: $query_rsLPINDS = sprintf(SELECT LurkProfiles_Industries.ProfileID, LurkProfiles_Industries.IndID, LurkerProfiles.ProfileID FROM LurkProfiles_Industries INNER JOIN LurkerProfiles ON (LurkProfiles_Industries.ProfileID = LurkerProfiles.ProfileID) INNER JOIN SignUp ON (LurkerProfiles.LurkID = SignUp.SignUpID) INNER JOIN StaIndTypes ON LurkProfiles_Industries.IndID = StaIndTypes.CareerIDs) WHERE LurkerProfiles.ProfileID = %s and LurkID = %s and hash = '%s', $colname__rsLPINDS,$colname2__rsLPINDS,$colname3__rsLPINDS); I've created the variable for IndID like this : $IndID = $rsLPINDS-Fields('IndID'); which when I do a print_r($IndID), prints out the first record. So at this point I'm trying to figure out what I need to make $IndID an array. Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Stumbling across some posts online, I noticed [some of] my messages were being sent as evil ugly HTML - so I'm going to do my best to post from Thunderbird for the list. Gotta keep OE configured as is for all the lovely meeting scheduling. Stuart Felenstein wrote: --- Jochem Maas [EMAIL PROTECTED] wrote: if (count($inds) 0 AND is_array($inds)) { $ind = '.implode(',', $inds).'; } looks like you want to do a select statement with $ind in the form of SELECT * FROM yourtable WHERE yourfield IN ($inds) Adding the IN clause did not help in any way. What I've been able to get so far is only the first record returned from the database (even though 2 exists) Using this result set it is picking up the correct user records: $query_rsLPINDS = sprintf(SELECT LurkProfiles_Industries.ProfileID, LurkProfiles_Industries.IndID, LurkerProfiles.ProfileID FROM LurkProfiles_Industries INNER JOIN LurkerProfiles ON (LurkProfiles_Industries.ProfileID = LurkerProfiles.ProfileID) INNER JOIN SignUp ON (LurkerProfiles.LurkID = SignUp.SignUpID) INNER JOIN StaIndTypes ON LurkProfiles_Industries.IndID = StaIndTypes.CareerIDs) WHERE LurkerProfiles.ProfileID = %s and LurkID = %s and hash = '%s', $colname__rsLPINDS,$colname2__rsLPINDS,$colname3__rsLPINDS); I've created the variable for IndID like this : $IndID = $rsLPINDS-Fields('IndID'); which when I do a print_r($IndID), prints out the first record. So at this point I'm trying to figure out what I need to make $IndID an array. Stuart If I remember correctly, you're using some kind of database class that we spent some time pinning down how to pull the values out of. If that is indeed the case - you need to request the next record to be able to pull that records value for the field in. I don't remember what package you were using - but whatever that is, I think you need to be running across your result set (foreach || while ) and requesting each result as you go (or you need to access the property of the object that stores the whole result set/etc.). Whatever the case - I'm like 95% sure that -Fields('fieldname') was for last pulled rows value of this field or similar and was for pulling record by record. Cheers, - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Update multiple records
Having a problem here with updating multiple records in a table. First the table is like such: +-+--+ | RecordID [int] | IndID [int] | +-+--+ There is no auto inc column. User has a record number and then can have multiple rows in table with the same record number. i.e: +-+--+ | RecordID [int] | IndID [int] | +-+--+ |101 | 5 | +-+--+ |101 | 10 | +-+--+ |101 | 22 | +-+--+ I've setup the sql result set as such: SELECT * FROM `Profiles` INNER JOIN `Profiles_Industries` ON Profiles.ProfileID = Profiles_Industries.ProfileID) INNER JOIN IndTypes ON Profiles_Industries.IndID = IndTypes.CareerIDs) INNER JOIN SU ON (Profiles.kID = `SU.kID) WHERE Profiles.ProfileID = colname I have a list menu (multi select) using the IndTypes table and have named the element IndID[] I have the array variable to grab the IndID values from the record set. inds = implode(,,$_POST['IndID']); And I am attempting to highlight the IndID that exist in the users records in the multi select: ?php $selected = explode(,,$rsLPInds-Fields('IndID')); while(!$rsInds-EOF){ ? option value=?php echo $rsInds-Fields('CareerIDs')? ?php if (in_array($rsInds-Fields('IndID'),$selected)) { echo selected; } ? ?php echo $rsInds-Fields('CareerCategories')?/option ?php I'm sure this is all most likely confusing. :) Typical post from me ...sorry. None of this is working though. Perhaps updating multiple records is more difficult then I first imagined. Can anyone lend some advice , assistance ? Thank you, Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Update multiple records
-Original Message- From: Stuart Felenstein [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 10:40 AM Subject: [PHP-DB] Update multiple records Having a problem here with updating multiple records in a table. [snip] Lets see - where to begin... SELECT * FROM `Profiles` INNER JOIN `Profiles_Industries` ON Profiles.ProfileID = Profiles_Industries.ProfileID) INNER JOIN IndTypes ON Profiles_Industries.IndID = IndTypes.CareerIDs) INNER JOIN SU ON (Profiles.kID = `SU.kID) WHERE Profiles.ProfileID = colname [snip] You list nothing indicating any sort of update, so forget that for the time being until things are working. That's your end goal, but it doesn't look to be what you're fighting with now. You have a very complicated (perhaps messy, perhaps not - it might all be required) select, and then you're trying to pull that information out and populate a select. INNER JOIN SU ON (Profiles.kID = `SU.kID) [snip] This line in particular clearly warrants attention. Cookie to whoever guesses what the' problem` might 'be. ?php $selected = explode(,,$rsLPInds-Fields('IndID')); while(!$rsInds-EOF){ ? option value=?php echo $rsInds-Fields('CareerIDs')? ?php if (in_array($rsInds-Fields('IndID'),$selected)) { echo selected; } ? ?php echo $rsInds-Fields('CareerCategories')?/option [snip] explode() turns an array into a string, you'll have trouble in_array()ing a string. You may want to start there. You don't list the select bit around your select, I'm assuming it's there - what actual behavior/output are you seeing? View source to be sure - you have to specify a select is a multiselect, otherwise it will just be a dropdown and select the first one you say is selected (or maybe the last, I've not messed with it in some time - actually, it's browser dependant, but I think they all tend to behave the same.) rsLPInds-Fields and rsInds-Fields - this is two objects/tables/etc. - you only mention the one, so it's hard to follow what data's where - to be sure. Try that stuff and get back to us. You definitely want to be using print_r() (possibly in pre tags) to see what information is actually stored in the results of your select statement, if there is any question there. - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Norland, Martin wrote: -Original Message- From: Stuart Felenstein [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 10:40 AM Subject: [PHP-DB] Update multiple records Having a problem here with updating multiple records in a table. [snip] Lets see - where to begin... SELECT * FROM `Profiles` INNER JOIN `Profiles_Industries` ON Profiles.ProfileID = Profiles_Industries.ProfileID) INNER JOIN IndTypes ON Profiles_Industries.IndID = IndTypes.CareerIDs) INNER JOIN SU ON (Profiles.kID = `SU.kID) WHERE Profiles.ProfileID = colname [snip] You list nothing indicating any sort of update, so forget that for the time being until things are working. That's your end goal, but it doesn't look to be what you're fighting with now. You have a very complicated (perhaps messy, perhaps not - it might all be required) select, and then you're trying to pull that information out and populate a select. INNER JOIN SU ON (Profiles.kID = `SU.kID) [snip] This line in particular clearly warrants attention. Cookie to whoever guesses what the' problem` might 'be. that will be a lone backtick then :-) now where's the cookiejar ;-) ?php $selected = explode(,,$rsLPInds-Fields('IndID')); while(!$rsInds-EOF){ ? option value=?php echo $rsInds-Fields('CareerIDs')? ?php if (in_array($rsInds-Fields('IndID'),$selected)) { echo selected; } ? ?php echo $rsInds-Fields('CareerCategories')?/option [snip] explode() turns an array into a string, you'll have trouble in_array()ing a string. You may want to start there. er Martin, no it does not. explode creates an array. the manual defines it as thus: array explode ( string separator, string string [, int limit]) possibly you got mixed up with implode() (or join() which is an alias of implode()) You don't list the select bit around your select, I'm assuming it's there - what actual behavior/output are you seeing? View source to be sure - you have to specify a select is a multiselect, otherwise it will just be a dropdown and select the first one you say is selected (or maybe the last, I've not messed with it in some time - actually, it's browser dependant, but I think they all tend to behave the same.) rsLPInds-Fields and rsInds-Fields - this is two objects/tables/etc. - you only mention the one, so it's hard to follow what data's where - to be sure. Try that stuff and get back to us. You definitely want to be using print_r() (possibly in pre tags) to see what information is actually stored in the results of your select statement, if there is any question there. - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Update multiple records
-Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 11:59 AM Subject: Re: [PHP-DB] Update multiple records [snip] This line in particular clearly warrants attention. Cookie to whoever guesses what the' problem` might 'be. that will be a lone backtick then :-) now where's the cookiejar ;-) [snip] All my cookies are stored on my local drives - sorry, I can't give you access. explode() turns an array into a string, you'll have trouble in_array()ing a string. You may want to start there. er Martin, no it does not. explode creates an array. the manual defines it as thus: array explode ( string separator, string string [, int limit]) possibly you got mixed up with implode() (or join() which is an alias of implode()) [snip] That's what I get for troubleshooting before lunch! My apologies to the list and to anyone unfortunate enough to find that post with a search! I always get implode/explode mixed up (I think of an array as more organized than a string - so I think of a string as just an array that's been blown to smithereens). I guess the idea is that an array is like a bunch of pieces of a string after it's been blown up. I even checked the manual and dyslexically read it. 'Spose I owe everyone a cookie, and Jochem Maas two (plus first pick!). Cheers, - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Stuart Felenstein wrote: Having a problem here with updating multiple records in a table. as Martin Norland (a heavy hitter on this list AFAIKT) already stated you don't seem to be at the stage of actually doing an update, no big deal - only you are doing yourself an injustice by given a misleading subject. stick to the matter at hand (one step at a time!) - by all means explain the context of the problem (e.g. your goal of multiple updates) but don't confuse the problem with the context! I'm sure this is all most likely confusing. :) Typical I took one look and thought 'no thanks', if _you_ think _your_ post is confusing how is anybody else supposed to make head or tail of it. post from me ...sorry. None of this is working though. don't be sorry, be pro-active and rewrite it until its idiot proof. its in your own best interest - the clearer you state your problem the greater the chance someone will/can help you. ok, so that was a bit of a rant, the idea being to educate people in the value of taking the time (and it often takes lots of time!) to formulate their problems (and what they have tried so far) properly - its in everyones interest because it increase the potential of everyone on the list to: a, get involved b, learn something new we want you to succeed, if only for the selfish reason that one day you'll have the capability to help out others. besides the more good PHP hackers there are the better it is for all of us - in terms of the perceived validity of PHP (especially at the enterprise level). Perhaps updating multiple records is more difficult then I first imagined. alas we all have stories of spending countless hours trying to figure out whats seems to be very simple problems! Can anyone lend some advice , assistance ? not directly, but you may want to look into making your code more readable/flexible by not constantly switching in and out of PHP mode (i.e. using ?php ? everytime you want to output something.) Thank you, Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
--- Jochem Maas [EMAIL PROTECTED] wrote: don't be sorry, be pro-active and rewrite it until its idiot proof. its in your own best interest - the clearer you state your problem the greater the chance someone will/can help you. Well I've started with a clean slate. Meaning I ditched what was starting to look like spaghetti and started over with a lot of print_r's. My select statement in the (intended)update page has 3 parameters in the where statement, that are passed over from the link using $GET_VARS. 1- is the recordID, 2-the userID 3-an encrypted code tied to the user. All those parameters show up fine (print_r) on said update page. The first problem I'm having is getting the update page to show which values currently exist. This is the multi select box and the (adodb) recordset listing all the options. I'm lacking something in the page though that allow it to see which values are already chosen in the database: select name=inds[] size=8 multiple id=inds[] ?php while(!$rsInds-EOF){ ? option value=?php echo rsInds-Fields('CareerIDs')? ?php if (count($IndID) 0 AND is_array($IndID)) { foreach ($IndID as $ind) { ? ?php if ($rsInds-Fields('IndID')== $ind) {echo SELECTED;} } }? ?php echo $rsInds-Fields('CareerCategories')?/option ?php $rsInds-MoveNext(); } $rsInds-MoveFirst(); I've added this in the script, which prints out fine once I've submitted the page. Not sure if I need something similar for the records that already exist ? if (count($inds) 0 AND is_array($inds)) { $ind = '.implode(',', $inds).'; } Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Norland, Martin wrote: -Original Message- From: Jochem Maas [mailto:[EMAIL PROTECTED] Sent: Monday, January 10, 2005 11:59 AM Subject: Re: [PHP-DB] Update multiple records ... That's what I get for troubleshooting before lunch! My apologies to the list and to anyone unfortunate enough to find that post with a search! I always get implode/explode mixed up (I think of an array as more organized than a string - so I think of a string as just an array that's been blown to smithereens). I guess the idea is that an array is like a bunch of pieces of a string after it's been blown up. thats actually why I personally always use join() instead implode(). also it does help beginners, the fact that its possible to use 'array syntax' on strings e.g.: $str = 'mystring'; echo $str[1] . ' me God?'; // echos 'y me God?' - say it out loud people ;-) I even checked the manual and dyslexically read it. 'Spose I owe everyone a cookie, and Jochem Maas two (plus first pick!). I quick google lead me to suspect Martin is american... if that is true then I demand one of those bigass cookies with even bigger chocolate chips :-) Cheers, - Martin Norland, Database / Web Developer, International Outreach x3257 The opinion(s) contained within this email do not necessarily represent those of St. Jude Children's Research Hospital. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Update multiple records
Stuart Felenstein wrote: --- Jochem Maas [EMAIL PROTECTED] wrote: don't be sorry, be pro-active and rewrite it until its idiot proof. its in your own best interest - the clearer you state your problem the greater the chance someone will/can help you. I don't know about anyone else, but I haven't got a clue as to what the problem is. I know I'm fairly intelligent but I can't work it out. Well I've started with a clean slate. Meaning I always a good plan! ditched what was starting to look like spaghetti and started over with a lot of print_r's. My select statement in the (intended)update page has 3 is it an update script or a selection/view script or both? parameters in the where statement, that are passed over from the link using $GET_VARS. 1- is the recordID, 2-the userID 3-an encrypted code tied to the user. so you start with a page that submits three values to another page which works so that not the problem... All those parameters show up fine (print_r) on said update page. The first problem I'm having is getting the update page to show which values currently exist. what values are you talking about? currently exist where? This is the multi select box and the (adodb) recordset listing all the options. I'm lacking something in the page though that allow it to see which values are already chosen in the database: select name=inds[] size=8 multiple id=inds[] ?php while(!$rsInds-EOF){ ? option value=?php echo rsInds-Fields('CareerIDs')? ?php if (count($IndID) 0 AND is_array($IndID)) { use not AND unless you know what your doing! they are different. also you check the count() on $IndID before you check its an array! another thing: $IndID and $rsInds are pretty meaningless to the rest of the world, and they will be to you as well in 6 months time! use a few extra chars and give the vars meaningfully, easily idenfiable names (helps us guess what you are doing too!) foreach ($IndID as $ind) { ? ?php if ($rsInds-Fields('IndID')== $ind) {echo SELECTED;} } }? ?php echo $rsInds-Fields('CareerCategories')?/option ?php $rsInds-MoveNext(); } $rsInds-MoveFirst(); that looks evil; seeing as I a still have no idea what your actually stuck on I'll give you a quick lesson in writing neater/better code: // begin code sample --- $opts = array(); $IndID = (array) $IndID; while (!$rsInds-EOF) { /* is this option selected? */ $selected = in_array($rsInds-Fields('IndID'), $IndID) ? 'selected=selected' : ''; /* build the option */ $opts[] = sprintf('option value=%s %s%s/option', rsInds-Fields('CareerIDs'), $selected, $rsInds-Fields('CareerCategories')); $rsInds-MoveNext(); } /* output the complete select element, * you don't have to output directly!!! * you could stuff the strings into another * var and echo it out later (e.g. after all * processing has been done) */ echo 'select name=inds[] size=8 multiple id=inds[]'; echo join(\n, $opts); echo '/select'; $rsInds-MoveFirst(); // end code sample --- excuse the strange layout a, I like short lines. b, I find tertiary if statements very readable when spread across multiple lines. c, I'm try to avoid nasty linewrap due to mail setups. BTW - the above is not syntax checked. anyone care to say this is _not_ more readable? I've added this in the script, which prints out fine once I've submitted the page. Not sure if I need something similar for the records that already exist ? neither do I! if (count($inds) 0 AND is_array($inds)) { $ind = '.implode(',', $inds).'; } looks like you want to do a select statement with $ind in the form of SELECT * FROM yourtable WHERE yourfield IN ($inds) heh why not! Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Update Multiple records
I want to update a MySQL db table, but I want to update multiple records, Like this: I want to run a statement like this: update weld_details set parent = '1' where db_uid = '1','2' Now, it dont work, and I cant see why, I think it has something to do with the numbers at the end of the statement. But I cant see what... Pls help. Thanks in advance. -- Ben Cairns - Head Of Technical Operations intasept.COM Tel: 01332 365333 Fax: 01332 346010 E-Mail: [EMAIL PROTECTED] Web: http://www.intasept.com MAKING sense of the INFORMATION TECHNOLOGY age @ WORK.. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Update Multiple records
Hi Ben, I think U can use: [...] where db_uid = '1' or db_uid = '2' ... OR [...] where db_uid in ('1', '2', ...) Hope this helps. Greetinx, Mike Michael Rudel - Web-Development, Systemadministration - ___ Suchtreffer AG Bleicherstraße 20 D-78467 Konstanz Germany fon: +49-(0)7531-89207-17 fax: +49-(0)7531-89207-13 e-mail: mailto:[EMAIL PROTECTED] internet: http://www.suchtreffer.de ___ -Original Message- From: Ben Cairns [mailto:[EMAIL PROTECTED]] Sent: Thursday, May 17, 2001 10:29 AM To: [EMAIL PROTECTED] Subject: [PHP-DB] Update Multiple records I want to update a MySQL db table, but I want to update multiple records, Like this: I want to run a statement like this: update weld_details set parent = '1' where db_uid = '1','2' Now, it dont work, and I cant see why, I think it has something to do with the numbers at the end of the statement. But I cant see what... Pls help. Thanks in advance. -- Ben Cairns - Head Of Technical Operations intasept.COM Tel: 01332 365333 Fax: 01332 346010 E-Mail: [EMAIL PROTECTED] Web: http://www.intasept.com MAKING sense of the INFORMATION TECHNOLOGY age @ WORK.. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Update Multiple records
I think , You should do following : update weld_details set parent = '1' where db_uid = '1' or db_uid = '2' Ben Cairns wrote: I want to update a MySQL db table, but I want to update multiple records, Like this: I want to run a statement like this: update weld_details set parent = '1' where db_uid = '1','2' Now, it dont work, and I cant see why, I think it has something to do with the numbers at the end of the statement. But I cant see what... Pls help. Thanks in advance. -- Ben Cairns - Head Of Technical Operations intasept.COM Tel: 01332 365333 Fax: 01332 346010 E-Mail: [EMAIL PROTECTED] Web: http://www.intasept.com "MAKING sense of the INFORMATION TECHNOLOGY age @ WORK.." -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]