RE: [PHP] Can I do this in a single match/replace?

2012-06-28 Thread Ford, Mike
 -Original Message-
 From: Paul Halliday [mailto:paul.halli...@gmail.com]
 Sent: 28 June 2012 02:27

 
 Using preg_match and this pattern I can get the refs:
 
 $pattern = '\reference:url,([^;]+;)\';
 
 which gives me:
 
 $matches[0] = www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-
 04.txt
 $matches[1] = doc.emergingthreats.net/bin/view/Main/2002068
 
 now what I would like to do is replace inline adding a
 href=http://;
 . $matches[n] .  . $matches[n] . /a
 
 Can this be done or do I need to say loop through matches (there can
 be none or many) and do a str_replace.

$new_string = preg_replace($pattern, 'a href=http://$1;$1/a' , 
$string);

should do it -- don't *think* you need any pesky \ escapes in the
replacement, but could be wrong on that one, so please suck it and
see...

Cheers!

Mike

-- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Portland PD507, City Campus, Leeds Metropolitan University,
Portland Way, LEEDS,  LS1 3HE,  United Kingdom 
E: m.f...@leedsmet.ac.uk T: +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] Can I do this in a single match/replace?

2012-06-27 Thread Chris Testroet

On 6/27/2012 6:26 PM, Paul Halliday wrote:

I have lines that look like (I added intentional line breaks):

alert tcp $HOME_NET 1 - $EXTERNAL_NET any (msg:ET EXPLOIT NDMP
Notify Connect - Possible Backup Exec Remote Agent Recon;
flow:established,from_server; content:|00 00 05 02|; offset:16;
depth:20; content: |00 00 00 03|; offset: 28;
depth: 32; 
reference:url,www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-04.txt;
reference:url,doc.emergingthreats.net/bin/view/Main/2002068;
classtype:attempted-recon; sid:2002068; rev:8;)

So within this there are reference urls that I would like to turn into
links so that when they are rendered they can be clicked on.

Using preg_match and this pattern I can get the refs:

$pattern = '\reference:url,([^;]+;)\';

which gives me:

$matches[0] = www.ndmp.org/download/sdk_v4/draft-skardal-ndmp4-04.txt
$matches[1] = doc.emergingthreats.net/bin/view/Main/2002068

now what I would like to do is replace inline adding a href=http://;
. $matches[n] .  . $matches[n] . /a

Can this be done or do I need to say loop through matches (there can
be none or many) and do a str_replace.

Thoughts? Other ideas?

Thanks.



Look into preg_replace, with the e modifier. It allows you to run php 
code for every replace.


Chris


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



Re: [PHP] can I do this without eval?

2009-01-22 Thread Nathan Nobbe
On Thu, Jan 22, 2009 at 8:35 AM, Frank Stanovcak
blindspot...@comcast.netwrote:

 I'm trying to build a prepared statment and dynamically bind the variables
 to it since I use this on severaly different pages I didn't want to build a
 huge bind statement hard coded on each page and then have to maintain it
 every time there was a change.

 I despise having to use eval() and was hoping one of you had stumbled upon
 this and found a better workaround for it.

 I've seen references to call_user_function_array, but couldn't find a
 tutorial, or description that could make me understand how to use it.
 I think the big problem with all of them was they expected me to know oop,
 and that is on my plate to learn after I finnish this project.


 Frank

 
 //initialize a variable to let us know this is the first time through on
 //the SET construction
  $i = true;

 //step through all the FILTERED values to build the SET statment
  foreach($FILTERED as $key=$value){

 //make sure we single quote the string fields
  if($i){
   $sqlstring .=  $key = ?;
   $i = false;
  }else{
   $sqlstring .= , $key = ?;
  };

 //build the list of variables to bound durring the mysqli prepared staments
  $params[] = \$FILTERED[' . $key . '];

 //build the list of types for use durring the mysqli perepared statments
  switch($key){
  case in_array($key, $stringfields):
   $ptype[] = 's';
   break;

  case in_array($key, $doublefields):
   $ptype[] = 'd';
   break;

  default:
   $ptype[] = 'i';
  };
  };

 //make sure we only update the row we are working on
  $sqlstring .= ' WHERE BoL=' . $FILTERED['BoL'];

 //connect to the db
  include('c:\inetpub\security\connection.php');

 //ok...let's do this query
 //use mysqli so we can use a prepared statment and avoid sql insert attacks
  $stmt = mysqli_prepare($iuserConnect, $sqlstring);
  if(!$stmt){
  die(mysqli_stmt_error($stmt));
  };

 //implode the two variables to be used in the mysqli bind statment so they
 are in
 //the proper formats
  $params = implode(, , $params);
  $ptype = implode('', $ptype);

 ---
 - is there a better way to accomplish this? -
 ---
 //run an eval to build the mysqli bind statment with the string list of
 variables
 //to be bound
  eval(\$check = mysqli_stmt_bind_param(\$stmt, '$ptype', $params););
  if(!$check){
  die(mysqli_stmt_error($stmt) . 'brbr');
  };


yeah, id try call_user_func_array(),

omit the line to create a string out of the $params, then merge the later
arguments into an array w/ the first 2 args

#$params = implode(, , $params);
$check = call_user_func_array('mysqli_stmt_bind_param',
array_merge(array($stmt, $ptype), $params));

something like that i think should do the trick.

-nathan


Re: [PHP] can I do this without eval?

2009-01-22 Thread Frank Stanovcak

Nathan Nobbe quickshif...@gmail.com wrote in message 
news:7dd2dc0b0901221048g2f089cf9s36ecb9a5b35ab...@mail.gmail.com...
 On Thu, Jan 22, 2009 at 8:35 AM, Frank Stanovcak
 blindspot...@comcast.netwrote:

 I'm trying to build a prepared statment and dynamically bind the 
 variables
 to it since I use this on severaly different pages I didn't want to build 
 a
 huge bind statement hard coded on each page and then have to maintain it
 every time there was a change.

 I despise having to use eval() and was hoping one of you had stumbled 
 upon
 this and found a better workaround for it.

 I've seen references to call_user_function_array, but couldn't find a
 tutorial, or description that could make me understand how to use it.
 I think the big problem with all of them was they expected me to know 
 oop,
 and that is on my plate to learn after I finnish this project.


 Frank

 
 //initialize a variable to let us know this is the first time through on
 //the SET construction
  $i = true;

 //step through all the FILTERED values to build the SET statment
  foreach($FILTERED as $key=$value){

 //make sure we single quote the string fields
  if($i){
   $sqlstring .=  $key = ?;
   $i = false;
  }else{
   $sqlstring .= , $key = ?;
  };

 //build the list of variables to bound durring the mysqli prepared 
 staments
  $params[] = \$FILTERED[' . $key . '];

 //build the list of types for use durring the mysqli perepared statments
  switch($key){
  case in_array($key, $stringfields):
   $ptype[] = 's';
   break;

  case in_array($key, $doublefields):
   $ptype[] = 'd';
   break;

  default:
   $ptype[] = 'i';
  };
  };

 //make sure we only update the row we are working on
  $sqlstring .= ' WHERE BoL=' . $FILTERED['BoL'];

 //connect to the db
  include('c:\inetpub\security\connection.php');

 //ok...let's do this query
 //use mysqli so we can use a prepared statment and avoid sql insert 
 attacks
  $stmt = mysqli_prepare($iuserConnect, $sqlstring);
  if(!$stmt){
  die(mysqli_stmt_error($stmt));
  };

 //implode the two variables to be used in the mysqli bind statment so 
 they
 are in
 //the proper formats
  $params = implode(, , $params);
  $ptype = implode('', $ptype);

 ---
 - is there a better way to accomplish this? -
 ---
 //run an eval to build the mysqli bind statment with the string list of
 variables
 //to be bound
  eval(\$check = mysqli_stmt_bind_param(\$stmt, '$ptype', $params););
  if(!$check){
  die(mysqli_stmt_error($stmt) . 'brbr');
  };


 yeah, id try call_user_func_array(),

 omit the line to create a string out of the $params, then merge the later
 arguments into an array w/ the first 2 args

 #$params = implode(, , $params);
 $check = call_user_func_array('mysqli_stmt_bind_param',
 array_merge(array($stmt, $ptype), $params));

 something like that i think should do the trick.

 -nathan


Thanks Nathan!
Just to make sure I understand call_user_func_array, and how it opperates.
It's first paramer is the name of the function...any function, which is part 
of what made it so confusing to me...and the second paramter is an array 
that will be used to populate the the parameters of the called function as a 
comma seperated list.

Please tell me if I got any of that wrong.  This is how I learn!

Frank 



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



Re: [PHP] can I do this without eval?[RESOLVED]

2009-01-22 Thread Frank Stanovcak

Nathan Nobbe quickshif...@gmail.com wrote in message 
news:7dd2dc0b0901221048g2f089cf9s36ecb9a5b35ab...@mail.gmail.com...

 yeah, id try call_user_func_array(),

 omit the line to create a string out of the $params, then merge the later
 arguments into an array w/ the first 2 args

 #$params = implode(, , $params);
 $check = call_user_func_array('mysqli_stmt_bind_param',
 array_merge(array($stmt, $ptype), $params));

 something like that i think should do the trick.

 -nathan


Ok.  I only had to make minimal chnages to the offered 
solution...highlighted below...I would still appreciate anyone letting me 
know if my understanding of call_user_func_array() is incorrect though. :) 
Thanks everyone!

Frank


//put the string fields directly in as we will be preparing the sql statment
//and that will protect us from injection attempts
if($continue){
 foreach($stringfields as $value){
  $FILTERED[$value] = $_POST[$value];
 };
};

//ok...we've made it this far, so let's start building that update query!
$vartype = '';
if($continue){

//start building the SQL statement to update the bol table
 $sqlstring = UPDATE bol SET;

//initialize a variable to let us know this is the first time through on
//the SET construction
 $i = true;

//step through all the FILTERED values to build the SET statment
//and accompanying bind statment
 foreach($FILTERED as $key=$value){

//make sure we don't put a comma in the first time through
  if($i){
   $sqlstring .=  $key = ?;
   $i = false;
  }else{
   $sqlstring .= , $key = ?;
  };

//build the list of types for use durring the mysqli perepared statments
  switch($key){
  case in_array($key, $stringfields):
   $ptype[] = 's';
   break;

  case in_array($key, $doublefields):
   $ptype[] = 'd';
   break;

  default:
   $ptype[] = 'i';
  };
 };

//make sure we only update the row we are working on
 $sqlstring .= ' WHERE BoL=' . $FILTERED['BoL'];

//connect to the db
 include('c:\inetpub\security\connection.php');

//ok...let's do this query
//use mysqli so we can use a prepared statment and avoid sql insert attacks
 $stmt = mysqli_prepare($iuserConnect, $sqlstring);
 if(!$stmt){
  die(mysqli_stmt_error($stmt));
 };

//implode the field types so that we have a useable string for the bind
 $ptype = implode('', $ptype);


- I completely did away with the $param and inserted --
- $FILTERED directly and everything worked great! --


//bind the variables using a call to call_user_func_array to put all the
//$FILTERED variables in
 $check = call_user_func_array('mysqli_stmt_bind_param', 
array_merge(array($stmt, $ptype), $FILTERED));
 if(!$check){
  die(mysqli_stmt_error($stmt) . 'brbr');
 }; 



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



Re: [PHP] can I do this without eval?

2009-01-22 Thread Nathan Nobbe
On Thu, Jan 22, 2009 at 12:06 PM, Frank Stanovcak
blindspot...@comcast.netwrote:


 Nathan Nobbe quickshif...@gmail.com wrote in message
 news:7dd2dc0b0901221048g2f089cf9s36ecb9a5b35ab...@mail.gmail.com...
  On Thu, Jan 22, 2009 at 8:35 AM, Frank Stanovcak
  blindspot...@comcast.netwrote:
 
  I'm trying to build a prepared statment and dynamically bind the
  variables
  to it since I use this on severaly different pages I didn't want to
 build
  a
  huge bind statement hard coded on each page and then have to maintain it
  every time there was a change.
 
  I despise having to use eval() and was hoping one of you had stumbled
  upon
  this and found a better workaround for it.
 
  I've seen references to call_user_function_array, but couldn't find a
  tutorial, or description that could make me understand how to use it.
  I think the big problem with all of them was they expected me to know
  oop,
  and that is on my plate to learn after I finnish this project.
 
 
  Frank
 
  
  //initialize a variable to let us know this is the first time through on
  //the SET construction
   $i = true;
 
  //step through all the FILTERED values to build the SET statment
   foreach($FILTERED as $key=$value){
 
  //make sure we single quote the string fields
   if($i){
$sqlstring .=  $key = ?;
$i = false;
   }else{
$sqlstring .= , $key = ?;
   };
 
  //build the list of variables to bound durring the mysqli prepared
  staments
   $params[] = \$FILTERED[' . $key . '];
 
  //build the list of types for use durring the mysqli perepared statments
   switch($key){
   case in_array($key, $stringfields):
$ptype[] = 's';
break;
 
   case in_array($key, $doublefields):
$ptype[] = 'd';
break;
 
   default:
$ptype[] = 'i';
   };
   };
 
  //make sure we only update the row we are working on
   $sqlstring .= ' WHERE BoL=' . $FILTERED['BoL'];
 
  //connect to the db
   include('c:\inetpub\security\connection.php');
 
  //ok...let's do this query
  //use mysqli so we can use a prepared statment and avoid sql insert
  attacks
   $stmt = mysqli_prepare($iuserConnect, $sqlstring);
   if(!$stmt){
   die(mysqli_stmt_error($stmt));
   };
 
  //implode the two variables to be used in the mysqli bind statment so
  they
  are in
  //the proper formats
   $params = implode(, , $params);
   $ptype = implode('', $ptype);
 
  ---
  - is there a better way to accomplish this? -
  ---
  //run an eval to build the mysqli bind statment with the string list of
  variables
  //to be bound
   eval(\$check = mysqli_stmt_bind_param(\$stmt, '$ptype', $params););
   if(!$check){
   die(mysqli_stmt_error($stmt) . 'brbr');
   };
 
 
  yeah, id try call_user_func_array(),
 
  omit the line to create a string out of the $params, then merge the later
  arguments into an array w/ the first 2 args
 
  #$params = implode(, , $params);
  $check = call_user_func_array('mysqli_stmt_bind_param',
  array_merge(array($stmt, $ptype), $params));
 
  something like that i think should do the trick.
 
  -nathan
 

 Thanks Nathan!


np, please keep responses on list tho, so the conversations end up in the
archives for future benefit.


 Just to make sure I understand call_user_func_array, and how it opperates.
 It's first paramer is the name of the function...any function, which is
 part
 of what made it so confusing to me...and the second paramter is an array
 that will be used to populate the the parameters of the called function as
 a
 comma seperated list.


yes, thats correct, however the first argument is of the php pseudo-type
callback.  which can take one of 3 forms

. string of a global function name
. array containing, [handle to an object, name of an instance method
(string)]
. array containing, [name of a class (string), name of a static method
(string)]

you can find more on the php manual page about pseudo types

http://us2.php.net/manual/en/language.pseudo-types.php#language.types.callback

-nathan


Re: [PHP] Can I do in Drupal

2008-06-14 Thread Bastien Koert
On Sat, Jun 14, 2008 at 5:57 AM, mukesh yadav [EMAIL PROTECTED] wrote:

 Hi,
  I'm new to PHP and i have got an asign a job in PHP. I need to develop a
 site where a admin can handle a site like a CMS. e.g. updating a site
 without any tech guy.
 Is it possible using Drupal? If yes then can you please suggest how to go..

 thank you


yes, download drupal and install it

-- 

Bastien

Cat, the other other white meat


Re: [PHP] Can I do in Drupal

2008-06-14 Thread Daniel Brown
On Sat, Jun 14, 2008 at 5:57 AM, mukesh yadav [EMAIL PROTECTED] wrote:
 Hi,
  I'm new to PHP and i have got an asign a job in PHP. I need to develop a
 site where a admin can handle a site like a CMS. e.g. updating a site
 without any tech guy.
 Is it possible using Drupal? If yes then can you please suggest how to go..


http://www.catb.org/esr/jargon/html/S/STFW.html


-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

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



Re: [PHP] Can I do in Drupal

2008-06-14 Thread Robert Cummings
On Sat, 2008-06-14 at 10:35 -0400, Daniel Brown wrote:
 On Sat, Jun 14, 2008 at 5:57 AM, mukesh yadav [EMAIL PROTECTED] wrote:
  Hi,
   I'm new to PHP and i have got an asign a job in PHP. I need to develop a
  site where a admin can handle a site like a CMS. e.g. updating a site
  without any tech guy.
  Is it possible using Drupal? If yes then can you please suggest how to go..
 
 
 http://www.catb.org/esr/jargon/html/S/STFW.html

*lol* Whoever did that webpage needs to STFW about character encodings.

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] Can I do in Drupal

2008-06-14 Thread Daniel Brown
On Sat, Jun 14, 2008 at 11:32 AM, Robert Cummings [EMAIL PROTECTED] wrote:
 On Sat, 2008-06-14 at 10:35 -0400, Daniel Brown wrote:

 http://www.catb.org/esr/jargon/html/S/STFW.html

 *lol* Whoever did that webpage needs to STFW about character encodings.

Why?  What?s wrong with how they?re doing it?

-- 
/Daniel P. Brown
Dedicated Servers - Intel 2.4GHz w/2TB bandwidth/mo. starting at just
$59.99/mo. with no contract!
Dedicated servers, VPS, and hosting from $2.50/mo.

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



Re: [PHP] Can I do in Drupal

2008-06-14 Thread Robert Cummings
On Sat, 2008-06-14 at 11:38 -0400, Daniel Brown wrote:
 On Sat, Jun 14, 2008 at 11:32 AM, Robert Cummings [EMAIL PROTECTED] wrote:
  On Sat, 2008-06-14 at 10:35 -0400, Daniel Brown wrote:
 
  http://www.catb.org/esr/jargon/html/S/STFW.html
 
  *lol* Whoever did that webpage needs to STFW about character encodings.
 
 Why?  What?s wrong with how they?re doing it?

Methinks you already know! :D


-- 
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] can I do this: update table while selecting data from table?

2006-06-15 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 ?!?!?!?!?!?!

I hope youi used str_repeat() to generate that.


 seriously though, have you tried it?

 that said your [probably] better off just doing 1 query:

  UPDATE members SET member_name = 'N/A' WHERE member_name = '';

 that said your [probably] better off leaving the name empty or setting it
 NULL if
 it's unknown and showing 'N/A' in whatever output screen it's relevant for
 any
 names that are found to be empty.

 Thanks

 -afan

 --
 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] can I do this: update table while selecting data from table?

2006-06-15 Thread afan
I wonder why this sarcasm? Why so rude?

-afan


 [EMAIL PROTECTED] wrote:
 ?!?!?!?!?!?!

 I hope youi used str_repeat() to generate that.


 seriously though, have you tried it?

 that said your [probably] better off just doing 1 query:

 UPDATE members SET member_name = 'N/A' WHERE member_name = '';

 that said your [probably] better off leaving the name empty or setting
 it
 NULL if
 it's unknown and showing 'N/A' in whatever output screen it's relevant
 for
 any
 names that are found to be empty.

 Thanks

 -afan

 --
 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



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



Re: [PHP] can I do this: update table while selecting data from table?

2006-06-15 Thread afan
Jochem,
You are wrong. I tried and it worked. But, when I asked can I, I meant
Am I allowed to do that. The same as many security or other kind
questions where answer is: Yes, it works - but it's NOT correct.

Yes, I did search php.net but didn't find answer.
Yes, I did search mysql.com but didn't find answer.
(Hm, maybe I had to spend few more days before I'm ALLOWED to post a
question here)

And, please, if you DON'T WANT to help - don't answer at all. Believe me,
your kind of answer REALLY do not help. Contrary, brings this kind of
conversation what this great group really doesn't need.

Thanks.

-afan




 [EMAIL PROTECTED] wrote:
 I wonder why this sarcasm? Why so rude?

 your original question could have been answered by:

 a, trying to run the code provided (thats called testing btw)
 b, reading php.net
 c, reading mysql.com/docs (or where ever they have the docs this week)

 my reply not only contained the blantantly silly suggestion that you
 had to reboot the machine but also seriously asked if you had tried to run
 the code (I can garantee that you had not because then you would have know
 that it did work with out posting here) AND I offered 2 suugestions as to
 why the strategy you were employing for the routine sucked - one
 performance
 related, one with regard to DB/data theory.

 and all you could come up with as a response was '?!?!?!?!?!?!'

 you want spoonfeeding, try kindergarten.


 -afan


 [EMAIL PROTECTED] wrote:
 ?!?!?!?!?!?!
 I hope youi used str_repeat() to generate that.

 seriously though, have you tried it?

 that said your [probably] better off just doing 1 query:

   UPDATE members SET member_name = 'N/A' WHERE member_name = '';

 that said your [probably] better off leaving the name empty or
 setting
 it
 NULL if
 it's unknown and showing 'N/A' in whatever output screen it's
 relevant
 for
 any
 names that are found to be empty.

 Thanks

 -afan

 --
 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






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



Re: [PHP] can I do this: update table while selecting data from table?

2006-06-15 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 You are wrong. 

there's a first for everything, heh.

 I tried and it worked. But, when I asked can I, I meant
 Am I allowed to do that. The same as many security or other kind

then say what you mean in future. you already knew that you *can* do it,
you should have asked 'is this wise' - which would have led to a different
response namely:

in general nothing wrong with it, in your particular case it seems INEFFICIENT.

 questions where answer is: Yes, it works - but it's NOT correct.

there is nothing technically incorrect about perform a query whilst
looping the results of a different query btw.

 
 Yes, I did search php.net but didn't find answer.
 Yes, I did search mysql.com but didn't find answer.
 (Hm, maybe I had to spend few more days before I'm ALLOWED to post a
 question here)

your allowed to post whenever you want.

 And, please, if you DON'T WANT to help - don't answer at all. Believe me,
 your kind of answer REALLY do not help. Contrary, brings this kind of
 conversation what this great group really doesn't need.

REALLY I don't care what you think. you control what you post I control what I
post and not vice versa.

 
 Thanks.

for bruising your ego? or for originally giving 2 suggestions as to better
strategies for doing what you *seemed* to be wanting to achieve - 2 suggestions
which you blatantly seemed to ignore in favor of moaning about your bruised ego.

en fin.

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



Re: [PHP] can I do this: update table while selecting data from table?

2006-06-15 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 I wonder why this sarcasm? Why so rude?

your original question could have been answered by:

a, trying to run the code provided (thats called testing btw)
b, reading php.net
c, reading mysql.com/docs (or where ever they have the docs this week)

my reply not only contained the blantantly silly suggestion that you
had to reboot the machine but also seriously asked if you had tried to run
the code (I can garantee that you had not because then you would have know
that it did work with out posting here) AND I offered 2 suugestions as to
why the strategy you were employing for the routine sucked - one performance
related, one with regard to DB/data theory.

and all you could come up with as a response was '?!?!?!?!?!?!'

you want spoonfeeding, try kindergarten.

 
 -afan
 
 
 [EMAIL PROTECTED] wrote:
 ?!?!?!?!?!?!
 I hope youi used str_repeat() to generate that.

 seriously though, have you tried it?

 that said your [probably] better off just doing 1 query:

UPDATE members SET member_name = 'N/A' WHERE member_name = '';

 that said your [probably] better off leaving the name empty or setting
 it
 NULL if
 it's unknown and showing 'N/A' in whatever output screen it's relevant
 for
 any
 names that are found to be empty.

 Thanks

 -afan

 --
 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


 

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



Re: [PHP] can I do this: update table while selecting data from table?

2006-06-15 Thread tedd
At 4:11 PM +0200 6/15/06, [EMAIL PROTECTED] wrote:
Jochem,
You are wrong. I tried and it worked. But, when I asked can I, I meant
Am I allowed to do that. The same as many security or other kind
questions where answer is: Yes, it works - but it's NOT correct.

Yes, I did search php.net but didn't find answer.
Yes, I did search mysql.com but didn't find answer.
(Hm, maybe I had to spend few more days before I'm ALLOWED to post a
question here)

And, please, if you DON'T WANT to help - don't answer at all. Believe me,
your kind of answer REALLY do not help. Contrary, brings this kind of
conversation what this great group really doesn't need.

Thanks.

-afan

-afan:

You should keep this in mind while posting.

People, like Jochem, are here to help you with no reward except that they are 
helping others. They spend their time reading your post and trying to provide 
you with guidance from their experience.

I can't speak for Jochem, but sometimes what we post doesn't come across as 
well as we intended. I know I've pissed-off some people on this list and I 
regret that, even though it was unintentional.

So, try to give those who try to help you a bit slack. Permit them the right to 
tell you to RTFM or whatever else they think will help you. Granted, sometimes 
we don't want to hear what our problem is, but that's what happens when you 
post to a list asking for help.

So, cut us all a bit of slack and we'll all be better for it.

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] can I do this: update table while selecting data from table?

2006-06-15 Thread afan
Yes, you are right, I had to be more carefull about how to write my post.

 Thanks.

 for bruising your ego? or for originally giving 2 suggestions as to better
 strategies for doing what you *seemed* to be wanting to achieve - 2
 suggestions
 which you blatantly seemed to ignore in favor of moaning about your
 bruised ego.

Since you didn't get it, Thanks is part of polite communication between
people.

-afan



 [EMAIL PROTECTED] wrote:
 You are wrong.

 there's a first for everything, heh.

 I tried and it worked. But, when I asked can I, I meant
 Am I allowed to do that. The same as many security or other kind

 then say what you mean in future. you already knew that you *can* do it,
 you should have asked 'is this wise' - which would have led to a different
 response namely:

 in general nothing wrong with it, in your particular case it seems
 INEFFICIENT.

 questions where answer is: Yes, it works - but it's NOT correct.

 there is nothing technically incorrect about perform a query whilst
 looping the results of a different query btw.


 Yes, I did search php.net but didn't find answer.
 Yes, I did search mysql.com but didn't find answer.
 (Hm, maybe I had to spend few more days before I'm ALLOWED to post a
 question here)

 your allowed to post whenever you want.

 And, please, if you DON'T WANT to help - don't answer at all. Believe
 me,
 your kind of answer REALLY do not help. Contrary, brings this kind of
 conversation what this great group really doesn't need.

 REALLY I don't care what you think. you control what you post I control
 what I
 post and not vice versa.


 Thanks.

 for bruising your ego? or for originally giving 2 suggestions as to better
 strategies for doing what you *seemed* to be wanting to achieve - 2
 suggestions
 which you blatantly seemed to ignore in favor of moaning about your
 bruised ego.

 en fin.

 --
 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] can I do this: update table while selecting data from table?

2006-06-14 Thread Jochem Maas
[EMAIL PROTECTED] wrote:
 Am I allowde to do this:
 
 $query = mysql_query(SELECT member_id, member_name FROM members);
 while($result = mysql_fetch_array($query))
 {
   if(empty($result['member_name']))
   {
 mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id =
 .$result['member_id'].);
   }
 }
 
 As far as I know, after SELECT query, data are in buffer and I AM able
 to connect to the same table and do UPDATE, right?

no you'll have to reboot the machine first.








seriously though, have you tried it?

that said your [probably] better off just doing 1 query:

UPDATE members SET member_name = 'N/A' WHERE member_name = '';

that said your [probably] better off leaving the name empty or setting it NULL 
if
it's unknown and showing 'N/A' in whatever output screen it's relevant for any
names that are found to be empty.

 
 Thanks
 
 -afan
 

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



Re: [PHP] can I do this: update table while selecting data from table?

2006-06-14 Thread Satyam

It looks very much as if you did:

update members set member_name = 'N/A' where member_name = null

Nevertheless, I would rather keep null within the database and use 'N/A' at 
the presentation level. My rule is that the data in the database should 
be in a machine oriented format.  For example, I store timestamps, never 
formated dates, numbers as actual numerical datatypes, not as strings, 
though PHP can cope with either.  'N/A' is a way to present that information 
to the user, which might even be, for example, language dependant.


On displaying, you could well do:

SELECT member_id, ifnull(member_name,'N/A') FROM members

Satyam


- Original Message - 
From: [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Wednesday, June 14, 2006 11:37 PM
Subject: [PHP] can I do this: update table while selecting data from table?



Am I allowde to do this:

$query = mysql_query(SELECT member_id, member_name FROM members);
while($result = mysql_fetch_array($query))
{
 if(empty($result['member_name']))
 {
   mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id =
.$result['member_id'].);
 }
}

As far as I know, after SELECT query, data are in buffer and I AM able
to connect to the same table and do UPDATE, right?

Thanks

-afan

--
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] can I do this: update table while selecting data from table?

2006-06-14 Thread afan
?!?!?!?!?!?!



 [EMAIL PROTECTED] wrote:
 Am I allowde to do this:

 $query = mysql_query(SELECT member_id, member_name FROM members);
 while($result = mysql_fetch_array($query))
 {
   if(empty($result['member_name']))
   {
 mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id
 =
 .$result['member_id'].);
   }
 }

 As far as I know, after SELECT query, data are in buffer and I AM able
 to connect to the same table and do UPDATE, right?

 no you'll have to reboot the machine first.








 seriously though, have you tried it?

 that said your [probably] better off just doing 1 query:

   UPDATE members SET member_name = 'N/A' WHERE member_name = '';

 that said your [probably] better off leaving the name empty or setting it
 NULL if
 it's unknown and showing 'N/A' in whatever output screen it's relevant for
 any
 names that are found to be empty.


 Thanks

 -afan


 --
 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] can I do this: update table while selecting data from table?

2006-06-14 Thread afan
No, that was just an exapmle to explain better. Of course this is not the
REAL code. :)
And there are some more thing to do inside while loop.

Thanks.

-afan


 It looks very much as if you did:

 update members set member_name = 'N/A' where member_name = null

 Nevertheless, I would rather keep null within the database and use 'N/A'
 at
 the presentation level. My rule is that the data in the database
 should
 be in a machine oriented format.  For example, I store timestamps, never
 formated dates, numbers as actual numerical datatypes, not as strings,
 though PHP can cope with either.  'N/A' is a way to present that
 information
 to the user, which might even be, for example, language dependant.

 On displaying, you could well do:

 SELECT member_id, ifnull(member_name,'N/A') FROM members

 Satyam


 - Original Message -
 From: [EMAIL PROTECTED]
 To: php-general@lists.php.net
 Sent: Wednesday, June 14, 2006 11:37 PM
 Subject: [PHP] can I do this: update table while selecting data from
 table?


 Am I allowde to do this:

 $query = mysql_query(SELECT member_id, member_name FROM members);
 while($result = mysql_fetch_array($query))
 {
  if(empty($result['member_name']))
  {
mysql_query(UPDATE members SET member_name = 'N/A' WHERE member_id =
 .$result['member_id'].);
  }
 }

 As far as I know, after SELECT query, data are in buffer and I AM able
 to connect to the same table and do UPDATE, right?

 Thanks

 -afan

 --
 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



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



Re: [PHP] can i do this in one step

2006-04-18 Thread Jochem Maas

Ross wrote:
I am retrieving the vlaue from an associative arrray but do I need to do it 
in with two lines of code? The numerical value is stroed in the DB.



$region_array = array('a' ='All of Scotland', 1 ='Aberdeen City Council',
2 ='Aberdeenshire Council', 3 ='AngusCouncil', 5 ='Argyll and Bute
Council', 6 = 'Clackmannanshire Council', 9 ='Dumfries and Gallowalloway',
10 = 'Dundee City Council', 11 = 'East Ayrshire Council', 13 = 'East
Dunbartonshire', 14 = 'East Lothian Council', 15 = 'East Renfrewshire
Council', 16 ='Edinburgh City Council', 17 ='Falkirk Council', 18 ='Fife
Council', 20 ='Highland Council', 21 ='Inverclyde Council', 22
='Midlothian Council', 23 = 'Moray Council', 24 ='North Ayrshire
Council', 25 ='North Lanarkshire Council', 26 ='Orkney Islands Council',
27 ='Perth  Kinross Council', 28 = 'Renfrewshire Council',29 ='Scottish
Borders Council', 30 = 'Shetland Isles Council', 31 ='South Ayrshire
Council', 32 = 'South Lanarkshire Council', 33 = 'Stirling Council', 34
='West Dunbartonshire', 35 = 'West Lothian Council', 8 = 'Comhairle nan
Eilean');

$convert=$row['area'];
$area= $region_array['$convert'];



$area = $region_array[ $row['area'] ];

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



Re: [PHP] can I do a for each here??

2005-03-17 Thread Chris Ramsay
Difficult to be definitive without seeing your code, but I would be
tempted by the use of arrays...

cheers

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



Re: [PHP] can I do a for each here??

2005-03-17 Thread Marek Kilimajer
AndreaD wrote:
I have about 10 text boxes each taking in value (ages) , The code I have 
checks for a value and if it is set it then sets the cookie to that value. 
The else just clears the value. On the next page I use a foreach to get the 
values but I think there must be a quicker way to collect the data appart 
from 10 if-else staements.

if (isset($andrea){
setcookie(cookie[andrea], $andrea);
}
else {setcookie(cookie[$andrea], );
}
if (isset($james){
setcookie(cookie[james], $james);
}
else {setcookie(cookie[$james], );
}
$names = array('andrea', 'james', ...);
foreach($names as $name) {
  if (isset($_POST[$name]){
setcookie(cookie[$name], $_POST[$name]);
  } else {
setcookie(cookie[$name], );
  }
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] can I do a for each here??

2005-03-17 Thread AndreaD
Think what I want to do then is create two arrays, one for the values of the 
age and one for the correponding name e.g.

$age  = array() // this is the inputed textbox values
$name= array('john', 'bob', 'tim')

Then I need to assign the the ages to cookie of the persons name by using a 
for or do-while loop.

loop{
if (isset($age[x])){setcookie(cookie[ $name[x] ], $age[x]);}
else {
setcookie(cookie[ name[x] ], );}

}end loop

Any suggestion how I would execute this would be fantactic. Not to worry I 
can just have 10 lines if need be.

AD


Chris Ramsay [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]
 Difficult to be definitive without seeing your code, but I would be
 tempted by the use of arrays...

 cheers 

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



Re: [PHP] can I do a for each here??

2005-03-17 Thread Jeff Schmidt
I would be tempted to do the following.
First, I would setup the html form so that the text boxes are named 
something like 'age[Andrea]', 'age[Bob]', etc. When the form submitted, 
this will give you an array, accessible as $_POST['age'] (or 
$_GET['age'] depending on whether you used POST or GET form submission 
method).

This array would look like (Andrea = 25, Bob = 13, etc).
Then, I would use the following:
foreach($_POST['age'] as $name = $age)
{
  setcookie(cookie[$name], $age);
}
Although, unfortunately, this approach you take of using seperate 
cookies for all your different stored value is what I call cookie bloat. 
I would suggest you look at PHP's built-in session handling facilities.

http://www.php.net/manual/en/ref.session.php
 The way the session handling works is, in a nutshell, at the start of 
each of your scripts, you call session_start(). Then, you can access 
session variables as $_SESSION['name']. You can use the isset() operator 
to test to see if you already set a session variable, and you can use 
any of the normal access methods to manipulating the variable. You 
assign to it with $_SESSION['name'] = value, you can get the value 
just by using $_SESSION['name'] anywhere you would otherwise use a 
variable or constant (e.g. if($_SESSION['ages']['Andrea']  18) {echo 
You have been selected for Jury duty.;}.

(All this assumes your hosting provider has setup PHP for you, and 
configured the session handler. If that is not the case, then cookies 
might be an easier way to go. Depending on how ambitious you feel, and 
how much control you have of your site, you might also setup session 
handling yourself - it's not incredibly difficult, just read the 
documentation).

With that in mind, I would alter my above code to be the following:
foreach($_POST['age'] as $name = $age)
{
  $_SESSION['age'][$name] = $age;
}
AndreaD wrote:
Think what I want to do then is create two arrays, one for the values of the 
age and one for the correponding name e.g.

$age  = array() // this is the inputed textbox values
$name= array('john', 'bob', 'tim')
Then I need to assign the the ages to cookie of the persons name by using a 
for or do-while loop.

loop{
if (isset($age[x])){setcookie(cookie[ $name[x] ], $age[x]);}
else {
setcookie(cookie[ name[x] ], );}
}end loop
Any suggestion how I would execute this would be fantactic. Not to worry I 
can just have 10 lines if need be.

AD
Chris Ramsay [EMAIL PROTECTED] wrote in message 
news:[EMAIL PROTECTED]

Difficult to be definitive without seeing your code, but I would be
tempted by the use of arrays...
cheers 

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


Re: [PHP] can I do a for each here??

2005-03-17 Thread Jeff Schmidt
Yeah, after hitting the send button, I looked again at what I sent and 
realized something else. Having already caused PHP to put the stuff into 
an array, by the way I suggested constructing the form, you can 
eliminate the foreach loop, and just use the assignment operator to get 
PHP to copy the array from $_POST to $_SESSION (although, you might want 
to do some validation code, in which case you probably do want to use 
the foreach block, so that you have a chance to validate each of the 
submitted values, and the keys [sometimes it's usefull to validate the 
keys, to check to see if someone has forged a form submission with 
values other than what they are supposed to be using]).

But, assuming you aren't worried about validating, you could do like this:
$_SESSION['age'] = $_POST['age'];
But, honestly, I would still use the foreach loop, check the values of 
$name and $age to make sure they are legal, and in the correct format, 
and then assign them individually, as before.

Jeff
Jeff Schmidt wrote:
I would be tempted to do the following.
First, I would setup the html form so that the text boxes are named 
something like 'age[Andrea]', 'age[Bob]', etc. When the form submitted, 
this will give you an array, accessible as $_POST['age'] (or 
$_GET['age'] depending on whether you used POST or GET form submission 
method).

This array would look like (Andrea = 25, Bob = 13, etc).
Then, I would use the following:
foreach($_POST['age'] as $name = $age)
{
  setcookie(cookie[$name], $age);
}

[snip]
With that in mind, I would alter my above code to be the following:
foreach($_POST['age'] as $name = $age)
{
  $_SESSION['age'][$name] = $age;
}
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] can I do a for each here??

2005-03-17 Thread Chris Shiflett
AndreaD wrote:
I have about 10 text boxes each taking in value (ages), The code I have
checks for a value and if it is set it then sets the cookie to that value.
The else just clears the value. On the next page I use a foreach to get the
values but I think there must be a quicker way to collect the data appart
from 10 if-else staements.
if (isset($andrea){
setcookie(cookie[andrea], $andrea);
}
else {setcookie(cookie[$andrea], );
}
Let's look at your two setcookie() calls:
setcookie(cookie[andrea], $andrea)
setcookie(cookie[$andrea], )
Just for debugging purposes, assume $andrea is initialized prior to this 
as follows:

$andrea = 29;
So, your code says that you want a cookie with the following name and 
value (available on the next request):

$_COOKIE['cookie[andrea]'] = 29;
Is that really what you want?
Of course, it's very odd that if $andrea is not set, you want a cookie 
like this:

$_COOKIE['cookie[]'] = '';
In addition, you will be generating a notice, because you're using 
$andrea in the name of the cookie, although you're first making certain 
that $andrea isn't set.

I'm also a bit concerned about where $andrea originates. Is this coming 
from the user, and you're trusting it? That's a very dangerous practice.

If you explain your problem, we might be able to offer some help.
Chris
--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Can I do this? If so why wont it work

2004-01-16 Thread Jake McHenry

- Original Message - 
From: Alex Hogan [EMAIL PROTECTED]
To: PHP General list [EMAIL PROTECTED]
Sent: Friday, January 16, 2004 4:20 PM
Subject: [PHP] Can I do this? If so why wont it work


 I am wanting to read in several session values at once.
 
  
 
 This is what I have so far;
 
  
 
 $_SESSION['obj[1]'] = $_REQUEST['txtObj1'];
 
 $_SESSION['obj[2]'] = $_REQUEST['txtObj2'];
 
 $_SESSION['obj[3]'] = $_REQUEST['txtObj3'];
 
 $_SESSION['obj[4]'] = $_REQUEST['txtObj4'];
 
 $_SESSION['obj[5]'] = $_REQUEST['txtObj5'];
 
  
 
 $i = 1;
 
 while ($i = 5) {
 
 $obj_ar[$i] = $_SESSION['obj[$i]']$i++;
 
 }
 
  
 
 I keep getting this error;
 
 Parse error: parse error, unexpected T_VARIABLE in mypage.php on line 24 
 
  
 
 Where am I making the mistake?
 
  
 
 alex hogan
 
  
 
 
 
 ** 
 The contents of this e-mail and any files transmitted with it are 
 confidential and intended solely for the use of the individual or 
 entity to whom it is addressed.  The views stated herein do not 
 necessarily represent the view of the company.  If you are not the 
 intended recipient of this e-mail you may not copy, forward, 
 disclose, or otherwise use it or any part of it in any form 
 whatsoever.  If you have received this e-mail in error please 
 e-mail the sender. 
 ** 
 
 
 



What is on line 24?



Try this:

while ($i = 5) {
$obj_ar[$i] = $_SESSION['obj[$i]'];
$i++;
}


Jake

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



RE: [PHP] Can I do this? If so why wont it work

2004-01-16 Thread Alex Hogan

Line 24 is: $obj_ar[$i] = $_SESSION['obj[$i]']$i++;


Alex

 -Original Message-
 From: Jake McHenry [mailto:[EMAIL PROTECTED]
 Sent: Friday, January 16, 2004 3:31 PM
 To: Alex Hogan
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] Can I do this? If so why wont it work
 
 
 - Original Message -
 From: Alex Hogan [EMAIL PROTECTED]
 To: PHP General list [EMAIL PROTECTED]
 Sent: Friday, January 16, 2004 4:20 PM
 Subject: [PHP] Can I do this? If so why wont it work
 
 
  I am wanting to read in several session values at once.
 
 
 
  This is what I have so far;
 
 
 
  $_SESSION['obj[1]'] = $_REQUEST['txtObj1'];
 
  $_SESSION['obj[2]'] = $_REQUEST['txtObj2'];
 
  $_SESSION['obj[3]'] = $_REQUEST['txtObj3'];
 
  $_SESSION['obj[4]'] = $_REQUEST['txtObj4'];
 
  $_SESSION['obj[5]'] = $_REQUEST['txtObj5'];
 
 
 
  $i = 1;
 
  while ($i = 5) {
 
  $obj_ar[$i] = $_SESSION['obj[$i]']$i++;
 
  }
 
 
 
  I keep getting this error;
 
  Parse error: parse error, unexpected T_VARIABLE in mypage.php on line 24
 
 
 
  Where am I making the mistake?
 
 
 
  alex hogan
 
 
 
 
 
  **
  The contents of this e-mail and any files transmitted with it are
  confidential and intended solely for the use of the individual or
  entity to whom it is addressed.  The views stated herein do not
  necessarily represent the view of the company.  If you are not the
  intended recipient of this e-mail you may not copy, forward,
  disclose, or otherwise use it or any part of it in any form
  whatsoever.  If you have received this e-mail in error please
  e-mail the sender.
  **
 
 
 
 
 
 
 What is on line 24?
 
 
 
 Try this:
 
 while ($i = 5) {
 $obj_ar[$i] = $_SESSION['obj[$i]'];
 $i++;
 }
 
 
 Jake


** 
The contents of this e-mail and any files transmitted with it are 
confidential and intended solely for the use of the individual or 
entity to whom it is addressed.  The views stated herein do not 
necessarily represent the view of the company.  If you are not the 
intended recipient of this e-mail you may not copy, forward, 
disclose, or otherwise use it or any part of it in any form 
whatsoever.  If you have received this e-mail in error please 
e-mail the sender. 
** 




RE: [PHP] Can I do this? If so why wont it work

2004-01-16 Thread Alex Hogan
Tried it now I get;

Parse error: parse error, unexpected T_VARIABLE in mypage.php on line 22

Line 22 is $i++;

 Try this:
 
 while ($i = 5) {
 $obj_ar[$i] = $_SESSION['obj[$i]'];
 $i++;
 }


** 
The contents of this e-mail and any files transmitted with it are 
confidential and intended solely for the use of the individual or 
entity to whom it is addressed.  The views stated herein do not 
necessarily represent the view of the company.  If you are not the 
intended recipient of this e-mail you may not copy, forward, 
disclose, or otherwise use it or any part of it in any form 
whatsoever.  If you have received this e-mail in error please 
e-mail the sender. 
** 




Re: [PHP] Can I do this? If so why wont it work

2004-01-16 Thread John W. Holmes
Alex Hogan wrote:
I am wanting to read in several session values at once.

 

This is what I have so far;

 

$_SESSION['obj[1]'] = $_REQUEST['txtObj1'];

$_SESSION['obj[2]'] = $_REQUEST['txtObj2'];

$_SESSION['obj[3]'] = $_REQUEST['txtObj3'];

$_SESSION['obj[4]'] = $_REQUEST['txtObj4'];

$_SESSION['obj[5]'] = $_REQUEST['txtObj5'];

 

$i = 1;

while ($i = 5) {

$obj_ar[$i] = $_SESSION['obj[$i]']$i++;

}
I keep getting this error;
Parse error: parse error, unexpected T_VARIABLE in mypage.php on line 24 
Well, first your error is because you have $i++ on that last line. It 
should be separated like someone else mentioned. Second, using 
['obj[$i]'] as the key is not going to work because $i is not 
evaluated between single quotes.

Third, you really need to change how you do all of this and understand 
arrays a little better.

First thing to do is instead of naming things txtObj1 and txtObj2, 
etc, name them txtObj[]. Name every one of them that. Now, when the 
form is submitted, you'll have a $_REQUEST['txtObj'] array containing 
all of your data. $_REQUEST['txtObj'][0] will be the first value, 
$_REQUEST['txtObj'][1] will be the second, etc.

To save that in the session, you can simply do:

$_SESSION['txtObj'] = $_REQUEST['txtObj'];

Now, $_SESSION['txtObj'][0] is the first one, $_SESSION['txtObj'][1] is 
the second, etc.

Any time you're naming things _1, _2, _3, etc, you're doing it the hard 
way instead of using an array.

Hope this helps.

--
---John Holmes...
Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/

php|architect: The Magazine for PHP Professionals  www.phparch.com

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


RE: [PHP] Can I do this? If so why wont it work

2004-01-16 Thread Alex Hogan
Thanks..

 -Original Message-
 From: John W. Holmes [mailto:[EMAIL PROTECTED]
 Sent: Friday, January 16, 2004 4:29 PM
 To: Alex Hogan
 Cc: PHP General list
 Subject: Re: [PHP] Can I do this? If so why wont it work
 
 Alex Hogan wrote:
  I am wanting to read in several session values at once.
 
 
 
  This is what I have so far;
 
 
 
  $_SESSION['obj[1]'] = $_REQUEST['txtObj1'];
 
  $_SESSION['obj[2]'] = $_REQUEST['txtObj2'];
 
  $_SESSION['obj[3]'] = $_REQUEST['txtObj3'];
 
  $_SESSION['obj[4]'] = $_REQUEST['txtObj4'];
 
  $_SESSION['obj[5]'] = $_REQUEST['txtObj5'];
 
 
 
  $i = 1;
 
  while ($i = 5) {
 
  $obj_ar[$i] = $_SESSION['obj[$i]']$i++;
 
  }
  I keep getting this error;
 
  Parse error: parse error, unexpected T_VARIABLE in mypage.php on line 24
 
 Well, first your error is because you have $i++ on that last line. It
 should be separated like someone else mentioned. Second, using
 ['obj[$i]'] as the key is not going to work because $i is not
 evaluated between single quotes.
 
 Third, you really need to change how you do all of this and understand
 arrays a little better.
 
 First thing to do is instead of naming things txtObj1 and txtObj2,
 etc, name them txtObj[]. Name every one of them that. Now, when the
 form is submitted, you'll have a $_REQUEST['txtObj'] array containing
 all of your data. $_REQUEST['txtObj'][0] will be the first value,
 $_REQUEST['txtObj'][1] will be the second, etc.
 
 To save that in the session, you can simply do:
 
 $_SESSION['txtObj'] = $_REQUEST['txtObj'];
 
 Now, $_SESSION['txtObj'][0] is the first one, $_SESSION['txtObj'][1] is
 the second, etc.
 
 Any time you're naming things _1, _2, _3, etc, you're doing it the hard
 way instead of using an array.
 
 Hope this helps.
 
 --
 ---John Holmes...
 
 Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
 
 php|architect: The Magazine for PHP Professionals - www.phparch.com
 
 
 



** 
The contents of this e-mail and any files transmitted with it are 
confidential and intended solely for the use of the individual or 
entity to whom it is addressed.  The views stated herein do not 
necessarily represent the view of the company.  If you are not the 
intended recipient of this e-mail you may not copy, forward, 
disclose, or otherwise use it or any part of it in any form 
whatsoever.  If you have received this e-mail in error please 
e-mail the sender. 
** 




Re: [PHP] Can I do this? header(Content-type: text/rtf);

2003-02-20 Thread David Otton
On Thu, 20 Feb 2003 03:42:14 -0500, you wrote:

I'm using PHP  MySQL to generate a RTF document. I use this header:

header(Content-type: text/rtf);

Of course, the header scares the poor browser. The browser bawks and says, unknown 
file type, and instructs the browser to save the file.

It tries to save a file called export_to_rtf_text_format.php

The folks I work with are technologically challenged. Asking them to save that 
document and rename it to *.rtf may be disasterous.

Come on, we all work with a couple technologically challenged people :) I like mine 
so I try to make their life easier!

Sooo ... can I change the header somehow to instruct it to save a file called 
export_to_rtf_text_format.rtf instead?

If this is an intranet (ie you know everyone's on the same platform),
then header(Content-type: application/msword); will encourage the file
to open in Word (which is where you probably wanted it anyway).

If this is the only rtf file on your webserver, you could set it up so
*.rtf files get run under PHP just as *.php files do, then rename your
file to *.rtf

Again on an intranet, fix everyone's browsers so they handle text/rtf
correctly.


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




Re: [PHP] Can I do this? header(Content-type: text/rtf);

2003-02-20 Thread David Otton
On Thu, 20 Feb 2003 03:42:14 -0500, you wrote:

I'm using PHP  MySQL to generate a RTF document. I use this header:

header(Content-type: text/rtf);

Sorry, I should have mentioned

header(Content-Disposition: attachment; filename=myfile.rtf);

as well. Rather easier :)


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




Re: [PHP] Can I do this? header(Content-type: text/rtf);

2003-02-20 Thread John Taylor-Johnston
Works great. Thanks,
John


 I'm using PHP  MySQL to generate a RTF document. I use this header:
 header(Content-type: text/rtf);
 header(Content-Disposition: attachment; filename=myfile.rtf);

--
John Taylor-Johnston
-
If it's not open-source, it's Murphy's Law.

Université de Sherbrooke:
http://compcanlit.ca/


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




RE: [PHP] Can i do this?

2001-12-13 Thread Jack Dempsey

didn't check your code specifically, but you can definitely have arrays
nested inside of arrays...to see how to print them out use something like
print_r to look  at the structure...

-Original Message-
From: Daniel Alsén [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 13, 2001 10:12 AM
To: PHP
Subject: [PHP] Can i do this?


Hi,

can i do this?

$num_vals = array ();
for ($i=0; $i10; $i++)
{
  $shot_count = SELECT COUNT(*) FROM statistik WHERE
shooter='$shooter_login'  shot_one = '$i' || shooter='$shooter_login' 
shot_two = '$i' || shooter='$shooter_login'  shot_three = '$i' ||
shooter='$shooter_login'  shot_four = '$i' || shooter='$shooter_login' 
shot_five = '$i';
  $result = mysql_query($shot_count);
  $num_vals[$i] = mysql_fetch_array($result);
}

I guess it´s the last row that is troubling - getting an array into an
array. If the code is good - how do i echo the results?

# Daniel Alsén| www.mindbash.com #
# [EMAIL PROTECTED]  | +46 704 86 14 92 #
# ICQ: 63006462   | +46 8 694 82 22  #
# PGP: http://www.mindbash.com/pgp/  #


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Can i do this?

2001-12-13 Thread Jeremy Reed

However, in your if statement, you need to nest your statements with
parenthesis.

Jack Dempsey [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 didn't check your code specifically, but you can definitely have arrays
 nested inside of arrays...to see how to print them out use something like
 print_r to look  at the structure...

 -Original Message-
 From: Daniel Alsén [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, December 13, 2001 10:12 AM
 To: PHP
 Subject: [PHP] Can i do this?


 Hi,

 can i do this?

 $num_vals = array ();
 for ($i=0; $i10; $i++)
 {
   $shot_count = SELECT COUNT(*) FROM statistik WHERE
 shooter='$shooter_login'  shot_one = '$i' || shooter='$shooter_login' 
 shot_two = '$i' || shooter='$shooter_login'  shot_three = '$i' ||
 shooter='$shooter_login'  shot_four = '$i' || shooter='$shooter_login'

 shot_five = '$i';
   $result = mysql_query($shot_count);
   $num_vals[$i] = mysql_fetch_array($result);
 }

 I guess it´s the last row that is troubling - getting an array into an
 array. If the code is good - how do i echo the results?

 # Daniel Alsén| www.mindbash.com #
 # [EMAIL PROTECTED]  | +46 704 86 14 92 #
 # ICQ: 63006462   | +46 8 694 82 22  #
 # PGP: http://www.mindbash.com/pgp/  #


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]





-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Can i do this?

2001-12-13 Thread Daniel Alsén

Yep...

And i don´t get any wiser. I have tried all sorts of combinations. But i
can´t get the damn values printed.

This is how the print_r of $num_vals looks:

( [0] = Array ( [0] = 0 [COUNT(*)] = 0 )
[1] = Array ( [0] = 0 [COUNT(*)] = 0 )
[2] = Array ( [0] = 5 [COUNT(*)] = 5 )
[3] = Array ( [0] = 6 [COUNT(*)] = 6 )
[4] = Array ( [0] = 7 [COUNT(*)] = 7 )
[5] = Array ( [0] = 7 [COUNT(*)] = 7 )
[6] = Array ( [0] = 9 [COUNT(*)] = 9 )
[7] = Array ( [0] = 11 [COUNT(*)] = 11 )
[8] = Array ( [0] = 8 [COUNT(*)] = 8 )
[9] = Array ( [0] = 9 [COUNT(*)] = 9 ) )

Ideas?

Regards
Daniel

 -Original Message-
 From: Jack Dempsey [mailto:[EMAIL PROTECTED]]
 Sent: den 13 december 2001 16:30
 To: Daniel Alsén; PHP
 Subject: RE: [PHP] Can i do this?


 didn't check your code specifically, but you can definitely have arrays
 nested inside of arrays...to see how to print them out use something like
 print_r to look  at the structure...

 -Original Message-
 From: Daniel Alsén [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, December 13, 2001 10:12 AM
 To: PHP
 Subject: [PHP] Can i do this?


 Hi,

 can i do this?

 $num_vals = array ();
 for ($i=0; $i10; $i++)
 {
   $shot_count = SELECT COUNT(*) FROM statistik WHERE
 shooter='$shooter_login'  shot_one = '$i' || shooter='$shooter_login' 
 shot_two = '$i' || shooter='$shooter_login'  shot_three = '$i' ||
 shooter='$shooter_login'  shot_four = '$i' ||
 shooter='$shooter_login' 
 shot_five = '$i';
   $result = mysql_query($shot_count);
   $num_vals[$i] = mysql_fetch_array($result);
 }

 I guess it´s the last row that is troubling - getting an array into an
 array. If the code is good - how do i echo the results?

 # Daniel Alsén| www.mindbash.com #
 # [EMAIL PROTECTED]  | +46 704 86 14 92 #
 # ICQ: 63006462   | +46 8 694 82 22  #
 # PGP: http://www.mindbash.com/pgp/  #


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Can i do this?

2001-12-13 Thread Martin Towell

try:
echo $num_vals[0][0];  // should display 0
echo $num_vals[0][COUNT(*)]; // should display 0
echo $num_vals[1][0];  // should display 0
echo $num_vals[1][COUNT(*)]; // should display 0
echo $num_vals[2][0];  // should display 5
echo $num_vals[2][COUNT(*)]; // should display 5
// etc...

-Original Message-
From: Daniel Alsén [mailto:[EMAIL PROTECTED]]
Sent: Friday, December 14, 2001 9:31 AM
To: PHP; Jack Dempsey
Subject: RE: [PHP] Can i do this?


Yep...

And i don´t get any wiser. I have tried all sorts of combinations. But i
can´t get the damn values printed.

This is how the print_r of $num_vals looks:

( [0] = Array ( [0] = 0 [COUNT(*)] = 0 )
[1] = Array ( [0] = 0 [COUNT(*)] = 0 )
[2] = Array ( [0] = 5 [COUNT(*)] = 5 )
[3] = Array ( [0] = 6 [COUNT(*)] = 6 )
[4] = Array ( [0] = 7 [COUNT(*)] = 7 )
[5] = Array ( [0] = 7 [COUNT(*)] = 7 )
[6] = Array ( [0] = 9 [COUNT(*)] = 9 )
[7] = Array ( [0] = 11 [COUNT(*)] = 11 )
[8] = Array ( [0] = 8 [COUNT(*)] = 8 )
[9] = Array ( [0] = 9 [COUNT(*)] = 9 ) )

Ideas?

Regards
Daniel

 -Original Message-
 From: Jack Dempsey [mailto:[EMAIL PROTECTED]]
 Sent: den 13 december 2001 16:30
 To: Daniel Alsén; PHP
 Subject: RE: [PHP] Can i do this?


 didn't check your code specifically, but you can definitely have arrays
 nested inside of arrays...to see how to print them out use something like
 print_r to look  at the structure...

 -Original Message-
 From: Daniel Alsén [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, December 13, 2001 10:12 AM
 To: PHP
 Subject: [PHP] Can i do this?


 Hi,

 can i do this?

 $num_vals = array ();
 for ($i=0; $i10; $i++)
 {
   $shot_count = SELECT COUNT(*) FROM statistik WHERE
 shooter='$shooter_login'  shot_one = '$i' || shooter='$shooter_login' 
 shot_two = '$i' || shooter='$shooter_login'  shot_three = '$i' ||
 shooter='$shooter_login'  shot_four = '$i' ||
 shooter='$shooter_login' 
 shot_five = '$i';
   $result = mysql_query($shot_count);
   $num_vals[$i] = mysql_fetch_array($result);
 }

 I guess it´s the last row that is troubling - getting an array into an
 array. If the code is good - how do i echo the results?

 # Daniel Alsén| www.mindbash.com #
 # [EMAIL PROTECTED]  | +46 704 86 14 92 #
 # ICQ: 63006462   | +46 8 694 82 22  #
 # PGP: http://www.mindbash.com/pgp/  #


 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]