Re: [PHP] Problems with apc extension on wamp server.
Hi. Yes, as it turned out, the extension was not loaded. While following some tutorial i added only apc.rfc1867 = 1 to php.ini. Turns out that this particular line turns on one of apc functions (file tracking), but not the apc itself. However, now when i have apc turned on i still have a problem with file upload tracking: the apc_fetch(upload_xxx) returns information only when the file download is finished. while it is in progress, the result is false(0). Any ideas? 2009/6/17 Jonathan Tapicer tapi...@gmail.com: Hi, Does the extension appear on a phpinfo()? Seems like the extension isn't loaded. Jonathan On Tue, Jun 16, 2009 at 5:20 PM, Valentinas Bakaitisv.bakai...@gmail.com wrote: Hello! I am trying to track file upload progress using APC extension. However, when trying to use, it gives Fatal error: Call to undefined function apc_fetch() in C:\wamp\www\old\getprogress.php on line 3 I am using WAMP 2.0, with php 5.2.8 APC extension appear on extensions list and is enabled. Any ideas what i am doing wrong? here is the code of getprogress.php: * * $upload = apc_fetch('upload_1'); if ($upload) { if ($upload['done']) $percent = 100; else if ($upload['total'] == 0) $percent = 0; else $percent = $upload['current'] / $upload['total'] * 100; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Link to .php page with session
Stuart wrote: 2009/6/16 santel san...@siscom.it: Hi, I have a .php page that use sessions and shows a file .FLV by transcoding, on the fly, from any format video to FLV using a shell command [ system(/usr/bin/ffmpeg -re -i ./file.wmv -f flv -an -sameq -) ]. In a .php page: case 1): if j put a link to any page without session, all is ok; case 2): if j put a link to .php page with session -- when j click the link, the link take place only after system() command execution end. Is there a way to obtain case 1) behaviour also in case 2) ? I may have interpreted your problem incorrectly, but I think your problem is due to the session data not being saved until the script has finished running, including the system call. To get around this you can save and close the session before calling system using the session_write_close [1] function. Note that after calling that you won't be able to make any other changes to the session data in that request. -Stuart [1] http://php.net/session_write_close Hi Stuart, You are right, session_write_close solved the problem. Thank you very much Sante Luciani -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Persistent data between two executions
(Man, this reply-all takes some getting used to...) As long as your objects don't contain any reference variables (see manual) you can just assign the object to an element of $_SESSION and leave it at that. The session management code takes care of the serialization. So you're just duplicating work thats already done by serializing the object before putting it in $_SESSION. $_SESSION['myobj'] = new MyObj('string data',63453.2342); Then you can access it from any script during the session... var_dump($_SESSION['myobj']); You can also write custom session storage code and set it using session_set_save_handler(). The default save handler writes to flat files. You could write a handler that saves your data to a database (or whatever storage mechanism you wish to use) which with proper database design and caching will greatly improve the performance of handling the amount of session data you are talking about. On Tue, Jun 16, 2009 at 11:56 PM, James Colanninoja...@colannino.org wrote: Martin Scotta wrote: You can use $_SESSION to store the object, and serialize to convert to string and reverse I like that idea. I think I may end up going that route. I have one question. This is VERY hypothetical, and mostly just to satisfy a curiosity, but let's assume that you write an application that supports a few hundred users, each of which happen to be logged on at the same time. Assuming that serialization/unserialization happens frequently in the application, how severely will that impact performance? I'd imagine quite a bit, since you're reading/writing a lot from disk, which is inherently slow. I suppose one interesting way to alleviate this problem on a per-machine basis would be to implement /tmp in a RAM disk, so that session data is effectively written to and read from memory instead of to and from the disk. I suppose the best solution would be to design things such that as little data as possible is serialized between page refreshes. James -- 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
RE: [PHP] populate form input option dropdown box from existing data
On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Re: sloppiness stupidity
On 17 June 2009 02:11, Shawn McKenzie advised: PJ wrote: I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. In my quest for a way to populate a multiple option select box I have run across so many errors that it's beyond belief... such nonsense as select for select or select=select ( think this is right, but then who knows?) I know. So does the HTML recommendation which states that it is a boolean attribute, meaning it is stated (on/boolean 1) or it isn't (off/boolean 0) in the HTML context. So while other variations may work, this is correct: For multiple select: SELECT multiple name=component-select --or-- For single select: SELECT name=component-select This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. Other differences you may see are because in most programming TIMTOWTDI[1], as perl would have it, and different people make different choices about which way to go. Then again, some *is* simply due to sloppiness, or under-explanation because of over-familiarity with the code or feature in question, or confidence in one's own misunderstanding! [1] There Is More Than One Way To Do It Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sloppiness stupidity
2009/6/17 PJ af.gour...@videotron.ca: I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. In my quest for a way to populate a multiple option select box I have run across so many errors that it's beyond belief... such nonsense as select for select or select=select ( think this is right, but then who knows?) other variations; then theres in_array() that has explanations about as clear as a cesspool - the way it's explained is not at all clear, -- and somebody did an in_array($tring, text) - which is reversed... don't these idiots read what they are putting up on the internet? And some of you wonder why I ask stupid questions? Rare, indeed, is the clear explanation or demonstration. I get the impression that there are a lot of asholeys out there who learn the less than basic programming and then forget that even a ignoramus as I can be looking for rather complicated guidance. The Internet was a great promise, but god is is overbloated with floating intellectual excrement. Sorry, but ranting sometimes is good for the psyche. :o I haven't really been following this thread, so I apologise if I've missed the point, but I don't see what's so hard about persisting selected values... http://dev.stut.net/php/pj/multiselect.php As far as the quality of information on the internet goes... were you actually born yesterday? Of course it sucks. If you want my advice you should buy a book to learn the basics. I can't really recommend one 'cause it's been a while since I've looked at a PHP book but you can pretty much guarantee that any book from the major technical publishers will have gone through several layers of checks before they printed it. Beyond that you need to learn how to read the manual. The description of in_array at http://php.net/in_array could not be any clearer if it tried - it even has examples. If you disagree then you should fix it and submit a patch to the documentation team. The only way open source stuff gets better is if you contribute changes when you think something can be improved. And with that I'm off to the zoo for the day! -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problems with apc extension on wamp server.
Found the problem: input type=hidden name=APC_UPLOAD_PROGRESS id=progress_key value=1 / must always be before file input in the form. 2009/6/17 Valentinas Bakaitis v.bakai...@gmail.com: Hi. Yes, as it turned out, the extension was not loaded. While following some tutorial i added only apc.rfc1867 = 1 to php.ini. Turns out that this particular line turns on one of apc functions (file tracking), but not the apc itself. However, now when i have apc turned on i still have a problem with file upload tracking: the apc_fetch(upload_xxx) returns information only when the file download is finished. while it is in progress, the result is false(0). Any ideas? 2009/6/17 Jonathan Tapicer tapi...@gmail.com: Hi, Does the extension appear on a phpinfo()? Seems like the extension isn't loaded. Jonathan On Tue, Jun 16, 2009 at 5:20 PM, Valentinas Bakaitisv.bakai...@gmail.com wrote: Hello! I am trying to track file upload progress using APC extension. However, when trying to use, it gives Fatal error: Call to undefined function apc_fetch() in C:\wamp\www\old\getprogress.php on line 3 I am using WAMP 2.0, with php 5.2.8 APC extension appear on extensions list and is enabled. Any ideas what i am doing wrong? here is the code of getprogress.php: * * $upload = apc_fetch('upload_1'); if ($upload) { if ($upload['done']) $percent = 100; else if ($upload['total'] == 0) $percent = 0; else $percent = $upload['current'] / $upload['total'] * 100; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] sloppiness stupidity
[snip] Excrement [/snip] Indeed. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] populate form input option dropdown box from existing data
sorry, maybe I have been lazy in that comment, I admit, whem wrote that solution I was in a such hurry and without time. I dont really read what I wrote, but now I think this solution is good. select name=categories multiple style='width:120px;height:150px' ? $sql = SELECT id,name FROM categories; if ( ( $results = mysql_query($sql, $conn) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected = ($id == $row['id'] ? 'selected=selected' : ''); echo option value=.$row['id']. .$selected..$row['name']./option; } } ? /select Date: Wed, 17 Jun 2009 10:16:15 +0100 From: m.f...@leedsmet.ac.uk To: php-general@lists.php.net Subject: RE: [PHP] populate form input option dropdown box from existing data On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Emoticons e Winks super diferentes para o Messenger. Baixe agora, é grátis! http://specials.br.msn.com/ilovemessenger/pacotes.aspx
RE: [PHP] populate form input option dropdown box from existing data
sorry, maybe I have been lazy in that comment, I admit, whem wrote that solution i was in a such hurry and without time. I dont really read what i wrote, but now i think this solution is good select name=categories multiple style='width:120px;height:150px' ? $sql = SELECT id,name FROM categories; if ( ( $results = mysql_query($sql, $conn) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected = ($id == $row['id'] ? 'selected=selected' : ''); echo option value=.$row['id']. .$selected..$row['name']./option; } } ? /select Date: Tue, 16 Jun 2009 20:46:29 -0400 From: af.gour...@videotron.ca To: a...@ashleysheridan.co.uk CC: gargari...@hotmail.com; m...@dajve.co.uk; php-general@lists.php.net; tedd.sperl...@gmail.com; nos...@mckenzies.net Subject: Re: [PHP] populate form input option dropdown box from existingdata Ashley Sheridan wrote: On Tue, 2009-06-16 at 18:19 -0400, PJ wrote: Ashley Sheridan wrote: On Tue, 2009-06-16 at 15:48 -0400, PJ wrote: jenai tomaka wrote: You can try like this, $row = stored data; and write the options like this option value=id (id == $row ? selected : ) /option Yuri Yarlei. http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8 Yuri, I'm still wet behind the ears on this so I don't quite understand what you mean by stored data ; and what does the id (id==$row?selected:) mean? I get the idea that this might be translated into something in the code I have dreamed up - further down. echo option value=, $row['id'], , $row['category'], /optionbr /; I suppose that I must add an if clause to insert the selected option for the categories that are relevant... Gentlemen, I have been diligently studying all this and have just returned my attention to the list, so I've read the replies/inputs and now comment: BTW, I had some problems with the multiple statement - it does not take any parameters; it must simply be stated multiple without quotes. Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } ? /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php option value=id (id == $row ? selected : ) /option is pretty bad HTML, as attributes should always have a value. Personally, I do something like this as it tends not to confuse the code too much $selected = ($id == $row)?'selected=selected':''; print option value=\$id\ $selected /option; I was unable to get any of the suggestions to work, except in_array(). However, the selected item refuses to become highlighted. code: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; //$selected = ($id == $row)?'selected=selected':''; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { if (in_array($row['id'], $ccc)) { echo option value=, $row['id'], selected , $row['category'], /optionbr /; } else echo option value=, $row['id'], , $row['category'], /optionbr /; } } ? /select I can't find anything that explains why the selected item is not highlighted. --
RE: [PHP] sloppiness stupidity
I agree, this list is to learn and improve skills in php laguage. not to discriminate the others when they try to help someone or trying to learn somethings Date: Tue, 16 Jun 2009 20:50:57 -0400 From: asny...@noloh.com To: af.gour...@videotron.ca; php-general@lists.php.net Subject: RE: [PHP] sloppiness stupidity While ranting might be good for the psyche there are trained psychiatric professionals that will readily listen to your rants. The PHP mailing list is not the place to vent. In every large community there will be those with less experience than others, and yes, many inexperienced programmers that will do whatever it takes to get things working, even if that means copying and pasting code they don't understand. Instead of ranting, a more useful approach would be to create a post that properly informs a user on how to populate a multiple option select box and eventually rank higher than any incorrect postings. -Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Tuesday, June 16, 2009 8:44 PM To: php-general@lists.php.net Subject: [PHP] sloppiness stupidity I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. In my quest for a way to populate a multiple option select box I have run across so many errors that it's beyond belief... such nonsense as select for select or select=select ( think this is right, but then who knows?) other variations; then theres in_array() that has explanations about as clear as a cesspool - the way it's explained is not at all clear, -- and somebody did an in_array($tring, text) - which is reversed... don't these idiots read what they are putting up on the internet? And some of you wonder why I ask stupid questions? Rare, indeed, is the clear explanation or demonstration. I get the impression that there are a lot of asholeys out there who learn the less than basic programming and then forget that even a ignoramus as I can be looking for rather complicated guidance. The Internet was a great promise, but god is is overbloated with floating intellectual excrement. Sorry, but ranting sometimes is good for the psyche. :o -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- 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 _ Deixe suas conversas mais divertidas. Baixe agora mesmo novos emoticons. É grátis! http://specials.br.msn.com/ilovemessenger/pacotes.aspx
Re: [PHP] populate form input option dropdown box from existing data
Ashley Sheridan wrote: On Tue, 2009-06-16 at 20:46 -0400, PJ wrote: Ashley Sheridan wrote: On Tue, 2009-06-16 at 18:19 -0400, PJ wrote: Ashley Sheridan wrote: On Tue, 2009-06-16 at 15:48 -0400, PJ wrote: jenai tomaka wrote: You can try like this, $row = stored data; and write the options like this option value=id (id == $row ? selected : ) /option Yuri Yarlei. http://brasil.microsoft.com.br/IE8/mergulhe/?utm_source=MSN%3BHotmailutm_medium=Taglineutm_campaign=IE8 Yuri, I'm still wet behind the ears on this so I don't quite understand what you mean by stored data ; and what does the id (id==$row?selected:) mean? I get the idea that this might be translated into something in the code I have dreamed up - further down. echo option value=, $row['id'], , $row['category'], /optionbr /; I suppose that I must add an if clause to insert the selected option for the categories that are relevant... Gentlemen, I have been diligently studying all this and have just returned my attention to the list, so I've read the replies/inputs and now comment: BTW, I had some problems with the multiple statement - it does not take any parameters; it must simply be stated multiple without quotes. Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } ? /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php option value=id (id == $row ? selected : ) /option is pretty bad HTML, as attributes should always have a value. Personally, I do something like this as it tends not to confuse the code too much $selected = ($id == $row)?'selected=selected':''; print option value=\$id\ $selected /option; I was unable to get any of the suggestions to work, except in_array(). However, the selected item refuses to become highlighted. code: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; //$selected = ($id == $row)?'selected=selected':''; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { if (in_array($row['id'], $ccc)) { echo option value=, $row['id'], selected , $row['category'], /optionbr /; } else echo option value=, $row['id'], , $row['category'], /optionbr /; } } ? /select I can't find anything that explains why the selected item is not highlighted. -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php Have you actually looked at the html this produces to see if any of the elements are being marked with the selected=selected attribute? Thanks Ash www.ashleysheridan.co.uk I just cannot find a way to pass the selected fields to the options script. Even if I add the selected to all the fields, they show up in the source code but the fields are still not highlighted. There has to be a way to get this right??? :'( -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan
Re: [PHP] populate form input option dropdown box from existing data
Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Disclaimer
Daniel: At 2:27 PM -0400 6/16/09, Daniel Brown wrote: You can change the hidden field to a regular text field (even disable it from editing), a div, or whatever. Just don't use the price as a hidden field on the production site. The above code is for example only. Take with food. Batteries not included. Cannot be combined with any other offer. See store for details. May cause cancer. Women who are pregnant or may become pregnant must not use this product. Limit one per customer. Contains Red Lake #5. Do not operate machinery after consuming. No pets allowed. Not responsible for lost or misdirected mail. Contains tree nuts. Wash before using. Keep out of reach of children. May cause drowsiness. Use as directed. While supplies last. Do not inhale. Neat. Here's mine. The above code is for example only. No cash value. While supplies last. Cannot be combined with any other offer. See store for details. Limit one per family. Batteries not included. Use as directed. Women who are pregnant or may become pregnant must not use this product. May contain Red Dye #1. Take with food. May cause drowsiness. Do not operate machinery after consuming. Keep away from pets and out of reach of children. If you experience loss of eyesight seek medical attention immediately. Keep extremities away from spinning blades. Absolutely not responsible for anything at anytime for any reason whatsoever. Anyone else? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Disclaimer
[snip] -Original Message- From: tedd [mailto:t...@sperling.com] Sent: Wednesday, June 17, 2009 9:07 AM To: php-general@lists.php.net Subject: [PHP] Disclaimer Daniel: At 2:27 PM -0400 6/16/09, Daniel Brown wrote: You can change the hidden field to a regular text field (even disable it from editing), a div, or whatever. Just don't use the price as a hidden field on the production site. The above code is for example only. Take with food. Batteries not included. Cannot be combined with any other offer. See store for details. May cause cancer. Women who are pregnant or may become pregnant must not use this product. Limit one per customer. Contains Red Lake #5. Do not operate machinery after consuming. No pets allowed. Not responsible for lost or misdirected mail. Contains tree nuts. Wash before using. Keep out of reach of children. May cause drowsiness. Use as directed. While supplies last. Do not inhale. Neat. Here's mine. The above code is for example only. No cash value. While supplies last. Cannot be combined with any other offer. See store for details. Limit one per family. Batteries not included. Use as directed. Women who are pregnant or may become pregnant must not use this product. May contain Red Dye #1. Take with food. May cause drowsiness. Do not operate machinery after consuming. Keep away from pets and out of reach of children. If you experience loss of eyesight seek medical attention immediately. Keep extremities away from spinning blades. Absolutely not responsible for anything at anytime for any reason whatsoever. Anyone else? [/snip] /* Isn't it somewhat satisfying to reach the end of the code? After all, you have taken several moments to peruse and analyze some relatively simple code. You can either be satisfied or you can have some regret that you will never get those moments back now that you realize that there is nothing earth-shattering in the code. It is pretty simple. So you went on to read the lengthy comments at the bottom of the code and you realize that it is pure drivel toobut it is too late. Several more moments have gone by and like a traffic accident on the freeway you still slow down in hopes that you will see something that will what? Increase your quality of life? Get over it. Sincerely, His Most Royal and Exhaulted Grand Imperial Schmoove Poobah 42 - Electric Boogaloo P.S. I though about typing a missive long enough to make this a number of lines of code divisible by 42, but I got over it. I wonder if all of this could be squeezed into 42 lines of code (and not those really long lines either)? That would be something, wouldn't it? P.S.S. You're still here? */ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disclaimer
On Wed, Jun 17, 2009 at 10:24, Jay Blanchardjblanch...@pocket.com wrote: [snip!] P.S. I though about typing a missive long enough to make this a number of lines of code divisible by 42, but I got over it. I wonder if all of this could be squeezed into 42 lines of code (and not those really long lines either)? That would be something, wouldn't it? Coincidentally, the above is 178 words. ?php $wordcount = 178; echo round(($wordcount / 42),1); ? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Disclaimer
[snip!] P.S. I though about typing a missive long enough to make this a number of lines of code divisible by 42, but I got over it. I wonder if all of this could be squeezed into 42 lines of code (and not those really long lines either)? That would be something, wouldn't it? Coincidentally, the above is 178 words. ?php $wordcount = 178; echo round(($wordcount / 42),1); ? [/snip!] Whoa! Totally unintentional dude! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Php and regex help or advice
Hi Everyone, Ok, so I've been plunged further into using php by being tasked to use it with regex (yes tylenol extra strength needed please) So far I have my code that grabs a full block of text by paragraphs, now I have to somehow write a snippet that goes inside this block and pulls out each line and puts each line in a db, the different lines of text are broken with br tags so that should be fairly simple? Right, here is what I have so far, I have played with some of the regex tester tools online but am not having any luck once inside the first block, which makes me think I'm doing it wrong. My wobbley code thus far I know it must have a long way to go: This grabs everything paragraph by paragraph: ?php $results = preg_match_all('/pfont size=2 face=Arial, Helvetica, sans-serif(.+)br(.+)br(.+)Critical Violations Found:/imsU'); Now I need to grab each line in the paragraph and am stuck:. //---at some point I have to strip the tags off of what will be put in the db--// $raw = strip_tags($results); echo $raw; ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disclaimer
On Wed, Jun 17, 2009 at 10:40 AM, Daniel Browndanbr...@php.net wrote: On Wed, Jun 17, 2009 at 10:37, Jay Blanchardjblanch...@pocket.com wrote: Whoa! Totally unintentional dude! DON'T PANIC! -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php Hang on to your towel! -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sloppiness stupidity
On Wed, Jun 17, 2009 at 8:57 AM, Yuri Yarleigargari...@hotmail.com wrote: I agree, this list is to learn and improve skills in php laguage. not to discriminate the others when they try to help someone or trying to learn somethings Date: Tue, 16 Jun 2009 20:50:57 -0400 From: asny...@noloh.com To: af.gour...@videotron.ca; php-general@lists.php.net Subject: RE: [PHP] sloppiness stupidity While ranting might be good for the psyche there are trained psychiatric professionals that will readily listen to your rants. The PHP mailing list is not the place to vent. In every large community there will be those with less experience than others, and yes, many inexperienced programmers that will do whatever it takes to get things working, even if that means copying and pasting code they don't understand. Instead of ranting, a more useful approach would be to create a post that properly informs a user on how to populate a multiple option select box and eventually rank higher than any incorrect postings. -Original Message- From: PJ [mailto:af.gour...@videotron.ca] Sent: Tuesday, June 16, 2009 8:44 PM To: php-general@lists.php.net Subject: [PHP] sloppiness stupidity I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. In my quest for a way to populate a multiple option select box I have run across so many errors that it's beyond belief... such nonsense as select for select or select=select ( think this is right, but then who knows?) other variations; then theres in_array() that has explanations about as clear as a cesspool - the way it's explained is not at all clear, -- and somebody did an in_array($tring, text) - which is reversed... don't these idiots read what they are putting up on the internet? And some of you wonder why I ask stupid questions? Rare, indeed, is the clear explanation or demonstration. I get the impression that there are a lot of asholeys out there who learn the less than basic programming and then forget that even a ignoramus as I can be looking for rather complicated guidance. The Internet was a great promise, but god is is overbloated with floating intellectual excrement. Sorry, but ranting sometimes is good for the psyche. :o -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- 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 _ Deixe suas conversas mais divertidas. Baixe agora mesmo novos emoticons. É grátis! http://specials.br.msn.com/ilovemessenger/pacotes.aspx http://www.weberdev.com/get_example-3852.html may helpi wrote it some time ago but it might point you in a new direction -- Bastien Cat, the other other white meat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sloppiness stupidity
At 8:43 PM -0400 6/16/09, PJ wrote: I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. Then stop doing it. You appear to be mixing apples and oranges in your questions. I find your questions not well thought-out nor to the point. For example, you talk about using a SELECT control and then mix that with using a SELECT statement in MySQL -- no wonder you're confused and are not getting the answers you want. The art of programming is to identify a problem, take it apart, and then solve it in smaller easy-to-understand steps. You can't hope for a big solution that will solve everything. Problems are not like that. In this thread you asked how to populate an array from a SELECT control and I provided a solution -- here's a link: http://php1.net/b/form-select/index.php But for my efforts, it doesn't seem that you even reviewed what I provided. Now you ask how to use the select attribute in a SELECT control and here's another solution for you to ignore: http://php1.net/b/form-select1/index.php For closure of the thought, you might also review: http://php1.net/b/form-checkbox/index.php http://php1.net/b/form-checkbox1/index.php You know, part of this QA thing is to read/review what's been provided for you and respond to it. Remember, we're trying to help you, not the other way around. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] inserting blobs into mysql
i'm having trouble getting binary data into blobs in mysql. to help debug, i set up a test db and discovered that when i insert a binary string encoded using mysql_real_escape_string (according to the php manual: If binary data is to be inserted, this function must be used.), only byte values lower than 128 are accepted. all bytes in the string with value greater equal 128 are stripped out upon insertion, regardless where they appear in the string. so, for example if i create a test binart string thus: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n) . chr($n+128); and inset it (using mysql_real_escape_string), the blob value that appears as viewed with phpmyadmin is only 128 bytes long. and when i select it, the value i get back is the same as if i had inserted: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n); any idea why? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Totally weird behavior trying to download a Mac DMG file
On 6/16/09 1:40 PM, Brian Dunning br...@briandunning.com wrote: However, when I complete a test purchase and download using the above code, the DMG file downloads, but then it mounts; the contents are copied into the Downloads folder; the image unmounts; and then deletes. All the contents are delivered, but not in a desirable way. what headers are sent by the server when you don't use your php script? try sending those headers instead. perhaps try application/force-download as the content type instead. for several user agents this seems to prevent then from doing something useful with the file and just save it instead. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
On Wed, 2009-06-17 at 10:01 -0400, PJ wrote: Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php in_array() does work with associative arrays, I used it myself before! Don't forget, it only attempts to match the value in an associative array, not the key. Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Help: PHP version not up to date after apt-get install php5-dev
Dear PHP [hard]core expert After apt-get install php5-dev on Linux (Debian, Ubuntu, Hardy Heron) with an already existing and functioning PHP5 interpreter phpinfo() still shows PHP Version 5.2.4-2ubuntu5.6. BUT at the same time phpinfo() shows Build Date: April 17 2009! This seems incongruent to me! PHP 5.2.4 is from the year 2007!!! Which version of PHP does my server run now? How can I find out in this mess? Do I really need to deinstall and reinstall PHP in order to get the right version displayed? Thank you very much for your brief info about this confusion! Philipp Schaffner, Switzerland -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
PJ wrote: It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. The name is not what makes it work. That's just an example name I copied from w3c. It could be anything. What makes it work is the multiple. This will work just as well (notice you need the array if you want multiple values passed in $_POST): select name=pjs-select-thing[] multiple -Shawn I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: inserting blobs into mysql
false alarm. the error was in my mysql abstraction class. some time ago i put a function in there to clean up invalid utf8 strings and it was doing a nice job on my binary strings. On 6/17/09 1:24 PM, Tom Worster f...@thefsb.org wrote: i'm having trouble getting binary data into blobs in mysql. to help debug, i set up a test db and discovered that when i insert a binary string encoded using mysql_real_escape_string (according to the php manual: If binary data is to be inserted, this function must be used.), only byte values lower than 128 are accepted. all bytes in the string with value greater equal 128 are stripped out upon insertion, regardless where they appear in the string. so, for example if i create a test binart string thus: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n) . chr($n+128); and inset it (using mysql_real_escape_string), the blob value that appears as viewed with phpmyadmin is only 128 bytes long. and when i select it, the value i get back is the same as if i had inserted: $data = ''; for ( $n=0; $n=127; $n++ ) $data .= chr($n); any idea why? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Help: PHP version not up to date after apt-get install php5-dev
Philipp Schaffner wrote: Dear PHP [hard]core expert After apt-get install php5-dev on Linux (Debian, Ubuntu, Hardy Heron) with an already existing and functioning PHP5 interpreter phpinfo() still shows PHP Version 5.2.4-2ubuntu5.6. BUT at the same time phpinfo() shows Build Date: April 17 2009! This seems incongruent to me! PHP 5.2.4 is from the year 2007!!! Which version of PHP does my server run now? How can I find out in this mess? Do I really need to deinstall and reinstall PHP in order to get the right version displayed? Thank you very much for your brief info about this confusion! Philipp Schaffner, Switzerland What you installed are development (source) files needed to build PHP modules. $ apt-cache show php5-dev Version: 5.2.4-2ubuntu5.6 Description: Files for PHP5 module development This package provides the files from the PHP5 source needed for compiling additional modules. AFAIK you're out of luck on Ubuntu for releases newer than 5.2.4 at the moment. Unless you want to add a Debian repository or another third party one. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
Ashley Sheridan wrote: On Wed, 2009-06-17 at 10:01 -0400, PJ wrote: Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php in_array() does work with associative arrays, I used it myself before! Don't forget, it only attempts to match the value in an associative array, not the key. Could you show me how, because just running in_array($test_string, $assoc_array) never produced a result regardless of what I put into the $test_string or even if I used value, value, 'value', 14, 14, '14', and the corresponding string existed in the array - the results were zip, zero, nothing; like a dead fish. And now there is another little glitch, if the array finds that there is no category listed, then I get an error of undeclared variable... man, talk about contortions... :-( -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List
Re: [PHP] Re: Help: PHP version not up to date after apt-get install php5-dev
Why not just compile it yourself? On Wed, Jun 17, 2009 at 3:34 PM, Shawn McKenzienos...@mckenzies.net wrote: Philipp Schaffner wrote: Dear PHP [hard]core expert After apt-get install php5-dev on Linux (Debian, Ubuntu, Hardy Heron) with an already existing and functioning PHP5 interpreter phpinfo() still shows PHP Version 5.2.4-2ubuntu5.6. BUT at the same time phpinfo() shows Build Date: April 17 2009! This seems incongruent to me! PHP 5.2.4 is from the year 2007!!! Which version of PHP does my server run now? How can I find out in this mess? Do I really need to deinstall and reinstall PHP in order to get the right version displayed? Thank you very much for your brief info about this confusion! Philipp Schaffner, Switzerland What you installed are development (source) files needed to build PHP modules. $ apt-cache show php5-dev Version: 5.2.4-2ubuntu5.6 Description: Files for PHP5 module development This package provides the files from the PHP5 source needed for compiling additional modules. AFAIK you're out of luck on Ubuntu for releases newer than 5.2.4 at the moment. Unless you want to add a Debian repository or another third party one. -- Thanks! -Shawn http://www.spidean.com -- 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
Re: [PHP] populate form input option dropdown box from existing data
PJ wrote: Ashley Sheridan wrote: On Wed, 2009-06-17 at 10:01 -0400, PJ wrote: Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php in_array() does work with associative arrays, I used it myself before! Don't forget, it only attempts to match the value in an associative array, not the key. Could you show me how, because just running in_array($test_string, $assoc_array) never produced a result regardless of what I put into the $test_string or even if I used value, value, 'value', 14, 14, '14', and the corresponding string existed in the array - the results were zip, zero, nothing; like a dead fish. Pretty simple: $needle01 = 1; $needle02 = 'test name'; $haystack = array('id' = 1, name = 'test name'); if (in_array($needle01, $haystack)) { echo FOUND $needle01; } if (in_array($needle02, $haystack)) { echo FOUND $needle02; } And now there is another little glitch, if the array finds that there is no category listed, then I get an error of undeclared variable... man, talk about contortions... :-( I don't know
Re: [PHP] Re: sloppiness stupidity
On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. /Nisse -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Multi-Sort -- how to do this?
Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ... $c[] = ... $d[] = ... } Now, let's say you want to sort the $d array, but you also want the arrays $a, $b, and $c to be arranged in the same resultant order as $d. For example, please follow this: Before sort of $d: $a = [apple, banana, grape, orange] $b = [100, 2111, 198, 150] $c = [red, yellow, purple, orange] $d = [100, 300, 11, 50] After sort of $d: $a = [grape, orange, apple, banana] $b = [198, 150, 100, 2111] $c = [purple, orange, red, yellow] $d = [11, 50, 100, 300] Is there a slick way to do that? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
On Wed, 2009-06-17 at 16:29 -0400, PJ wrote: Ashley Sheridan wrote: On Wed, 2009-06-17 at 10:01 -0400, PJ wrote: Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php in_array() does work with associative arrays, I used it myself before! Don't forget, it only attempts to match the value in an associative array, not the key. Could you show me how, because just running in_array($test_string, $assoc_array) never produced a result regardless of what I put into the $test_string or even if I used value, value, 'value', 14, 14, '14', and the corresponding string existed in the array - the results were zip, zero, nothing; like a dead fish. And now there is another little glitch, if the array finds that there is no category listed, then I get an error of undeclared variable... man, talk about contortions... :-( I'm using this code on a site, and it works: $styles = Array('main' = 'Pastel', 'modern' = 'Modern');
Re: [PHP] Re: sloppiness stupidity
On Wed, 2009-06-17 at 23:05 +0200, Nisse Engström wrote: On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. /Nisse I read somewhere that the XHTML standards say that for all attributes that would normally be standalone in HTML, they should be given a value that is the same as the attribute name, so you would use multiple=multiple, selected=selected, checked=checked, etc. As far as I know, using this in regular HTML won't cause it to choke either, as the parsers tend to only look at the existence of the attributes, not the values they may or may not have. Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
On Wed, 2009-06-17 at 17:11 -0400, tedd wrote: Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ... $c[] = ... $d[] = ... } Now, let's say you want to sort the $d array, but you also want the arrays $a, $b, and $c to be arranged in the same resultant order as $d. For example, please follow this: Before sort of $d: $a = [apple, banana, grape, orange] $b = [100, 2111, 198, 150] $c = [red, yellow, purple, orange] $d = [100, 300, 11, 50] After sort of $d: $a = [grape, orange, apple, banana] $b = [198, 150, 100, 2111] $c = [purple, orange, red, yellow] $d = [11, 50, 100, 300] Is there a slick way to do that? Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all have the same index, like in your example. If you were using keys, could you maybe join all the arrays using some sort of serialisation, sort, then unserialise into the separate arrays? Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
...Sticking my neck out playing with the big boys (and girls) now... I assume you've looked at array_multisort() for this, I would think you could have multiple arrays being sorted with it (I've only ever used it for 2-array sorts). The other option would be to pop all those arrays into a single array and use array_multisort()'s ability to sort arrays-within-arrays. Otherwise Ashley's solution is another possibility; using the keys in the sorted $d to dictate where you could place the elements in the other arrays. I'd say you could do a nifty loop system which says sequentially read the indices in $d and then make a new temp array that is $a, $b or $c (depending on which you are sorting) in the sorted order then just name the temp array as the original (again, I'd say array_multisort() is fancier than this crude but elegant system). Finally, why not use quicksort or mergesort for the sorting? Bubblesort is inefficient for large lists...
Re: [PHP] Multi-Sort -- how to do this?
On Wed, 2009-06-17 at 22:54 +0100, Douglas Temple wrote: ...Sticking my neck out playing with the big boys (and girls) now... I assume you've looked at array_multisort() for this, I would think you could have multiple arrays being sorted with it (I've only ever used it for 2-array sorts). The other option would be to pop all those arrays into a single array and use array_multisort()'s ability to sort arrays-within-arrays. Otherwise Ashley's solution is another possibility; using the keys in the sorted $d to dictate where you could place the elements in the other arrays. I'd say you could do a nifty loop system which says sequentially read the indices in $d and then make a new temp array that is $a, $b or $c (depending on which you are sorting) in the sorted order then just name the temp array as the original (again, I'd say array_multisort() is fancier than this crude but elegant system). Finally, why not use quicksort or mergesort for the sorting? Bubblesort is inefficient for large lists... I only mention using a bubblesort as it is the only sorting algorithm i know! Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
Yuri Yarlei wrote: sorry, maybe I have been lazy in that comment, I admit, whem wrote that solution I was in a such hurry and without time. I dont really read what I wrote, but now I think this solution is good. select name=categories multiple style='width:120px;height:150px' ? $sql = SELECT id,name FROM categories; if ( ( $results = mysql_query($sql, $conn) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected = ($id == $row['id'] ? 'selected=selected' : ''); echo option value=.$row['id']. .$selected..$row['name']./option; } } ? /select doesnt quite work: there was a conflict with a $id that I fixed; but your code did not pass the $selected ids - don't know why. Here's what finally worked and it required the categoriesIN[] for the name: echo select name='categoriesIN[]' multiple size='8'; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { if (in_array($row['id'], $selected)) { echo option value=, $row['id'], selected , $row['category'], /optionbr /; } else echo option value=, $row['id'], , $row['category'], /optionbr /; } } I think it will work now. Thanks much for the input the support. :-) Date: Wed, 17 Jun 2009 10:16:15 +0100 From: m.f...@leedsmet.ac.uk To: php-general@lists.php.net Subject: RE: [PHP] populate form input option dropdown box from existing data On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. Cheers! Mike -- Mike Ford, Electronic Information Developer, C507, Leeds Metropolitan University, Civic Quarter Campus, Woodhouse Lane, LEEDS, LS1 3HE, United Kingdom Email: m.f...@leedsmet.ac.uk Tel: +44 113 812 4730 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php _ Emoticons e Winks super diferentes para o Messenger. Baixe agora, � gr�tis! http://specials.br.msn.com/ilovemessenger/pacotes.aspx
Re: [PHP] populate form input option dropdown box from existing data
Shawn McKenzie wrote: PJ wrote: Ashley Sheridan wrote: On Wed, 2009-06-17 at 10:01 -0400, PJ wrote: Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php in_array() does work with associative arrays, I used it myself before! Don't forget, it only attempts to match the value in an associative array, not the key. Could you show me how, because just running in_array($test_string, $assoc_array) never produced a result regardless of what I put into the $test_string or even if I used value, value, 'value', 14, 14, '14', and the corresponding string existed in the array - the results were zip, zero, nothing; like a dead fish. Pretty simple: $needle01 = 1; $needle02 = 'test name'; $haystack = array('id' = 1, name = 'test name'); if (in_array($needle01, $haystack)) { echo FOUND $needle01; } if (in_array($needle02, $haystack)) { echo FOUND $needle02; } And now there is another little glitch, if the array finds that there is no category listed, then I get an error of undeclared variable... man, talk about contortions... :-( I don't know what you mean
[PHP] Using large multi dimenstional arrays in js
Hello all, My new project needs to use large multi dimenstional php arrays in javascript. I'm not sure how to do it. Is there any lead or any one give a clue. Regards Sancar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Using large multi dimenstional arrays in js
Hi... you can use 'json_encode'... http://de2.php.net/manual/de/function.json-encode.php like this... script type=text/javascript var my_js_array = ?= json_encode($my_php_array) ?; /script YT BB Am 18.06.2009 um 00:32 schrieb Sancar Saran: Hello all, My new project needs to use large multi dimenstional php arrays in javascript. I'm not sure how to do it. Is there any lead or any one give a clue. Regards Sancar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php [Björn Bartels ] [email : bart...@dragon-projects.de ] [home : http://dragon-projects.de ] [skype : bb-drummer ] [--- ] Diese E-Mail könnte vertrauliche und/oder rechtlich geschützte Informationen enthalten. Wenn Sie nicht der richtige Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie bitte sofort den Absender und vernichten Sie diese Mail. Das unerlaubte Kopieren sowie die unbefugte Weitergabe dieser Mail sind nicht gestattet. This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorised copying, disclosure or distribution of the material in this e-mail is strictly forbidden. [--- ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
Nisse Engström wrote: On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. From my limited experience, and vast reading of those glorious 20,000 entries on the Internet, multiple does not take a parameter. I had my fingers slapped once when I validated or something - multiple is just plain multiple ! :-P ;-) :-) -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] sloppiness stupidity
:-* Matty Sarro wrote: *hug* I think that's what you were really asking for. -Matty On Tue, Jun 16, 2009 at 8:43 PM, PJ af.gour...@videotron.ca mailto:af.gour...@videotron.ca wrote: I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. In my quest for a way to populate a multiple option select box I have run across so many errors that it's beyond belief... such nonsense as select for select or select=select ( think this is right, but then who knows?) other variations; then theres in_array() that has explanations about as clear as a cesspool - the way it's explained is not at all clear, -- and somebody did an in_array($tring, text) - which is reversed... don't these idiots read what they are putting up on the internet? And some of you wonder why I ask stupid questions? Rare, indeed, is the clear explanation or demonstration. I get the impression that there are a lot of asholeys out there who learn the less than basic programming and then forget that even a ignoramus as I can be looking for rather complicated guidance. The Internet was a great promise, but god is is overbloated with floating intellectual excrement. Sorry, but ranting sometimes is good for the psyche. :o -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com mailto:p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
At 10:51 PM +0100 6/17/09, Ashley Sheridan wrote: On Wed, 2009-06-17 at 23:05 +0200, Nisse Engström wrote: On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. /Nisse I read somewhere that the XHTML standards say that for all attributes that would normally be standalone in HTML, they should be given a value that is the same as the attribute name, so you would use multiple=multiple, selected=selected, checked=checked, etc. As far as I know, using this in regular HTML won't cause it to choke either, as the parsers tend to only look at the existence of the attributes, not the values they may or may not have. Thanks Ash Ash: As I understand it and is my experience, that is true -- a stand-alone HTML attribute should be equal to itself, such as selected=selected, or more specifically selected=SELECTED. However, it will still work but will throw a validation error/warning in some DOCTYPEs, such as XHTLM. I don't know of any other DOCTYPE that might throw such as error. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
At 10:54 PM +0100 6/17/09, Ashley Sheridan wrote: I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all have the same index, like in your example. If you were using keys, could you maybe join all the arrays using some sort of serialisation, sort, then unserialise into the separate arrays? Thanks Ash Ash: You missed the point. I could use the built-in sort (i.e., sort() ) and sort the $d array. However, I would like the indexes of the other arrays to match the new sort. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
On Wed, 2009-06-17 at 18:59 -0400, tedd wrote: At 10:51 PM +0100 6/17/09, Ashley Sheridan wrote: On Wed, 2009-06-17 at 23:05 +0200, Nisse Engström wrote: On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. /Nisse I read somewhere that the XHTML standards say that for all attributes that would normally be standalone in HTML, they should be given a value that is the same as the attribute name, so you would use multiple=multiple, selected=selected, checked=checked, etc. As far as I know, using this in regular HTML won't cause it to choke either, as the parsers tend to only look at the existence of the attributes, not the values they may or may not have. Thanks Ash Ash: As I understand it and is my experience, that is true -- a stand-alone HTML attribute should be equal to itself, such as selected=selected, or more specifically selected=SELECTED. However, it will still work but will throw a validation error/warning in some DOCTYPEs, such as XHTLM. I don't know of any other DOCTYPE that might throw such as error. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com I was under the impression that in XHTML *all* attributes had to have values, even if just empty strings? Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
On Wed, 2009-06-17 at 19:27 -0400, tedd wrote: At 10:54 PM +0100 6/17/09, Ashley Sheridan wrote: I'd probably go with some sort of custom bubble sorting function. Base the sorting on your $d array, and then update the other arrays as necessary. Should be OK if they all have the same index, like in your example. If you were using keys, could you maybe join all the arrays using some sort of serialisation, sort, then unserialise into the separate arrays? Thanks Ash Ash: You missed the point. I could use the built-in sort (i.e., sort() ) and sort the $d array. However, I would like the indexes of the other arrays to match the new sort. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com I think I might need a for-instance here, as you lost me! Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
I don't know what validator you're using, but according to http://validator.w3.org/ (as official as it gets) the following fragment is correct in HTML 4.01, HTML 5, XHTML 1.0 Strict, and XHTML 1.1: select option selected=selectedtest/option /select Thus sayeth the W3C, so let it be written, so let it be done. Go read a tutorial on the transition to XHTML as well as XML. 2009/6/17 PJ af.gour...@videotron.ca: Nisse Engström wrote: On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. From my limited experience, and vast reading of those glorious 20,000 entries on the Internet, multiple does not take a parameter. I had my fingers slapped once when I validated or something - multiple is just plain multiple ! :-P ;-) :-) -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- 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
Re: [PHP] populate form input option dropdown box from existing data
Oops, hit reply instead of reply to all. Sorry for the duplicate PJ. 2009/6/17 PJ af.gour...@videotron.ca: Shawn McKenzie wrote: PJ wrote: Ashley Sheridan wrote: On Wed, 2009-06-17 at 10:01 -0400, PJ wrote: Ford, Mike wrote: On 16 June 2009 20:48, PJ advised: Now, I was happy to learn that it is simpler to populate the insert new books page dynamically from the db. Much shorter neater. It looks to me like the best solution for the edit page is close to what Yuri suggests. Since the edit page is very similar to the insert new books page, I merely need to populate the Select options box slightly differently. This is the code to populate the insert page: select name=categoriesIN[] multiple size=8 ?php $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], , $row['category'], /optionbr /; } } /select The problem nowis to find a way to add a conditional clause above that will insert the option=selected in the output. The input for this comes from: // do categories $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id;; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo$row['id'], br /; } } This may return any number of category ids so the problem is to figure out a way to pass the ids from the above code to the right ids in the first code above. How what do I search to match the two ids? Well, if I'm understanding your queries correctly, you need to compare the two sets of $row['id'] from the two queries above -- so your first query should be the second one above (SELECT id, category FROM ...), and you need to save the ids it returns for use in the loop which emits the selects. This can be done by replacing the echo $row['id'] with $selected_ids[] = $row['id']. Now you have an array of the selected ids which you can use in your in_array(). So your finished code is going to look something like this: select name=categoriesIN[] multiple size=8 ?php // do categories $selected_ids = array(); $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = $idIN book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected_ids[] = $row['id']; } } $sql = SELECT * FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { echo option value=, $row['id'], (in_array($row['id'], $selected_ids)? selected:), , $row['category'], /option\n; } } ? /select Hope this helps. It does, indeed. This confirms my inexperienced conclusion that in_array() does not work on associative arrays per se; it works on simple arrays and I just don't have the experience to think of extracting only the id fields. I actually am using a slightly more complicated if else statement which works. Also, the other problem was the option selected definition required Shawn's clarification select name='component-select' multiple ... which now highlights the selected fields. In all my searches (horrendously wasted time) I did not find any mention of component-select either in php.net or w3c.org (I don't think my queries on Google brought up anything from php.net) but w3c.org did and I had looked at the page but somehow missed it. I'm going to have to look at the way I search things. When you are looking for something specific, other, even relevant, solutions seem to get screened out. Anyway, I learned quite a bit, here. Thank you very, very much, gentlemen. PJ -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php in_array() does work with associative arrays, I used it myself before! Don't forget, it only attempts to match the value in an associative array, not the key. Could you show me how, because just running in_array($test_string, $assoc_array) never produced a result regardless of what I put into the $test_string or even if I used value, value, 'value', 14, 14, '14', and the corresponding string existed in the array - the results were zip, zero, nothing; like a dead fish. Pretty simple: $needle01 = 1; $needle02 = 'test name'; $haystack = array('id' = 1, name = 'test name'); if (in_array($needle01, $haystack)) { echo FOUND $needle01; } if (in_array($needle02, $haystack)) { echo FOUND $needle02; } And now there is another little glitch, if the array finds that there is no category listed, then I
Re: [PHP] Disclaimer
2009/6/17 Daniel Brown danbr...@php.net: On Wed, Jun 17, 2009 at 10:37, Jay Blanchardjblanch...@pocket.com wrote: Whoa! Totally unintentional dude! DON'T PANIC! Mr Mannering! What do you mean it's the wrong reference? Mr Mannering! Better? (sorry, it's late!) -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
Ford, Mike wrote: On 17 June 2009 02:11, Shawn McKenzie advised: PJ wrote: I'm sorry, guys, but I am really getting po'd. The irresponsible sloppiness and stupidity is just getting to me. In my quest for a way to populate a multiple option select box I have run across so many errors that it's beyond belief... such nonsense as select for select or select=select ( think this is right, but then who knows?) I know. So does the HTML recommendation which states that it is a boolean attribute, meaning it is stated (on/boolean 1) or it isn't (off/boolean 0) in the HTML context. So while other variations may work, this is correct: For multiple select: SELECT multiple name=component-select --or-- For single select: SELECT name=component-select This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. Any validator should validate against the declared DTD which should define the accepted values. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disclaimer
On Thu, 2009-06-18 at 01:06 +0100, Stuart wrote: 2009/6/17 Daniel Brown danbr...@php.net: On Wed, Jun 17, 2009 at 10:37, Jay Blanchardjblanch...@pocket.com wrote: Whoa! Totally unintentional dude! DON'T PANIC! Mr Mannering! What do you mean it's the wrong reference? Mr Mannering! Better? (sorry, it's late!) -Stuart -- http://stut.net/ Error, undefine literal Mannering, assumed Mainwaring ... :p Thanks Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disclaimer
2009/6/18 Ashley Sheridan a...@ashleysheridan.co.uk: On Thu, 2009-06-18 at 01:06 +0100, Stuart wrote: 2009/6/17 Daniel Brown danbr...@php.net: On Wed, Jun 17, 2009 at 10:37, Jay Blanchardjblanch...@pocket.com wrote: Whoa! Totally unintentional dude! DON'T PANIC! Mr Mannering! What do you mean it's the wrong reference? Mr Mannering! Better? (sorry, it's late!) -Stuart -- http://stut.net/ Error, undefine literal Mannering, assumed Mainwaring ... :p Quite right too. Did I mention it's late? -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
I snipped to make it short... continue at bottom... Step back from the code and consider the steps you need to perform... 1) Get an array of the categories, ideally in the form $cats[catid] = categoryname. 2) Get an array of the category IDs that should be selected, i.e. $selectedcats = array(3, 5, 7, 9). 3) Start the HTML select element 4) foreach ($cats as $id = $catname) 5) Determine whether it should be selected. e.g. $selected = (in_array($id, $selectedcats) ? 'selected=selected' : ''. 6) Output the HTML option element, like option value=$id $selected$catname/option, escaping where appropriate. 7) End of loop, job done. If your code doesn't have that structure then you may want to consider starting again. I'm quite sure the structure is correct. Secondly, check that you're not using the same variable name twice. I did find that in an instance of $id being repeated so I changed it to $bid. In one of your previous emails you used $selected to hold the array of selected categories, and in another you used it for the text to be inserted into the option element. The latter will blat over the former leading to no more than 1 option selected, and even then only if it's the first option displayed. The $selected were not mine... as I was using $ccc ; only started using $selected a couple of hours ago. If you're still stuck please post more of your code in a single chunk including all the elements in my step-by-step above. The snippets you're currently posting are not giving us enough context to spot even the most common mistakes. I'm including the relevant code: // select categories for book to be updated $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = '$bid' book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) ) { while ( $row = mysql_fetch_assoc($results) ) { $selected[] = $row['id']; } } else $selected = Array( 0 = '0'); echo $selected; print_r($selected); $sql = SELECT * FROM categories; echo select name='categoriesIN[]' multiple size='8'; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { if (in_array($row['id'], $selected)) { echo option value=, $row['id'], selected='selected' , $row['category'], /optionbr /; } else echo option value=, $row['id'], , $row['category'], /optionbr /; } } Problem #1)in the first query result. I can't figure out how to deal with it. The code works fine if there are categories assigned to the book. If not, an undefined variable error is spewed out for selected. Problem #2) in the second query, the selected is in the source code but it is not highlited. Several times I did get the categories highlighted, but I could never catch what it was that made it work. When I had the $id problem, i was trying this code from Yuri (but I don't understand where he got the $id from ) : select name=categoriesIN[] multiple ? $sql = SELECT id, category FROM categories; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $selected = ($id == $row['id'] ? 'selected=selected' : ''); echo option value=.$row['id']. .$selected..$row['name']./option; } } ? /select I think there is an error in this last code... could it be $id is supposed to be the array holding the category ids? -- Hervé Kempf: Pour sauver la planète, sortez du capitalisme. - Phil Jourdan --- p...@ptahhotep.com http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
tedd wrote: At 10:51 PM +0100 6/17/09, Ashley Sheridan wrote: On Wed, 2009-06-17 at 23:05 +0200, Nisse Engström wrote: On Wed, 17 Jun 2009 10:18:09 +0100, Ford, Mike wrote: This is very true -- but XHTML requires *all* attributes to have a value, so an XHTML conformant page will use select multiple=multiple name=selector (or something similar such as select multiple=yes name=selector). The only inconsistency here is that different people have chosen to validate against different standards. The multiple attribute only has one value: multiple, so it has to be select multiple=multiple. I don't think yes cuts the mustard. In HTML, you can shorten it to select multiple. /Nisse I read somewhere that the XHTML standards say that for all attributes that would normally be standalone in HTML, they should be given a value that is the same as the attribute name, so you would use multiple=multiple, selected=selected, checked=checked, etc. As far as I know, using this in regular HTML won't cause it to choke either, as the parsers tend to only look at the existence of the attributes, not the values they may or may not have. Thanks Ash Ash: As I understand it and is my experience, that is true -- a stand-alone HTML attribute should be equal to itself, such as selected=selected, or more specifically selected=SELECTED. How is that MORE specific? XHTML is like a cross-section of XML and HTML. It is case sensitive, so using an uppercase value in this context is LESS specific. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] populate form input option dropdown box from existing data
2009/6/18 PJ af.gour...@videotron.ca: I snipped to make it short... continue at bottom... Step back from the code and consider the steps you need to perform... 1) Get an array of the categories, ideally in the form $cats[catid] = categoryname. 2) Get an array of the category IDs that should be selected, i.e. $selectedcats = array(3, 5, 7, 9). 3) Start the HTML select element 4) foreach ($cats as $id = $catname) 5) Determine whether it should be selected. e.g. $selected = (in_array($id, $selectedcats) ? 'selected=selected' : ''. 6) Output the HTML option element, like option value=$id $selected$catname/option, escaping where appropriate. 7) End of loop, job done. If your code doesn't have that structure then you may want to consider starting again. I'm quite sure the structure is correct. Secondly, check that you're not using the same variable name twice. I did find that in an instance of $id being repeated so I changed it to $bid. In one of your previous emails you used $selected to hold the array of selected categories, and in another you used it for the text to be inserted into the option element. The latter will blat over the former leading to no more than 1 option selected, and even then only if it's the first option displayed. The $selected were not mine... as I was using $ccc ; only started using $selected a couple of hours ago. If you're still stuck please post more of your code in a single chunk including all the elements in my step-by-step above. The snippets you're currently posting are not giving us enough context to spot even the most common mistakes. I'm including the relevant code: // select categories for book to be updated $sql = SELECT id, category FROM categories, book_categories WHERE book_categories.bookID = '$bid' book_categories.categories_id = categories.id; if ( ( $results = mysql_query($sql, $db) ) ) { while ( $row = mysql_fetch_assoc($results) ) { $selected[] = $row['id']; } } else $selected = Array( 0 = '0'); echo $selected; print_r($selected); $sql = SELECT * FROM categories; echo select name='categoriesIN[]' multiple size='8'; if ( ( $results = mysql_query($sql, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { if (in_array($row['id'], $selected)) { echo option value=, $row['id'], selected='selected' , $row['category'], /optionbr /; } else echo option value=, $row['id'], , $row['category'], /optionbr /; } } Problem #1) in the first query result. I can't figure out how to deal with it. The code works fine if there are categories assigned to the book. If not, an undefined variable error is spewed out for selected. It's best practice to initialise all variables before using them. The code you have will not create the $selected variable if there are no results... (code repeated for clarity) if ( ( $results = mysql_query($sql, $db) ) ) { If there are no results this will still work so will drop through to... while ( $row = mysql_fetch_assoc($results) ) { $selected[] = $row['id']; } But since there are no results the first call to mysql_fetch_assoc will return false so the line in the middle will never get executed. } else $selected = Array( 0 = '0'); Drop this else line and instead put $selected = array(); before the mysql_query line. Not sure why you want an element 0 = '0' in there, I'm guessing it's one of your attempts to get rid of the notice. Problem #2) in the second query, the selected is in the source code but it is not highlited. Several times I did get the categories highlighted, but I could never catch what it was that made it work. Can you post the HTML you're getting for this select using the above code. If the selected attributes are in the code correctly then there must be a syntax error in there somewhere and the easiest way to find it will be by looking at the HTML. -Stuart -- http://stut.net/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Disclaimer
On Wed, Jun 17, 2009 at 20:15, Stuartstut...@gmail.com wrote: 2009/6/18 Ashley Sheridan a...@ashleysheridan.co.uk: On Thu, 2009-06-18 at 01:06 +0100, Stuart wrote: 2009/6/17 Daniel Brown danbr...@php.net: On Wed, Jun 17, 2009 at 10:37, Jay Blanchardjblanch...@pocket.com wrote: Whoa! Totally unintentional dude! DON'T PANIC! Mr Mannering! [snip!] Error, undefine literal Mannering, assumed Mainwaring ... [snip!] Quite right too. Did I mention it's late? You crazy Brits and your local entertainment. I keep having to Google these references just to keep up! In fact, had Ash not chimed in, I may not have even thought to check for a pop culture reference there, instead just thinking that Stut went off his meds again this week. ;-P -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
Robert Cummings wrote: Ash: As I understand it and is my experience, that is true -- a stand-alone HTML attribute should be equal to itself, such as selected=selected, or more specifically selected=SELECTED. How is that MORE specific? XHTML is like a cross-section of XML and HTML. It is case sensitive, so using an uppercase value in this context is LESS specific. I always do lower case and it validates (both as html 4.01 and xhtml 1.1) but only the element and attribute names must be lower case. attribute values do not need to be lower case. Maybe they do in this case, I haven't tried validating selected=SELECTED - but in general, the case sensitive nature only applies because the DTD is case sensitive and upper case element/attribute names are not defined in the DTD. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
On Wed, Jun 17, 2009 at 17:11, teddt...@sperling.com wrote: Hi gang: [snip!] Is there a slick way to do that? Hacked together in the two minutes before I go to bed, so don't complain about its inelegance. ;-P ?php $a = array('apple', 'banana', 'grape', 'orange'); $b = array(100, 2111, 198, 150); $c = array('red', 'yellow', 'purple', 'orange'); $d = array(100, 300, 11, 50); for($i=0;$icount($d);$i++) { $e[$d[$i]]['a'] = $a[$i]; $e[$d[$i]]['b'] = $b[$i]; $e[$d[$i]]['c'] = $c[$i]; } ksort($e); print_r($e); ? -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: sloppiness stupidity
Michael A. Peters wrote: Robert Cummings wrote: Ash: As I understand it and is my experience, that is true -- a stand-alone HTML attribute should be equal to itself, such as selected=selected, or more specifically selected=SELECTED. How is that MORE specific? XHTML is like a cross-section of XML and HTML. It is case sensitive, so using an uppercase value in this context is LESS specific. I always do lower case and it validates (both as html 4.01 and xhtml 1.1) but only the element and attribute names must be lower case. attribute values do not need to be lower case. Maybe they do in this case, I haven't tried validating selected=SELECTED - but in general, the case sensitive nature only applies because the DTD is case sensitive and upper case element/attribute names are not defined in the DTD. I didn't say it didn't work, I said it's not more specific to use an uppercase value that's supposed to be equal to the attribute name itself... which in turn should be lowercase according to XHTML. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
tedd wrote: Hi gang: Here's the problem. Let's say you have a collection of arrays, such as: $a = array(); $b = array(); $c = array(); $d = array(); And then you populate the arrays like so: while(...) { $a[] = ... $b[] = ... $c[] = ... $d[] = ... } Now, let's say you want to sort the $d array, but you also want the arrays $a, $b, and $c to be arranged in the same resultant order as $d. For example, please follow this: Before sort of $d: $a = [apple, banana, grape, orange] $b = [100, 2111, 198, 150] $c = [red, yellow, purple, orange] $d = [100, 300, 11, 50] After sort of $d: $a = [grape, orange, apple, banana] $b = [198, 150, 100, 2111] $c = [purple, orange, red, yellow] $d = [11, 50, 100, 300] Is there a slick way to do that? Yes... ?php function tedd_sort( $arrays ) { $master = null; $followers = array(); $first = true; foreach( array_keys( $arrays ) as $key ) { if( $first ) { $first = false; $master = $arrays[$key]; } else { $followers[] = $arrays[$key]; } } asort( $master ); foreach( array_keys( $master ) as $mkey ) { foreach( array_keys( $followers ) as $fkey ) { $value = $followers[$fkey][$mkey]; unset( $followers[$fkey][$mkey] ); $followers[$fkey][$mkey] = $value; } } } $a = array( 'apple', 'banana', 'grape', 'orange' ); $b = array( 100, 2111, 198, 150 ); $c = array( 'red', 'yellow', 'purple', 'orange' ); $d = array( 100, 300, 11, 50 ); $arrays = array( $d, $a, $b, $c ); tedd_sort( $arrays ); print_r( $a ); print_r( $b ); print_r( $c ); print_r( $d ); ? If func_get_args() or func_get_arg() had supported retrieving a reference to the argument, then we could have saved having to pass the arrays via a combined array. I chose to make $d the first array since in your example result set it is the one sorted and thus the rest follow as you would expect. Cheers, Rob. -- http://www.interjinn.com Application and Templating Framework for PHP -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multi-Sort -- how to do this?
On Wed, Jun 17, 2009 at 10:31:18PM -0400, Robert Cummings wrote: snip ?php function tedd_sort( $arrays ) { $master = null; $followers = array(); $first = true; foreach( array_keys( $arrays ) as $key ) { if( $first ) { $first = false; $master = $arrays[$key]; } else { $followers[] = $arrays[$key]; } } asort( $master ); foreach( array_keys( $master ) as $mkey ) { foreach( array_keys( $followers ) as $fkey ) { $value = $followers[$fkey][$mkey]; unset( $followers[$fkey][$mkey] ); $followers[$fkey][$mkey] = $value; } } } $a = array( 'apple', 'banana', 'grape', 'orange' ); $b = array( 100, 2111, 198, 150 ); $c = array( 'red', 'yellow', 'purple', 'orange' ); $d = array( 100, 300, 11, 50 ); $arrays = array( $d, $a, $b, $c ); tedd_sort( $arrays ); print_r( $a ); print_r( $b ); print_r( $c ); print_r( $d ); ? Wow, tedd has a sort named after him! I'm sooo jealous. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php