Re: [PHP] who can do this without the recursion

2005-07-05 Thread Christopher Fulton
On 7/5/05, Jochem Maas [EMAIL PROTECTED] wrote:
 hi everyone,
 
 I have a function which recursively loops an assoc array in
 order to build an HTML string containing hidden input elements
 that repesent the key/values passed in the array ... I know this can
 be done without recursion but I'm having a brainfreeze, anyone care
 to share some tips on replacing the recursion with some kind of stack
 based solution (the idea being that I want to remove the overhead
 of the recursive calls to the function if possible ...
 
 I'm looking to get a better understanding of alternatives to
 recursion in general rather than in this specific example,
 so come people show us what you can do! :-)
 
 example:
 
 function rec_build_hidden_inputs($args = array(), $prefix = '')
 {
  static $inputTpl = input type=hidden name=%s value=%s /\n;
 
  $_contents = '';
  foreach ($args as $key = $val) {
  $nextPrefix = $prefix  ''
  ? {$prefix}[{$key}];
  : $key
  ;
 
  $_contents .= is_array($val)
  ? rec_build_hidden_inputs($val, $nextPrefix)
  : sprintf($inputTpl, $nextPrefix, $key)
  ;
  }
 
  return $_contents;
 }
 
 rgds,
 Jochem
 
 PS - do ya think I can copyright this?:
 
 =
 ?
 :
 ;
 
 nah, didn't think so - none the less you might be surprised how many people
 it annoys ;-)
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

This is completely untested (sry, don't have the time right now to
test it), but something like this should work

$inputTpl = input type=hidden name=%s value=%s /\n;
$recursiveStack = array();

// change  firstArgs and firstPrefix to the first values in your array
$firstArgs = array();
$firstPrefix = '';
$recursiveStack[] = array(args=$firstArgs, prefix=$firstPrefix);
$_contents = '';

while($currVal = array_pop($recursiveStack)) {
   $args = $currVal[args];
   $prefix = $currVal[prefix];
   foreach($args as $key=$val) {
  $nextPrefix = $prefix  ''
 ? {$prefix}[{$key}];
 : $key
 ;
  if(is_array($val)) {
 array_push($recursiveStack, array(args=$val,
prefix=$nextPrefix));
  } else {
 $contents .= sprintf($inputTpl, $nextPrefix, $key);
  }
   }
}

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Splitting Vars from MySQL in PHP

2005-04-29 Thread Christopher Fulton
On 4/29/05, jlfx mailgroups [EMAIL PROTECTED] wrote:
 
 I remember in Perl I used to extract vars from a single fetchrow by adding
 each var name to the beginning (like this). Only this ain'ta workin :)...
 Anyone know the right syntax to do this?
 
 ($var1, $var2, $var3)= mysql_fetch_array($result, MYSQL_ASSOC)
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 


list($var1, $var2, $var3) = mysql_fetch_array($result, MYSQL_ASSOC);
http://us4.php.net/manual/en/function.list.php

-Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: Re[2]: [PHP] Re: 1 web site, 3 servers, 3 countries - best practises?

2005-04-22 Thread Christopher Fulton
  This isn't about redundancy, it's about enhancing the experience for
  customers physically located thousands of miles away from the server
  they are trying to access. So, bring the content closer to them and
  drop their wait times massively. It's easy for those of us sat on the
  end of cable connections to become complacent about this IMHO (i.e.
  the Internet is fast enough now that you don't need to do this), but
  in reality that's not really yet the case.

Here is something I have done in the past to speed up php/mysql pages
(should work with other databases though).  Basically, I noticed that
the majority of our database calls were read calls, rather than write
calls.  So, in all of the locations globally, I set up read-only
database servers, and also replicated the php code to all of the
sites, then still did all of the writes to the master server but,
all of the reads from each local read-only server.

Not sure if this is necessairily the best way to do things, but it
worked well for me, and sped things up quite a bit.  This does mean
you have 2 database connections always, 1 for reading, and 1 for
writing.

For mysql, look more at their website for how to set up replication
machines.  As far as the code goes, I just have a process that
straight copy's it from my master server.

-Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Last visitors (SOLVED?)

2005-04-19 Thread Christopher Fulton
 I did, the problem is the client is on a box with mySql 3.23.x or 4.0.x, he
 is deciding to upgrade to a dedicated box but then the host he is looking at
 says they will charge him if they are to upgrade to mysql 4.1 (hence i cant
 even use sub-selects)
 (Sorry I didnt mention the MySql version before...didnt think it was
 important till now)

The MySQL version should not matter for what he was saying (you don't
need subqueries).  I think he was saying that every time you insert a
user, also insert 10 records into the users profile_viewed_log. with
an empty timestamp.  Then, every time someone views the profile,
update the profile_viewed_log, instead of inserting into it.  (which
can be done with a simple query...)
$SQL = UPDATE profile_log SET user_id=.$userId.,
date_entered='1113931530' WHERE profile_id=.
$profileId. ORDER BY date_entered ASC LIMIT 1;

(the date i have is a unix timestamp, but you can use whatever format
you wish).

I havn't tested that query, but it should work with no problem. 
Basically, it just updates the first record with the smallest
timestamp.

Then, when you want to show the user the views for his/her profile, 
you just exclude the one's with an empty timestamp.

Your other option, which also would work well, would be to do the cron
job, with a limit value on the query.  IMHO this is better than 3
queries every time someone views a profile.  Also, you can set the
cron job to run at 3AM, when there are not likely to be many users.

Hope this helps some.

-Chris

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Multiline data Insert Into table from a generated form?

2005-02-04 Thread Christopher Fulton
[snip]
  //user connection section--begin
  $username=root;
  $password=;
  $database=nazardane;
[/snip]

If this is actually your login, I would suggest changing it right away

[snip]
  while ($c=0;$ccount($_POST['tourid']):$c++)
[/snip]

Like Mike already said, that should be a for loop.  But, you do have
one other option, that I prefer...A foreach loop.

foreach($_POST['tourid'] AS $tour_id {
... now in your code use $tour_id instead of $_POST['tourid'][$c]
}

-Chris

ps...You may want to read through the php turorial again.  Lots of 
helpful information there.  http://us2.php.net/tut.php
-- 
Christopher Fulton
http://www.fultonfam.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] PHP editor suggestion?

2005-01-24 Thread Christopher Fulton
[quote]
 I am looking for a relieable, stable and quick PHP/HTML editor.
 
 Can anybody suggest a good one? I tried phpdesigner, but it seems to
 have lots of bugs and is quite slow.
 
[/quote]

Just a suggestionA mailing list may not be the best place to find
the answer for this question.  A person's choice in an editor is going
to be different depending on who you talk to.  One person may love vi,
whereas another person may love Dreamweaver.  If you read the
archives, you'll see several responses going many different ways as to
what editor is the best.  My suggestion would be to decide what are
the most important things you want in an editor (ie...syntax
highlighting, speed, a built in code debugger, cross platform
compatibility, etc...).  Then, once you have decided what is
essential for you, do a google search for editors with those things.
 Try a few out, and decide what works best for you.

Happy Searching, 
Chris  

---
Christopher Fulton
http://www.fultonfam.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Writing static file from dynamic PHP page

2005-01-18 Thread Christopher Fulton
Just an fyi...this would be VERY easy to get online.  PHP keeps an
archive of all the posts.  Here's the link

http://marc.theaimsgroup.com/?l=php-general

In fact, you may even find other posts similar to yours by searching
(that could answer your question?)

-Chris


On Tue, 18 Jan 2005 09:30:00 -0500, Chris Bruce [EMAIL PROTECTED] wrote:
 sorry for the repost, but my mail server was down from about 11pmEST
 last night to 9:15am this morning and unable to receive responses. Can
 someone forward me responses to this post if any? Thanks. Chris
 
  Hi,
 
  I am looking for a way to write to a file what the browser would see
  (raw html) when viewing a dynamic PHP page. I have numerous include
  files, MySQL db queries, loops etc. and I want to generate the static
  result of that file and save it as an html page. I have toyed a little
  with output buffering to no avail.
 
  Is there an easy way to do this?
 
 --
 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] Get name of extending class with static method call

2005-01-11 Thread Christopher Fulton
Not sure if this is the best way to do it or not, but you can do this
and it should (untested code) work.

class Car {
function drive() {
 return $this-getClassName();
}
function getClassName() {
  return Car; 
}
}

class Porshe {
 function getClassName() {
  return Porshe;
 }
}

$foo = new Porshe();
echo $foo-drive();


On Tue, 11 Jan 2005 17:08:27 +0100, Torsten Roehr [EMAIL PROTECTED] wrote:
 Hi list,
 
 in PHP4 it was possible to get the name of the calling class with
 debug_bcktrace(). Unfortunately this behaviour has been changed in PHP5. I
 didn't find a solution in the archives.
 
 Is there *any* way to get the name of the calling class?:
 
 class Car {
 function drive() {
 // I need the name of the calling class here
 // in this case it should be 'Porsche'
 }
 }
 
 class Porsche extends Car {
 }
 
 Porsche::drive();
 
 Any help is greatly appreciated!
 
 Thanks and best regards,
 
 Torsten Roehr
 
 --
 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] Re: Get name of extending class with static method call

2005-01-11 Thread Christopher Fulton
This should work for you then(maybe...i don't have php5 on my
system, so it may not, but i think it would.
http://us4.php.net/manual/en/function.get-class.php

class Car {
function drive() {
 return get_class($this);
}
 }

 class Porshe {
 }

$foo = new Porshe();
echo $foo-drive();

On Tue, 11 Jan 2005 14:24:46 -0500, Jason Barnett
[EMAIL PROTECTED] wrote:
 
  __CLASS__ contains the name of the class the method is in. In my sample it
  would be 'Car' and not 'Porsche'.
 
  What I don't understand is why the behaviour of debug_backtrace() has been
  changed!?!
 
  Regards, Torsten
 
 I have no idea why the behaviour changed (I didn't really use the
 function before, either).  And I see now the change in the manual that
 addresses this (essentially debug_backtrace gives you __CLASS__)
 
 If you had an actual instance of the class you could use get_class, but
 alas you are using a static method call.  You punk.
 
 The only other solution that comes to mind is a little messy but it lets
 you get away with no object.  Instead of calling the method statically
 you can use call_user_func_array() with the child class name as a
 parameter.  Then change the parent method to accept the child class name
 as a parameter.
 
 ?php
 
 function call_static_child() {
$drive_args = func_get_args();
/** assume that first parameter is child of class Car */
return call_user_func_array(array($drive_args[0], 'drive'), $drive_args);
 }
 
 ?
 
 
 --
 Teach a person to fish...
 
 Ask smart questions: http://www.catb.org/~esr/faqs/smart-questions.html
 PHP Manual: http://www.php.net/manual/en/index.php
 php-general archives: http://marc.theaimsgroup.com/?l=php-generalw=2
 
 --
 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] $_FILE[user][error] = 6 ?

2004-12-29 Thread Christopher Fulton
It may help to know what your form looks like.  Does your form have
the hidden MAX_FILE_SIZE variable before the file field?  Also, what
version of PHP are you running?

Anyways, just some suggestions.
-Chris


On Tue, 28 Dec 2004 15:18:16 -0500, Al [EMAIL PROTECTED] wrote:
 I keyed $_FILE[user][error] from memory, and it's wrong.  It really is 
 userfile;
 
 Weird problem, eh!
 
 Sebastian wrote:
  not sure if its a typo but the array shows userfile and your variable
  array shows user
  it looks like the file isn't being passed at all, double check if you have
  any typos..  type is blank which should at least show the mime type..
 
  - Original Message -
  From: Al [EMAIL PROTECTED]
  To: php-general@lists.php.net
  Sent: Tuesday, December 28, 2004 2:51 PM
  Subject: Re: [PHP] $_FILE[user][error] = 6 ?
 
 
 
 Doesn't work on any file type.
 
 I've checked the usual suspects. e.g.
 form enctype=multipart/form-data action=_url_ method=\post\ URL is
 
  my
 
 php file.
 
 On Wednesday 29 December 2004 01:40, Al wrote:
 
 What is a $_FILE[user][error]= 6
 
 I can't find Error level 6 in the manual or on Google.
 
 Here is my files array:
 
 [userfile] = Array
 (
  [name] = Readme.txt
  [type] =
  [tmp_name] =
  [error] = 6
  [size] = 0
  )
 
 Doesn't make sense.  Readme.txt is simply a small text file on my local
 
  HD.
 
 --
 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] Date problem?

2004-12-22 Thread Christopher Fulton
Try this instead...
  echo date('F',strtotime(+1 month)); 

read through the user comments at...
http://us2.php.net/manual/en/function.strtotime.php

there are some things pertaining to your situtation
-Chris


On Wed, 22 Dec 2004 15:38:38 -0800, PHP [EMAIL PROTECTED] wrote:
  
 echo date('F',strtotime(next month)); 
   
 This is printing February right now. Does this sound right or is this a but
 in strtotime()? is next month a valid parameter? 
   
 and yes, I am sure our server is set to December(todays date). 
   
 echo date('F',strtotime(last month)); 
 Does give me November as it should 
   
 No virus found in this outgoing message.
 Checked by AVG Anti-Virus.
 Version: 7.0.298 / Virus Database: 265.6.4 - Release Date: 12/22/2004
 
 
 --
 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] Writing new code vs. re-writing someone else's code

2004-12-21 Thread Christopher Fulton
Honestly, I think it does depend a lot on the language you are using. 
From my experience, most people who work in PHP tend to write more new
code than those who use COBOL.
[snip]
There are *so* many legacy COBOL applications though that, yeah, I think
a COBOL programmer will very rarely get to write anything new.
[/snip]
I agree.  I was reading something that like 80% of the code out there
(don't quote my numbers) is in COBOL and FORTRAN.

Anyways, to answer your question, I spend about 30% of my time writing
new code and about 70% of my time working on legacy code.  Of course,
often due to lacking comments most of the time spent with old code is
just trying to figure out what they were doing.  :)

-Chris

On Wed, 22 Dec 2004 01:13:58 +1100, Justin French
[EMAIL PROTECTED] wrote:
 On 21/12/2004, at 9:41 PM, Eakin, W wrote:
 
  The question is, how much of your time (you, the professional PHP
  coder reading this), is spent rewriting/repairing old code vs. writing
  new code.
 
 When I'm working on a new project, my time is generally spent hooking
 into my existing framework with new code and models.
 
 When I'm making changes to existing projects, I tend to be mainly
 repairing, modifying and updating code, plus adding a little new code.
 I'm highly addicted to cleaning and refining my old code, so if I see
 something messy and have a few spare minutes, I'll always clean up old
 code to make it better.
 
 I absolutely hate working with other people's code or inheriting a
 project unless it's really clean and well thought out, and well
 documented.
 
 ---
 Justin French, Indent.com.au
 [EMAIL PROTECTED]
 Web Application Development  Graphic Design
 
 --
 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] How to set register_globals=off in the script?

2004-12-21 Thread Christopher Fulton
Yes and no...
Here's what the manual has to say about this...Basically, you can't do
it using ini_set, but you can do it using an htaccess file.

http://us2.php.net/manual/en/ini.sect.data-handling.php#ini.register-globals

register_globals  boolean

Whether or not to register the EGPCS (Environment, GET, POST,
Cookie, Server) variables as global variables.

As of PHP 4.2.0, this directive defaults to off.

Please read the security chapter on Using register_globals for
related information.

Please note that register_globals cannot be set at runtime
(ini_set()). Although, you can use .htaccess if your host allows it as
described above. An example .htaccess entry: php_flag register_globals
off.

Note: register_globals is affected by the variables_order directive. 

On Tue, 21 Dec 2004 14:56:03 -0500, Jerry Swanson [EMAIL PROTECTED] wrote:
 I know that register_globals = on is not secure. But one program
 requires to use register_globals=on. So in php.ini register_globals is
 set to on.
 
 I have PHP 5.1, is it possible in the code set register_globals=off
 for specific scripts.
 
 So I want to keep PHP register_globals=on in php.ini, but in local
 files set to off?
 
 How I can do this?
 
 --
 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] scripting with php

2004-12-14 Thread Christopher Fulton
one more note...you may look at the manual under

http://us3.php.net/features.commandline

-Chris


On Tue, 14 Dec 2004 16:04:15 -0800, Christopher Fulton
[EMAIL PROTECTED] wrote:
 Not sure if this is what you want, but i know that you can call php
 from a command line by using.
 
 php code_name.php
 
 that will print out the http headers, so to supress the headers you can do
 
 php -q code_name.php
 
 Hope this helps,
 Chris
 
 
 On Tue, 14 Dec 2004 21:38:18 +, Bruno Santos [EMAIL PROTECTED] wrote:
  Hello all.
 
  i'm working with php for about 3 years and i must say: i cant get tired
  of it !! :-)
 
  since my first page, ive used php as a server side language, embebed in
  html pages. now, i need to develop a small script to run as stand alone.
  how can i do it ?
 
  just like bourn shell, ive used #!/usr/bin/php -q, but it apears is not
  working ...
 
  can someone tell me how to i use php stand alone ?
  chears !!!
 
  Bruno Santos
 
  --
  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] scripting with php

2004-12-14 Thread Christopher Fulton
Not sure if this is what you want, but i know that you can call php
from a command line by using.

php code_name.php

that will print out the http headers, so to supress the headers you can do

php -q code_name.php

Hope this helps,
Chris


On Tue, 14 Dec 2004 21:38:18 +, Bruno Santos [EMAIL PROTECTED] wrote:
 Hello all.
 
 i'm working with php for about 3 years and i must say: i cant get tired
 of it !! :-)
 
 since my first page, ive used php as a server side language, embebed in
 html pages. now, i need to develop a small script to run as stand alone.
 how can i do it ?
 
 just like bourn shell, ive used #!/usr/bin/php -q, but it apears is not
 working ...
 
 can someone tell me how to i use php stand alone ?
 chears !!!
 
 Bruno Santos
 
 --
 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] searching with mutable criteria

2004-12-07 Thread Christopher Fulton
An easy way to fix that problem would be to, instead of checking every
time if one of the others also is not empty would be to do something
like this (havn't tested this code, so no guarantees there's no
typos).

$sqlCondition = ;

if($_POST[state] !=  || $_POST[types] !=  || $_POST[county] != ) {
 if($_POST[state] != ) {
  if($sqlCondition == ) {
  $sqlCondition .= SELECT * FROM listing WHERE state
= '$_POST[state]' ;
  }
  else {
  $sqlCondition .=  AND state = '$_POST[state]' ;
  }
 }
 if($_POST[types] != ) {
   if($sqlCondition == ) {
   SELECT * FROM listing WHERE types = '$_POST[types]' ;
}
else {
$sqlCondition .=  AND types = '$_POST[types]' ;
 }   
 }   
  $sqlCondition .=  LIMIT  . $from . , . $max_results;
}

Do the same thing for all of your conditions, and that should fix your error...


On Tue, 7 Dec 2004 07:52:07 -0800, Richard Kurth [EMAIL PROTECTED] wrote:
 
 
 I am having a problem with this script what it does is write the sql
 needed to search for data based on mutable criteria. It works fine if
 you search with all the different fields but if you only search with
 one or two of the fields it creates a sql that looks like this
 SELECT * FROM listing WHERE state = 'WA' AND LIMIT 0,5
 It adds the AND before the limit if you use all three fields it does
 not add the AND. How can I change this so it will not add the AND if
 there is only a search on one or two of the fields
 
 $cond = AND;
 $sql = 'SELECT * FROM listing ';
 if($_POST[state] !=  || $_POST[types] !=  || $_POST[county] != 
 ){$sql .= WHERE ;
 
 if($_POST[state] != ){
 $sql .= state  = '. $_POST[state] .';
 if($_POST[state] !=  || $_POST[types] !=  || $_POST[county] != 
 ){$sql .=  $cond ;}
 }
 
 if($_POST[type] != ){
 $sql .= types = '. $_POST[types] .';
 if($_POST[state] !=  || $_POST[types] !=  || $_POST[county] != ) 
 {$sql .=  $cond ;}
 }
 
 if($_POST[county] != ){
 $sql .= county = '. $_POST[county] .';
 if($_POST[state] !=  || $_POST[types] !=  || $_POST[county] != 
 ){$sql.=  $cond ; }
 }
 )
 $sql .=  LIMIT  . $from . , . $max_results;
 echo $sql
 --
 Best regards,
  Richard  mailto:[EMAIL PROTECTED]
 
 --
 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] Drawing checkboxes

2004-12-07 Thread Christopher Fulton
A few notes that may help you.

first.on strstri would use strpos instead for a simple checkso
 if(strstr($default, $values[$i]['id'])) {
 $field .= ' CHECKED';
 }
would become
 if(strpos($default, $values[$i]['id']) !== false) {
 $field .= ' CHECKED';
 }
note the double equals...not a mistakesee note in php docs about
that...the reason for using strpos is that strstr is a much longer
check than needed.anyways...on to your problem.

there is a slight logic issue (i think)
lets say your values are
$values = foo bar|foo;
this test (i think) should return true
if(strstr(foo, $values)) because it just looks for the first
occurence of the string


to fix this.

I would change it to this.
  $checkValues = array()
 $checkValues = explode(|, $values[$i]['id']);
 if(in_array($default, $checkValues)) {
 $field .= ' CHECKED';
 }

there may be a better/faster way to do this, but this should work

hope this helps,
chris



On Tue, 07 Dec 2004 15:10:59 -0500, Mike [EMAIL PROTECTED] wrote:
 
 
 Hello,
 
 I am having a hard time figuring this one out, maybe someone here (with
 fresh eyes) can offer a suggestion?
 
 Here is the function...
 
 // Draw Checkbox Menu
 function draw_checkbox_menu($name, $values, $default = false, $parameters =
 false) {
 
 for ($i=0; $isizeof($values); $i++) {
 $field .= 'input type=checkbox name='.$name.' value=' .
 $values[$i]['id'] . '';
 if(strstr($default, $values[$i]['id'])) {
 $field .= ' CHECKED';
 }
 $field .= ' ' . $values[$i]['text'] . 'br
 ';
 }
 
 return $field;
 }
 
 This function is passed the name of the checkbox list($name), the values
 that are available($values = array) along with the ones that should be
 checked ($default). Parameters too , but not important.
 
 The problem is this. The Values are formatted like this...
 
 value1|value2|value3...etc...
 
 I use the strstr() function to check against the $default so I can check it
 if so.
 
 Well it works great..BUT, lets say the product has a category of Coffee
 Pots, but the one of the values available is Coffee.
 
 In this case both Coffee AND Coffee Pots get checked when only Coffee
 Pots should.
 
 What can I do to this function eliminate this?
 
 Thanks
 
 ++
 Mike Yrabedra
 [EMAIL PROTECTED]
 Your Mac Intelligence Resource
 ++
 W: http://www.macagent.com/
 E: [EMAIL PROTECTED]
 
 --
 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] Drawing checkboxes

2004-12-07 Thread Christopher Fulton
so switch the two things.
  I would change it to this.
$checkValues = array()
   $checkValues = explode(|, $default);
   if(in_array($values[$i]['id'], $checkValues)) {
   $field .= ' CHECKED';
   }


i could be misinterpreting ya, but i think that would
work...actually...if default is going to be the same...i would pull
the checkValues part out of the loop, so you don't perform the explode
for every valuebut, that would work (i think?)

-chris

On Tue, 07 Dec 2004 16:21:15 -0500, Mike [EMAIL PROTECTED] wrote:
 
 
 Chris,
 
 Good idea, but $default is the value with pipe delimiters.
 
 on 12/7/04 4:11 PM, Christopher Fulton at [EMAIL PROTECTED]
 wrote:
 
 
 
  A few notes that may help you.
 
  first.on strstri would use strpos instead for a simple 
  checkso
  if(strstr($default, $values[$i]['id'])) {
  $field .= ' CHECKED';
  }
  would become
  if(strpos($default, $values[$i]['id']) !== false) {
  $field .= ' CHECKED';
  }
  note the double equals...not a mistakesee note in php docs about
  that...the reason for using strpos is that strstr is a much longer
  check than needed.anyways...on to your problem.
 
  there is a slight logic issue (i think)
  lets say your values are
  $values = foo bar|foo;
  this test (i think) should return true
  if(strstr(foo, $values)) because it just looks for the first
  occurence of the string
 
 
  to fix this.
 
  I would change it to this.
$checkValues = array()
   $checkValues = explode(|, $values[$i]['id']);
   if(in_array($default, $checkValues)) {
   $field .= ' CHECKED';
   }
 
  there may be a better/faster way to do this, but this should work
 
  hope this helps,
  chris
 
 
 
  On Tue, 07 Dec 2004 15:10:59 -0500, Mike [EMAIL PROTECTED] wrote:
 
 
  Hello,
 
  I am having a hard time figuring this one out, maybe someone here (with
  fresh eyes) can offer a suggestion?
 
  Here is the function...
 
  // Draw Checkbox Menu
  function draw_checkbox_menu($name, $values, $default = false, $parameters =
  false) {
 
  for ($i=0; $isizeof($values); $i++) {
  $field .= 'input type=checkbox name='.$name.' value=' .
  $values[$i]['id'] . '';
  if(strstr($default, $values[$i]['id'])) {
  $field .= ' CHECKED';
  }
  $field .= ' ' . $values[$i]['text'] . 'br
  ';
  }
 
  return $field;
  }
 
  This function is passed the name of the checkbox list($name), the values
  that are available($values = array) along with the ones that should be
  checked ($default). Parameters too , but not important.
 
  The problem is this. The Values are formatted like this...
 
  value1|value2|value3...etc...
 
  I use the strstr() function to check against the $default so I can check it
  if so.
 
  Well it works great..BUT, lets say the product has a category of Coffee
  Pots, but the one of the values available is Coffee.
 
  In this case both Coffee AND Coffee Pots get checked when only Coffee
  Pots should.
 
  What can I do to this function eliminate this?
 
  Thanks
 
  ++
  Mike Yrabedra
  [EMAIL PROTECTED]
  Your Mac Intelligence Resource
  ++
  W: http://www.macagent.com/
  E: [EMAIL PROTECTED]
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 ++
 
 
 Mike Yrabedra
 [EMAIL PROTECTED]
 Your Mac Intelligence Resource
 ++
 W: http://www.macagent.com/
 E: [EMAIL PROTECTED]
 
 --
 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