Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread Vern
Problem with that is it sorts according the results of the recordset range.

For instance:

It will show the user 1 trhough 10 sorted by miles then 20 - 30 sorted by
miles, however, in 1 through 10 could have a range of 0 to 1000 miles and
the next set will have 5 to 200 miles. What I need is to sort them all by
miles first. The only way I know to do that is to do the way I set it up. So
if I create an array, sort that array by the miles then use that array.
However the array is different that the recordset and thus does not use
LIMIT.

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



Re: [PHP] arrays() current() next() who to use

2004-08-19 Thread John Holmes
> From: "Vern" <[EMAIL PROTECTED]>

> How can I now get this output displyed in groups 
> of 10 so that I can display them 10 at a time on 
> a page then click a next button to dispaly they 
> next 10 and so forth?

Can't you do all that sorting in your query so you can just retrieve 10 rows at a time 
using LIMIT?

---John Holmes...

UCCASS - PHP Survey System
http://www.bigredspark.com/survey.html

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



[PHP] arrays() current() next() who to use

2004-08-19 Thread Vern
I'm setting up an array based on recordset that does a loop as follows:

do {
//SET ARRAYS
$z['username'][$k] = $row_rsUSERIDID['uname'];
$z['distance'][$k++] = $totaldist;
} while ($row_rsUSERIDID = mysql_fetch_assoc($rsUSERIDID));


//SET NEW ARRAY
$z['user'] = $z['username'];

//SORT BY DISTANCES
natsort ($z['distance']);
reset ($z['distance']);

foreach($z['distance'] as $k => $v){
$newuser = "{$z['user'][$k]}";
echo $newuser . "";
}

How can I now get this output displyed in groups of 10 so that I can display
them 10 at a time on a page then click a next button to dispaly they next 10
and so forth?

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



Re: [PHP] html form elements as php arrays

2004-05-07 Thread John Nichel
Matthew Oatham wrote:

Hi,

I am retrieving data from a database and displaying results on a html so
the user can edit them, I am sending the html form back to the server as an
array, i.e on my html for I might have 10 name fields so in the html code
all name fields are named name[] then I can iterate through the array on the
server. My problem isn't strictly php but more html / javascript. if I have
a load of form field elements all named name[] how do I access them to do
javascript validation? i.e document.form.name[].value doesn't work!
Cheers

Matt
Please wrap your lines.

document.form.elements['name[]'].value
>
>Matthew Oatham wrote:
> Mmmm that didn't work either!
>
> Thanks anyway
>
> Matt
Please reply to the list, and not just an individual person.

Anywho, if you want to address an element whose name contains special 
characters, the above way does work.

If these are check boxes, you have to loop thru them.  If these are 
text, you will have to loop thru all the elements on the page, and 
'look' for them. etc.

--
John C. Nichel
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] html form elements as php arrays

2004-05-06 Thread John Nichel
Matthew Oatham wrote:
Hi,
I am retrieving data from a database and displaying results on a html so the user can edit them, I am sending the html form back to the server as an array, i.e on my html for I might have 10 name fields so in the html code all name fields are named name[] then I can iterate through the array on the server. My problem isn't strictly php but more html / javascript. if I have a load of form field elements all named name[] how do I access them to do javascript validation? i.e document.form.name[].value doesn't work! 

Cheers
Matt
Please wrap your lines.
document.form.elements['name[]'].value
--
John C. Nichel
KegWorks.com
716.856.9675
[EMAIL PROTECTED]
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] html form elements as php arrays

2004-05-06 Thread Matthew Oatham
Hi,

I am retrieving data from a database and displaying results on a html so the user can 
edit them, I am sending the html form back to the server as an array, i.e on my html 
for I might have 10 name fields so in the html code all name fields are named name[] 
then I can iterate through the array on the server. My problem isn't strictly php but 
more html / javascript. if I have a load of form field elements all named name[] how 
do I access them to do javascript validation? i.e document.form.name[].value doesn't 
work! 

Cheers

Matt

[PHP] Arrays & Keys?

2004-03-24 Thread John Taylor-Johnston
Am I doing this right? Is there a better way? Am I doing this key thing right?

I'm doing the language thing. I have no extra plugins or rpms to help do this
properly. So I need advice. Is this going to work? I'm trying to make sense of
http://www.php.net/manual/en/language.types.array.php

$date = getdate(mktime(0,0,0,$month_now,1,$year_now));
$month_name = $date["month"];

$month_array = array("January" => "Janvier",
"February" => "Février",
"March" => "Mars",
"April" => "Avril",
etc ...
);
-snip-

Therefore:

-snip-

if ($lang == "french")
{
echo $month_array[$month_name]; // Should echo the current month: "Mars"?
}else{
echo "$month_name";
}

Am I doing this right? Is there a better way? Am I doing this key thing right?

Still trying to learn :)

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



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Jason Davidson
Im fully aware of diffrent ways of doing it, my question is, in the 2
ways i mentioned, which is more efficient.  Ill take the question to
the internals list. Thanks for your responses.

Jason





"Chris W. Parker" <[EMAIL PROTECTED]> wrote:
> 
> Luis Mirabal 
> on Wednesday, March 10, 2004 12:30 PM said:
> 
> > i would do it this way
> > 
> > function MyClass()
> > {
> > $this->myArray = range(0, 99);
> > }
> 
> guys (luis), guys (mike), let's not try to one-up each other...
> 
> ...
> 
> ...
> 
> but i would take it a step further. :P
> 
> function MyClass($limit = 100)
> {
>   $this->myArray = range(0, $limit-1);
> }
> 
> 
> 
> c.
> 
> --
> 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] arrays, loops, vars and props

2004-03-10 Thread Chris W. Parker
Luis Mirabal 
on Wednesday, March 10, 2004 12:30 PM said:

> i would do it this way
> 
> function MyClass()
> {
> $this->myArray = range(0, 99);
> }

guys (luis), guys (mike), let's not try to one-up each other...

...

...

but i would take it a step further. :P

function MyClass($limit = 100)
{
$this->myArray = range(0, $limit-1);
}



c.

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



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Michal Migurski
>here's how i would do it (coding styles aside):
>
>function MyClass()
>{
>$limit = 100;
>
>$i = -1;
>while(++$i < $limit)
>{
>$this->myArray[] = $i;
>}
>}

Don't forget poor old range:

$this->myArray = range(0, 99);

-
michal migurski- contact info and pgp key:
sf/cahttp://mike.teczno.com/contact.html

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



Re: [PHP] arrays, loops, vars and props

2004-03-10 Thread Luis Mirabal
i would do it this way

function MyClass()
{
$this->myArray = range(0, 99);
}

luis.


"Chris W. Parker" <[EMAIL PROTECTED]> escribió en el mensaje
news:[EMAIL PROTECTED]
Jason Davidson 
on Wednesday, March 10, 2004 12:25 AM said:

> would the following example be faster or slower had i simply done
> $this->myArray[$i] = $i;
>
> class MyClass {
> var $myArray = array();
>
> function MyClass() {
> $myTempArray = array();
> for($i=0;$i<100;$i++)
> $myTempArray[$i] = $i;
> $this->myArray = $myTempArray;
>}
> }

here's how i would do it (coding styles aside):

function MyClass()
{
$limit = 100;

$i = -1;
while(++$i < $limit)
{
$this->myArray[] = $i;
}
}



chris.

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



RE: [PHP] arrays, loops, vars and props

2004-03-10 Thread Chris W. Parker
Jason Davidson 
on Wednesday, March 10, 2004 12:25 AM said:

> would the following example be faster or slower had i simply done
> $this->myArray[$i] = $i;
>
> class MyClass {
> var $myArray = array();
> 
> function MyClass() {
> $myTempArray = array();
> for($i=0;$i<100;$i++)
> $myTempArray[$i] = $i;
> $this->myArray = $myTempArray;
>}
> }

here's how i would do it (coding styles aside):

function MyClass()
{
$limit = 100;

$i = -1;
while(++$i < $limit)
{
$this->myArray[] = $i;
}
}



chris.

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



[PHP] arrays, loops, vars and props

2004-03-10 Thread Jason Davidson
Hey, would anyone know offhand, if its faster to create a temp array,
fill it via loop, and then set a class property to that array, or to
simply fill the class property via loop.. 

to clearify. 

would the following example be faster or slower had i simply done
$this->myArray[$i] = $i;

class MyClass {
var $myArray = array();

function MyClass() {
$myTempArray = array();
for($i=0;$i<100;$i++)
$myTempArray[$i] = $i;
$this->myArray = $myTempArray;
   }
}

just curious...
Jason

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



Re: [PHP] arrays and sessions

2004-02-27 Thread Justin Patrin
First of all, make sure you're doing session_start() before 
reading/writing any session data and before you do any output.

Second, You likely need to just do something like this:

session_start();
if(post data) {
  $_SESSION['formArray'][] = $_POST;
}
This will save each POST array as-is in the session.

Chris W. Parker wrote:

Kermit Short 
on Friday, February 27, 2004 2:10 PM said:

I've got some code and it simply isn't working.  I thought it might be
because each time the form submits data, the array I'm storing
information in is being re-initialized.  If this is the case, I don't
have the multidimensional array I'm trying to get, but just a vector
array with the most recent submission data.


here are some thoughts...

sounds like you're just not keeping track of each iteration. i mean,
within the session variable you need to somehow differentiate between
each subsequent form submittal.


  $iteration = ++$_POST['iteration'];

  $_SESSION['post_data'][$iteration] = $_POST;

  // include $iteration in the post data
  // so that next time it comes around
  // it can be incremented.
  echo <<

 ...
 
 ...

?>

you should then see a multi-dimensional array with
'print_r($_SESSION);'.
this code is untested and not very complete. ;) but maybe it will give
you some ideas?
hth,
chris.


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


RE: [PHP] arrays and sessions

2004-02-27 Thread Chris W. Parker
Kermit Short 
on Friday, February 27, 2004 2:10 PM said:

> I've got some code and it simply isn't working.  I thought it might be
> because each time the form submits data, the array I'm storing
> information in is being re-initialized.  If this is the case, I don't
> have the multidimensional array I'm trying to get, but just a vector
> array with the most recent submission data.

here are some thoughts...

sounds like you're just not keeping track of each iteration. i mean,
within the session variable you need to somehow differentiate between
each subsequent form submittal.


 ...
 
 ...


?>

you should then see a multi-dimensional array with
'print_r($_SESSION);'.

this code is untested and not very complete. ;) but maybe it will give
you some ideas?


hth,
chris.

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



Re: [PHP] arrays and sessions

2004-02-27 Thread Kermit Short
I've got some code and it simply isn't working.  I thought it might be
because each time the form submits data, the array I'm storing information
in is being re-initialized.  If this is the case, I don't have the
multidimensional array I'm trying to get, but just a vector array with the
most recent submission data.  I tried making the array a session variable,
but I'm not even sure the session part of it is working.  So, if you have
any methods that you think might work better than what I'm trying to do, I'd
love to hear about it.  Basically, my file is structured like this:

1. Pull in POST data, and store them in php variables
2. If the POST data is null, display the first form and get the table name,
field name, field type, primary key, and null allowed information.  On
submit, the information is stored in an array.
3. If the POST data is not null, again display the entry form in case the
user needs to add more fields, and step through the array to display the
existing table info that the user has already entered.  A button in a second
form is also displayed.  When clicked, it actually creates the table.

My problems are that when I try to step through the array and display its
current contents, I get index not defined errors on my for loop indices
(?!).  The second problem is, when I try to use the print_r function to
display my array, it only displays one set of data.  This might be because
I'm trying to do a C++ type 2 dimensional array concept when PHP arrays are
associative by nature, and I'm not sure how to get around this.
Suggestions?

(Yes, Kermit is my real name.  Miss Piggy is well, and sends her regards.)

-Kermit

"Chris W. Parker" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
Kermit Short <mailto:[EMAIL PROTECTED]>
on Friday, February 27, 2004 1:47 PM said:

> A second form will contain an action that
> sends the sql code for creating the table to the database server, and
> viola, I've got myself a new table.

i prefer the violin, but viola's are cool too. ;)

> If anyone has any
> suggestions on how I can get this done I'd appreciate it!

wait.. i don't understand. you're asking us for a method to accomplish
what you describe or are you looking for help with a problem you're
having?? if the former, your method *sounds* ok to me. if the latter
please post the error you're getting.

> I'd really
> rather not post my whole code file, as it's really big and long, and
> emphasizes how novice I am at PHP.

good choice.


> Thanks in advance for your help!

no problem.


> -Kermit

is your real name Kermit?




chris.

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



RE: [PHP] arrays and sessions

2004-02-27 Thread Chris W. Parker
Kermit Short 
on Friday, February 27, 2004 1:47 PM said:

> A second form will contain an action that
> sends the sql code for creating the table to the database server, and
> viola, I've got myself a new table.

i prefer the violin, but viola's are cool too. ;)

> If anyone has any
> suggestions on how I can get this done I'd appreciate it!

wait.. i don't understand. you're asking us for a method to accomplish
what you describe or are you looking for help with a problem you're
having?? if the former, your method *sounds* ok to me. if the latter
please post the error you're getting.

> I'd really
> rather not post my whole code file, as it's really big and long, and
> emphasizes how novice I am at PHP.

good choice.


> Thanks in advance for your help!

no problem.


> -Kermit

is your real name Kermit?




chris.

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



[PHP] arrays and sessions

2004-02-27 Thread Kermit Short
Uh, sorry, I'm Kermit, not news.php.net


OK gurus, I'm trying to create a page that allows me to create a table in my
MSSQL database.  I'm accepting the field info one by one in a form using a
PHP_SELF action.  This information is supposed to be collected in an array
that's to be stored as a session variable for semi-permanance, until the
array contains all the fields and information for the table.  A second form
will contain an action that sends the sql code for creating the table to the
database server, and viola, I've got myself a new table.  Or not.  If anyone
has any suggestions on how I can get this done I'd appreciate it!  I'd
really rather not post my whole code file, as it's really big and long, and
emphasizes how novice I am at PHP.  Thanks in advance for your help!

-Kermit

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



[PHP] Arrays as session variables

2004-02-27 Thread news.php.net
OK gurus, I'm trying to create a page that allows me to create a table in my
MSSQL database.  I'm accepting the field info one by one in a form using a
PHP_SELF action.  This information is supposed to be collected in an array
that's to be stored as a session variable for semi-permanance, until the
array contains all the fields and information for the table.  A second form
will contain an action that sends the sql code for creating the table to the
database server, and viola, I've got myself a new table.  Or not.  If anyone
has any suggestions on how I can get this done I'd appreciate it!  I'd
really rather not post my whole code file, as it's really big and long, and
emphasizes how novice I am at PHP.  Thanks in advance for your help!

-Kermit

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



Re: [PHP] Arrays and performance

2003-11-18 Thread Kim Steinhaug
Thanks for your reply!

Im going to use this for a backup system for our webstore system,
where some of our customers have *alot* of products. Given the
structure of the database with categories and images 5000 unique
products quickly gives 3x = 15000 arrays. But again, how often
would the client need to revert the backup? Ive never needed to
do it for now, but I still want to do this backup system in XML
(Looks kinda up to date, :), and at the same time know that it will
eventually work -> even for the customers that infact has alot
of products in their system.

The alternative, would be that customers with >x products would only
have access to mySQL dump. Or to have a script that evaluates the
XML file and prompts the user that this file is to  large for automatic
import / revert.

a)
>From what I understand of your answer you're telling me that PHP
itself will not have any "problems" working with 1.000.000.000 arrays,
aslong as there are enough ram and processing power available, and
that the timeout is extended. Or would the PHP die a painfull death
as soon as it gets "to much" data?
Could we coclude the follwing, XMLfile > 200 MB = No PHP!

b)
I should do some benchmarking, to find the "magic" marker for how
much XML data that is "affordable" to grab when done on a webserver
with other clients to prevent angry customers or failures due to
factory timeout setting to 30 secs.

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---


"Raditha Dissanayake" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Hi,
>
> I belive PHP should be able to handle it but it's a bad idea. The reason
> being your app will not scale. Because if you script consumes 2mb of
> memory on average, 100 users accesing it at the same time will be 200Mb.
> Of course if you expect only a small number of users it does not matter.
>
> The biggest XML job i have handled with PHP is parsing the ODP RDF dump
> which is around 700MB. Obviously arrays are out of the question in such
> a scenario, even though only one user will be accessing the script at a
> given moment. the ODP dump has a couple of million records
>
>
>
> Kim Steinhaug wrote:
>
> >Something Ive wondered about as I started working with XML.
> >Importing huge XML files, and converting theese to arrays works
> >indeed very well. But I am wondering if there are any limits to
> >how many arrays the PHP can handle when performance is accounted for.
> >
> >Say I create an array from a XML with lots of childs, say we are
> >talking of upto 10 childs, which would give 10 dimensional arrays.
> >Say we then have 10.000 records, or even 100.000 records.
> >
> >Will this be a problem for PHP to handle, or should I break such
> >a prosess into lesser workloads (meaning lesser depth in the array)?
> >
> >Anyone with some experience on this?
> >
> >
> >
>
>
> -- 
> Raditha Dissanayake.
> 
> http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
> Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
> Graphical User Inteface. Just 150 KB | with progress bar.

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



Re: [PHP] Arrays and performance

2003-11-18 Thread Raditha Dissanayake
hi,

In fact i had to handle the ODP dump on two occaisions the first time 
the results went into a mysql db, the second time it went into a series 
of files.

On both occaisions i used SAX parsers. DOM would just roll over and die 
with this much of data. I placed code in the end element handler that 
would either save the data into a db or would save it to a file. In 
either case i only kept the data in memory for a short period. ie from 
the time the start element was detected through the character data 
handling until the end element was detected. (Obviously  i am not 
talking of the root node here :-))

During the whole process you barely noticed the memory usage, however 
the disk usage still went up of course. Reading from disk 1 and writing 
to disk 2 does wonders!

please let me know if you need any further clarifications.

Pablo Gosse wrote:

Raditha Dissanayake wrote:

[snip]The biggest XML job i have handled with PHP is parsing the ODP RDF
dump which is around 700MB. Obviously arrays are out of the question in
such a scenario, even though only one user will be accessing the script
At a given moment. the ODP dump has a couple of million records[/snip]
What was your solution for this, Raditha?  How did you handle the
parsing of such a large job?
Cheers,
Pablo
 



--
Raditha Dissanayake.

http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 150 KB | with progress bar.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


RE: [PHP] Arrays and performance

2003-11-18 Thread Pablo Gosse
Raditha Dissanayake wrote:

[snip]The biggest XML job i have handled with PHP is parsing the ODP RDF
dump which is around 700MB. Obviously arrays are out of the question in
such a scenario, even though only one user will be accessing the script
At a given moment. the ODP dump has a couple of million records[/snip]

What was your solution for this, Raditha?  How did you handle the
parsing of such a large job?

Cheers,
Pablo

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



Re: [PHP] Arrays and performance

2003-11-18 Thread Raditha Dissanayake
Hi,

I belive PHP should be able to handle it but it's a bad idea. The reason 
being your app will not scale. Because if you script consumes 2mb of 
memory on average, 100 users accesing it at the same time will be 200Mb. 
Of course if you expect only a small number of users it does not matter.

The biggest XML job i have handled with PHP is parsing the ODP RDF dump 
which is around 700MB. Obviously arrays are out of the question in such 
a scenario, even though only one user will be accessing the script at a 
given moment. the ODP dump has a couple of million records



Kim Steinhaug wrote:

Something Ive wondered about as I started working with XML.
Importing huge XML files, and converting theese to arrays works
indeed very well. But I am wondering if there are any limits to
how many arrays the PHP can handle when performance is accounted for.
Say I create an array from a XML with lots of childs, say we are
talking of upto 10 childs, which would give 10 dimensional arrays.
Say we then have 10.000 records, or even 100.000 records.
Will this be a problem for PHP to handle, or should I break such
a prosess into lesser workloads (meaning lesser depth in the array)?
Anyone with some experience on this?

 



--
Raditha Dissanayake.

http://www.radinks.com/sftp/ | http://www.raditha.com/megaupload
Lean and mean Secure FTP applet with | Mega Upload - PHP file uploader
Graphical User Inteface. Just 150 KB | with progress bar.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Arrays and performance

2003-11-18 Thread Kim Steinhaug
Something Ive wondered about as I started working with XML.
Importing huge XML files, and converting theese to arrays works
indeed very well. But I am wondering if there are any limits to
how many arrays the PHP can handle when performance is accounted for.

Say I create an array from a XML with lots of childs, say we are
talking of upto 10 childs, which would give 10 dimensional arrays.
Say we then have 10.000 records, or even 100.000 records.

Will this be a problem for PHP to handle, or should I break such
a prosess into lesser workloads (meaning lesser depth in the array)?

Anyone with some experience on this?

-- 
Kim Steinhaug
---
There are 10 types of people when it comes to binary numbers:
those who understand them, and those who don't.
---

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Eugene Lee 
on Tuesday, September 30, 2003 2:12 PM said:

> A heredoc is more readable:
> 
> echo <<  value="{$chkSessionF[$i]}">
> HTMLTAG;

Yeah, but I don't like those. :P


chris.

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



Re: [PHP] arrays and php

2003-09-30 Thread Eugene Lee
On Tue, Sep 30, 2003 at 09:10:44AM -0700, Chris W. Parker wrote:
: 
: Angelo Zanetti 
: on Tuesday, September 30, 2003 5:43 AM said:
: 
: > hi I have a table with rows and each row contains a checkbox ( array)
: > and a record. TD of the checkbox:
: > echo(" value=". $chkSessionF[$i] .">");
: 
: Firstly you should be putting double quotes around every value in your
: HTML tags.
: 
: Revised: (watch wrap)
: 
: echo "";

A heredoc is more readable:

echo <<
HTMLTAG;

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



Re: [PHP] arrays and php

2003-09-30 Thread Jason Wong
On Wednesday 01 October 2003 02:32, Chris W. Parker wrote:
> Jason Wong 
>
> on Tuesday, September 30, 2003 11:27 AM said:
>  echo "".print_r($chk)."";
> 
>  It will not work.
> >
> > Actually, the above *does* work!
>
> Not for me. (Although we may be testing different things.)

Sorry you're right, it doesn't work. I was testing with php-cli using:

  echo ("" . print_r($_SERVER) . "");

there was no parse error and I saw some output fly off the console, so I 
thought it had worked :)

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
You can't fall off the floor.
*/

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Chris Shiflett 
on Tuesday, September 30, 2003 11:39 AM said:

> The comma isn't concatenation; echo can take multiple arguments.

Oh ok, I get it.

> I've heard statements about passing multiple arguments to echo being
> faster than using concatenation, but every benchmark I've tried
> myself shows them to be nearly identical. Feel free to try it
> yourself and post your results. :-) I'd be curious to see if others
> reach the same conclusion. 

I tried this, and I think the comma was just slightly faster than the
period. But then again I didn't always get consistent results because I
was trying this out on a machine that is not very fast so the speed at
which is processes something varies quite a bit.

My conclusion was that it's not fast enough to bother changing all my
code, or start writing in a new way.


Although during some testing I did find that writing loops in the
following way is faster than normal.

$counter = -1;
while(++$counter < $amount)
{
// do stuff
}

It made a big enough difference on my slow machine to merit me writing
as many loops in this way as I can. (I think.)



Chris.

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



Re: [PHP] arrays and php

2003-09-30 Thread CPT John W. Holmes
From: "Chris W. Parker" <[EMAIL PROTECTED]>
> CPT John W. Holmes 
> on Tuesday, September 30, 2003 11:32 AM said:
>
> > Note that print_r() will (by default) return a 1 (TRUE) upon success,
> > so you end up with a "1" being printed at the end of your data.
>
> [snip]
>
> That answers it!

See... if you'd only have waited that extra second to press the Send button!
;)

---John Holmes...

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris Shiflett
--- "Chris W. Parker" <[EMAIL PROTECTED]> wrote:
> What's the difference between using , or . for concatenation? (I
> thought they were the same.)

The comma isn't concatenation; echo can take multiple arguments.

I've heard statements about passing multiple arguments to echo being faster
than using concatenation, but every benchmark I've tried myself shows them to
be nearly identical. Feel free to try it yourself and post your results. :-)
I'd be curious to see if others reach the same conclusion.

Chris

=
HTTP Developer's Handbook
 http://shiflett.org/books/http-developers-handbook
My Blog
 http://shiflett.org/

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
CPT John W. Holmes 
on Tuesday, September 30, 2003 11:32 AM said:

> Note that print_r() will (by default) return a 1 (TRUE) upon success,
> so you end up with a "1" being printed at the end of your data.

[snip]

That answers it!




c.

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Jason Wong 
on Tuesday, September 30, 2003 11:27 AM said:

 echo "".print_r($chk)."";
 
 It will not work.
> 
> Actually, the above *does* work!

Not for me. (Although we may be testing different things.)

".print_r($pageTitle)."";
?>

Gives me:

Checkout Step One1


If I use the , it's a little closer but still not correct (at least not
what I want). With , I get:

Checkout Step One1

Close but I don't know where the one is coming from. Maybe it's saying
it's 'true'?



Chris.

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



Re: [PHP] arrays and php

2003-09-30 Thread CPT John W. Holmes
From: "Jason Wong" <[EMAIL PROTECTED]>
> On Wednesday 01 October 2003 02:14, Chris W. Parker wrote:
> > Jason Wong 
> >
> > on Tuesday, September 30, 2003 11:06 AM said:
> > >> echo "".print_r($chk)."";
> > >>
> > >> It will not work.
> 
> Actually, the above *does* work!

It depends on how you define "works" :)

You'll end up with output like this:

Array
(
[0] => one
[1] => two
[2] => three
)
1

which "works" but is not what was desired. 

---John Holmes...

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



Re: [PHP] arrays and php

2003-09-30 Thread CPT John W. Holmes
From: "Chris W. Parker" <[EMAIL PROTECTED]>

>>> echo "".print_r($chk)."";
>>>
>>> It will not work.
>>
>> You can do this though:
>>
>>   echo "", print_r($chk), "";
>
>Well heck, that makes things easier!
>
>What's the difference between using , or . for concatenation? (I thought
>they were the same.)

Using a comma is just like using another echo command. So for the above,
you're effectively saying:

echo ""; echo print_r($chk); echo "";

Note that print_r() will (by default) return a 1 (TRUE) upon success, so you
end up with a "1" being printed at the end of your data.

You could also use this method:

echo "".print_r($chk,TRUE)."";

The TRUE causes the output of print_r() to be returned instead of printed
automatically. The benefit to this method is that you don't end up with the
"1" being printed.

---John Holmes...

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



Re: [PHP] arrays and php

2003-09-30 Thread Jason Wong
On Wednesday 01 October 2003 02:14, Chris W. Parker wrote:
> Jason Wong 
>
> on Tuesday, September 30, 2003 11:06 AM said:
> >> echo "".print_r($chk)."";
> >>
> >> It will not work.

Actually, the above *does* work!

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Test-tube babies shouldn't throw stones.
*/

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Jason Wong 
on Tuesday, September 30, 2003 11:06 AM said:

>> echo "".print_r($chk)."";
>> 
>> It will not work.
> 
> You can do this though:
> 
>   echo "", print_r($chk), "";

Well heck, that makes things easier!

What's the difference between using , or . for concatenation? (I thought
they were the same.)



Chris.

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



Re: [PHP] arrays and php

2003-09-30 Thread Jason Wong
On Wednesday 01 October 2003 00:10, Chris W. Parker wrote:

[snip]

> If you're not sure what a value is use print_r() to determine it.
>
> echo "";
> print_r($chk);
> echo "";
>
> Quick side note on the above code:
>
> You cannot write it like:
>
> echo "".print_r($chk)."";
>
> It will not work.

You can do this though:

  echo "", print_r($chk), "";

Or if using a recent version of php:

  echo nl2br(print_r($var, 1)); //or something like that

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
No bird soars too high if he soars with his own wings.
-- William Blake
*/

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



RE: [PHP] arrays and php

2003-09-30 Thread Chris W. Parker
Angelo Zanetti 
on Tuesday, September 30, 2003 5:43 AM said:

> hi I have a table with rows and each row contains a checkbox ( array)
> and a record. TD of the checkbox:
> echo(" value=". $chkSessionF[$i] .">");

Firstly you should be putting double quotes around every value in your
HTML tags.

Revised: (watch wrap)

echo "";

I also changed

". $chkSessionF[$i] ."

into

{$chkSessionF[$i]}

.

You can do it either way. I prefer the latter.

If you're not sure what a value is use print_r() to determine it.

echo "";
print_r($chk);
echo "";

Quick side note on the above code:

You cannot write it like:

echo "".print_r($chk)."";

It will not work.

> can anyone help. this is very strange.

I think your problem may just be the quotes around the values in the
HTML. Give it a shot.



hth,
chris.

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



[PHP] arrays and php

2003-09-30 Thread Angelo Zanetti
hi I have a table with rows and each row contains a checkbox ( array) and a
record. TD of the checkbox:
echo("");

as you can see the array of checkboxes is called chkR.

When the user clicks a submit button it calls the same
page and the value of the array is received using: $chkR=$_POST['chkR'];
however this variable is doing something weird because if I immediately do:
echo("chk: is array: " . is_array ($chk)); it doesnt display anything, so I
presume it isnt an array, supporting this is also the fact that I try to use
the $chkR in:

$indReqF = array_diff ($indReq, $chkR)

and everytime i run this statement php tells me that the 2nd argument isnt
an array. What is the reason for $chkR not being an array? I have used the
same code on a different page but instead of it posting to the same page
(like in this example) it posts to another page and works fine !?!?!?!?

can anyone help. this is very strange.
thanx in advance.

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



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread Evan Nemerson
/* UNTESTED - and prolly could be more efficient */
$c = $d = '';
natsort($info);
foreach ( $info as $i ) {
$d = substr($i, 0, 1);
if ( $d != $c )
echo "\n";
echo $i;
$c = $d;
}


On Tuesday 22 July 2003 09:40 am, Don Mc Nair wrote:
> Hi folks
>
> I am trying to print out a table of elements in alphabetical order. I have
> an SQL query which sorts out the data in order and am using 'while ($info
> =(mysql_fetch_row...etc)) to read the data array. I need it to echo out a
> table with all the A's first, then a blank line, then all the B's, a blank
> line and so on. I could write 26 different queries, one for each letter of
> the alphabet, but surely there is a tidier way.
>
> Any help is appreciated.
>
> Don
>
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003

-- 
"He who fights too long against dragons becomes a dragon himself; and if you 
gaze too long into the abyss, the abyss will gaze into you."

-Nietzche


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



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread Liam Gibbs
<>

Do a query, sorting by the field you need alphabetized. Then do this (and
tidy it up as you need):

echo "";
while($result = mysql_fetch_row$(query)) {
   if(substr($result, 0, 1) != $previousfirstletter) {
  $previousfirstletter = substr($result, 0, 1);
  echo "$previousfirstletter";
   }
   echo "$result";
}

echo "";

It's untested, but I believe it will work.


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



Re: [PHP] Arrays and Alphabetical order

2003-07-22 Thread David Nicholson
Hello,

This is a reply to an e-mail that you wrote on Tue, 22 Jul 2003 at
17:40, lines prefixed by '>' were originally written by you.
> I need it to echo
> out a
> table with all the A's first, then a blank line, then all the B's,
a
> blank
> line and so on. I could write 26 different queries, one for each
> letter of
> the alphabet, but surely there is a tidier way.

How about:
for($i="a";$i<="z";$i++){
echo "Items beginning with the letter $i";
$arrayposition = 0;
while(strtolower(substr($data[$arrayposition],0,1))==$i){
echo $data[$arrayposition] . "";
$arrayposition++;
}
}

--
phpmachine :: The quick and easy to use service providing you with
professionally developed PHP scripts :: http://www.phpmachine.com/

  Professional Web Development by David Nicholson
http://www.djnicholson.com/

QuizSender.com - How well do your friends actually know you?
 http://www.quizsender.com/
(developed entirely in PHP)

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



[PHP] Arrays and Alphabetical order

2003-07-22 Thread Don Mc Nair
Hi folks

I am trying to print out a table of elements in alphabetical order. I have
an SQL query which sorts out the data in order and am using 'while ($info
=(mysql_fetch_row...etc)) to read the data array. I need it to echo out a
table with all the A's first, then a blank line, then all the B's, a blank
line and so on. I could write 26 different queries, one for each letter of
the alphabet, but surely there is a tidier way.

Any help is appreciated.

Don


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.502 / Virus Database: 300 - Release Date: 18/07/2003



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



RE: [PHP] php arrays into flash

2003-07-07 Thread Ralph
Here is a site you might want to look at:

http://polar-lights.com/en/


-Original Message-
From: Jim McNeely [mailto:[EMAIL PROTECTED] 
Sent: Monday, July 07, 2003 4:29 PM
To: [EMAIL PROTECTED]
Subject: [PHP] php arrays into flash

I know a lot more about php than about flash (which is probably sad) 
but does anyone know how to take info in an array and pass it into an 
array in flash? I think they have arrays, but the only thing I can seem 
to find in flash to get info from php is the loadvariable actionscript 
step. I looked around via google and I couldn't find anything within a 
reasonable time that seemed to answer this question.

TIA

Jim McNeely
Envision Data
[EMAIL PROTECTED]
http://www.envisiondata.com


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




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



Re: [PHP] php arrays into flash

2003-07-07 Thread Pascal Polleunus
Jim McNeely wrote:
I know a lot more about php than about flash (which is probably sad) but 
does anyone know how to take info in an array and pass it into an array 
in flash? I think they have arrays, but the only thing I can seem to 
find in flash to get info from php is the loadvariable actionscript 
step. I looked around via google and I couldn't find anything within a 
reasonable time that seemed to answer this question.
You can do it via XML, or you could use serialize in PHP and write an
unserialize function in ActionScript.
Macromedia Flash MX Documentation:
http://www.macromedia.com/support/flash/documentation.html
TIA

Jim McNeely
Envision Data
[EMAIL PROTECTED]
http://www.envisiondata.com







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


Re: [PHP] php arrays into flash

2003-07-07 Thread Miles Thompson
Jim,

The key words are "implode" on the PHP side and "split" on the Flash side. 
Here's an example:

The data is returned from PHP like so, after doing the connect, select, 
etc. to produce an array of 7 dates for back issues ... no claim that this 
is optimal code.

if( $result && mysql_num_rows( $result ) >= 1 )
{
while( $row = mysql_fetch_array( $result ) )
{
 $arrdates[] = $row[ dtStory ];
}
$issuedates = implode( ",", $arrdates );
 } 

echo "issuedates=".$issuedates;

and in Flash, as part of the LoadVars  varGetDates.onLoad = function( 
success) callback is handled like so ...

_root.arrIssueDates = issuedates.split( "," );
_root.dtDate = _root.arrIssueDates[0];
for (i=0; i < arrIssueDates.length; i++)
{
   //load  combo-display and data same in this case
   cboIssueDates.addItem(arrIssueDates[i],arrIssueDates[i]);
}
At 06:29 PM 7/7/2003 -0500, Jim McNeely wrote:
I know a lot more about php than about flash (which is probably sad) but 
does anyone know how to take info in an array and pass it into an array in 
flash? I think they have arrays, but the only thing I can seem to find in 
flash to get info from php is the loadvariable actionscript step. I looked 
around via google and I couldn't find anything within a reasonable time 
that seemed to answer this question.

TIA

Jim McNeely
Envision Data
[EMAIL PROTECTED]
http://www.envisiondata.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


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


Re: [PHP] php arrays into flash

2003-07-07 Thread Jim Lucas
don't know about loading it directly in flash, but you could always create a
javascript array in the page that loads the flash module and then have flash
read it or javascript enter it into the flash module.

Jim lucas
- Original Message -
From: "Jim McNeely" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, July 07, 2003 4:29 PM
Subject: [PHP] php arrays into flash


> I know a lot more about php than about flash (which is probably sad)
> but does anyone know how to take info in an array and pass it into an
> array in flash? I think they have arrays, but the only thing I can seem
> to find in flash to get info from php is the loadvariable actionscript
> step. I looked around via google and I couldn't find anything within a
> reasonable time that seemed to answer this question.
>
> TIA
>
> Jim McNeely
> Envision Data
> [EMAIL PROTECTED]
> http://www.envisiondata.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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



[PHP] php arrays into flash

2003-07-07 Thread Jim McNeely
I know a lot more about php than about flash (which is probably sad) 
but does anyone know how to take info in an array and pass it into an 
array in flash? I think they have arrays, but the only thing I can seem 
to find in flash to get info from php is the loadvariable actionscript 
step. I looked around via google and I couldn't find anything within a 
reasonable time that seemed to answer this question.

TIA

Jim McNeely
Envision Data
[EMAIL PROTECTED]
http://www.envisiondata.com
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] Arrays

2003-03-16 Thread John Taylor-Johnston
Thanks!

"John W. Holmes" wrote:

> > $var = array (
> > 'AN' => array (
> >   'Description' => 'Accession Number: (AN)',
> >   'ReferenceURL' => 'AN__Accession_Number.jsp',
> >   ),
> >  'AU' => array (
> >   'Description' => 'Author(s): (AU)',
> >   'ReferenceURL' => 'AU__Author(s).jsp',
> >   )
> > )
> >
> > What I want to get is the keys 'AN' and 'AU' as values.
> >
> > while (??){
> > echo "This key is $var[??]";
> > }
> >
> > This key is AN
> > This key is AU
>
> foreach($var as $key => $value)
> { echo "The key is $key"; }
>
> ---John W. Holmes...
>
> PHP Architect - A monthly magazine for PHP Professionals. Get your copy
> today. http://www.phparch.com/

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

  ' ' '   Collège de Sherbrooke:
 ô¿ô   http://www.collegesherbrooke.qc.ca/languesmodernes/
   - Université de Sherbrooke:
  http://compcanlit.ca/
  819-569-2064



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



RE: [PHP] Arrays

2003-03-16 Thread John W. Holmes
> $var = array (
> 'AN' => array (
>   'Description' => 'Accession Number: (AN)',
>   'ReferenceURL' => 'AN__Accession_Number.jsp',
>   ),
>  'AU' => array (
>   'Description' => 'Author(s): (AU)',
>   'ReferenceURL' => 'AU__Author(s).jsp',
>   )
> )
> 
> What I want to get is the keys 'AN' and 'AU' as values.
> 
> while (??){
> echo "This key is $var[??]";
> }
> 
> This key is AN
> This key is AU

foreach($var as $key => $value)
{ echo "The key is $key"; }

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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



[PHP] Arrays

2003-03-16 Thread John Taylor-Johnston
I thought I understood this example: http://www.php.net/manual/en/ref.array.php

 array(
'first' => 'Caleb',
'last' => 'Maclennan'
)
);
echo "My first name is {$var['name']['first']}!";
?>

I can do that. But, my array looks more like:

$var = array (
'AN' => array (
  'Description' => 'Accession Number: (AN)',
  'ReferenceURL' => 'AN__Accession_Number.jsp',
  ),
 'AU' => array (
  'Description' => 'Author(s): (AU)',
  'ReferenceURL' => 'AU__Author(s).jsp',
  )
)

What I want to get is the keys 'AN' and 'AU' as values.

while (??){
echo "This key is $var[??]";
}

This key is AN
This key is AU

How :) ?

Still learning :)
John



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



RE: [PHP] MySQL and PHP arrays

2003-03-10 Thread Van Andel, Robbert
mysql_fetch_array($result) works too.  It fetches the data from the current row and is 
used in conjunction with a while loop:

while($array=mysql_fetch_array($result))
{
//stuff to do with the current array
}



Robbert van Andel 



-Original Message-
From: Mike Mannakee [mailto:[EMAIL PROTECTED]
Sent: Monday, March 10, 2003 8:45 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] MySQL and PHP arrays


You get at the data through $array = mysql_result($result,0,0);

Mike


"{R}Ichard Ashton" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote:
>
> >On Monday 10 March 2003 22:30, {R}ichard Ashton wrote:
> >> Is there a generally recommended way of storing an array created by PHP
> >> in a MySQL database field ?
> >
> >serialize() and unserialize().
> >
> >> What type of field should it be, and how do you get the whole array
> >> back in one go without reconstructing it row by row, if that is
> >> possible?
> >
> >Any text field will do, just make sure it's large enough for your data.
>
> Thanks that now makes much more sense. So when I look at the data in
> the database I see
> a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for
> the 142 elements of the array.
>
> But getting it out is not so easy.
>
> $result = mysql_query( " select post from posts where id = '$id' ")
>
> Gives $result as a Resource id #6 which is OK but I cant find the PHP
> MySQL command to get the whole field back to unserialize it :(
>
> {R}
>
>
>
> >--
> >Jason Wong -> Gremlins Associates -> www.gremlins.biz
> >Open Source Software Systems Integrators
> >* Web Design & Hosting * Internet & Intranet Applications Development *
> >--
> >Search the list archives before you post
> >http://marc.theaimsgroup.com/?l=php-general
> >--
> >/*
> >QOTD:
> > I'm not bald -- I'm "hair challenged".
> >
> > [I thought that was "differently haired". Ed.]
> >*/
> >
> >
> >--
> >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] MySQL and PHP arrays

2003-03-10 Thread Mike Mannakee
You get at the data through $array = mysql_result($result,0,0);

Mike


"{R}Ichard Ashton" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote:
>
> >On Monday 10 March 2003 22:30, {R}ichard Ashton wrote:
> >> Is there a generally recommended way of storing an array created by PHP
> >> in a MySQL database field ?
> >
> >serialize() and unserialize().
> >
> >> What type of field should it be, and how do you get the whole array
> >> back in one go without reconstructing it row by row, if that is
> >> possible?
> >
> >Any text field will do, just make sure it's large enough for your data.
>
> Thanks that now makes much more sense. So when I look at the data in
> the database I see
> a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for
> the 142 elements of the array.
>
> But getting it out is not so easy.
>
> $result = mysql_query( " select post from posts where id = '$id' ")
>
> Gives $result as a Resource id #6 which is OK but I cant find the PHP
> MySQL command to get the whole field back to unserialize it :(
>
> {R}
>
>
>
> >--
> >Jason Wong -> Gremlins Associates -> www.gremlins.biz
> >Open Source Software Systems Integrators
> >* Web Design & Hosting * Internet & Intranet Applications Development *
> >--
> >Search the list archives before you post
> >http://marc.theaimsgroup.com/?l=php-general
> >--
> >/*
> >QOTD:
> > I'm not bald -- I'm "hair challenged".
> >
> > [I thought that was "differently haired". Ed.]
> >*/
> >
> >
> >--
> >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] MySQL and PHP arrays

2003-03-10 Thread {R}ichard Ashton
On Mon, 10 Mar 2003 22:34:44 +0800, Jason Wong wrote:

>On Monday 10 March 2003 22:30, {R}ichard Ashton wrote:
>> Is there a generally recommended way of storing an array created by PHP
>> in a MySQL database field ?
>
>serialize() and unserialize().
>
>> What type of field should it be, and how do you get the whole array
>> back in one go without reconstructing it row by row, if that is
>> possible?
>
>Any text field will do, just make sure it's large enough for your data.

Thanks that now makes much more sense. So when I look at the data in
the database I see
a:142:{i:1;s:52:[52characters];i:2;s:37:[37characters] and so on for
the 142 elements of the array.

But getting it out is not so easy.

$result = mysql_query( " select post from posts where id = '$id' ")

Gives $result as a Resource id #6 which is OK but I cant find the PHP
MySQL command to get the whole field back to unserialize it :(

{R}



>-- 
>Jason Wong -> Gremlins Associates -> www.gremlins.biz
>Open Source Software Systems Integrators
>* Web Design & Hosting * Internet & Intranet Applications Development *
>--
>Search the list archives before you post
>http://marc.theaimsgroup.com/?l=php-general
>--
>/*
>QOTD:
>   I'm not bald -- I'm "hair challenged".
>
>   [I thought that was "differently haired". Ed.]
>*/
>
>
>-- 
>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] MySQL and PHP arrays

2003-03-10 Thread Messay W Asfaw
Serializing it would be the best way: seralize($myArray) 
then you can get the array back using unseralize($serializedarray)

-Original Message-
From: {R}ichard Ashton [mailto:[EMAIL PROTECTED]
Sent: 10 March 2003 14:31
To: [EMAIL PROTECTED]
Subject: [PHP] MySQL and PHP arrays



Is there a generally recommended way of storing an array created by PHP
in a MySQL database field ?

What type of field should it be, and how do you get the whole array 
back in one go without reconstructing it row by row, if that is
possible?

{R} 


-- 
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] MySQL and PHP arrays

2003-03-10 Thread Jason Wong
On Monday 10 March 2003 22:30, {R}ichard Ashton wrote:
> Is there a generally recommended way of storing an array created by PHP
> in a MySQL database field ?

serialize() and unserialize().

> What type of field should it be, and how do you get the whole array
> back in one go without reconstructing it row by row, if that is
> possible?

Any text field will do, just make sure it's large enough for your data.

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
QOTD:
I'm not bald -- I'm "hair challenged".

[I thought that was "differently haired". Ed.]
*/


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



[PHP] MySQL and PHP arrays

2003-03-10 Thread {R}ichard Ashton

Is there a generally recommended way of storing an array created by PHP
in a MySQL database field ?

What type of field should it be, and how do you get the whole array 
back in one go without reconstructing it row by row, if that is
possible?

{R} 


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



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
> You can use array_sum().

I have used that in the past, but only on single arrays, I can't figure out
how to do on multi-level arrays, and since I need to have different totals
from different levels of the array, I don't think this will work. If you can
shed some light on this it would be appreciated.

>From below - $totals[0][4] through $totals[19][4] , $totals[0][5] through
$totals[19][5], etc.


- Original Message -
From: "Jason Wong" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, March 02, 2003 4:53 PM
Subject: Re: [PHP] Arrays and MySQL


> On Sunday 02 March 2003 23:34, Beauford.2002 wrote:
> > Hi,
> >
> > I have an array which I am trying to total but having some problems. Any
> > help is appreciated.
> >
> > Example:  This is a hockey team and there are 20 players - I am
selecting
> > the goals, assists, and points from each player and then want to have a
> > grand total of all goals, assists, and points.
> >
> > $query = "select goals, assists, points from roster";
> >
> > while ($line = mysql_fetch_row($result)) {
> >
> > $totals[] = $line;
> >
> > }
> >
> > I want to total $totals[0][4] through $totals[19][4], $totals[0][5]
through
> > $totals[19][5], etc. for each stat. I thought of putting them in a for
loop
> > and just adding them, but this seemed kind of messy and the long way
around
>
> You can use array_sum().
>
> --
> Jason Wong -> Gremlins Associates -> www.gremlins.biz
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> --
> Search the list archives before you post
> http://marc.theaimsgroup.com/?l=php-general
> --
> /*
> Man's unique agony as a species consists in his perpetual conflict between
> the desire to stand out and the need to blend in.
> -- Sydney J. Harris
> */
>
>
> --
> 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] Arrays and MySQL

2003-03-02 Thread Leo Spalteholz
On March 2, 2003 01:53 pm, Jason Wong wrote:
> On Sunday 02 March 2003 23:34, Beauford.2002 wrote:
> > Hi,
> >
> > I have an array which I am trying to total but having some
> > problems. Any help is appreciated.
> >
> > Example:  This is a hockey team and there are 20 players - I am
> > selecting the goals, assists, and points from each player and
> > then want to have a grand total of all goals, assists, and
> > points.
> >
> > $query = "select goals, assists, points from roster";
> >
> > while ($line = mysql_fetch_row($result)) {
> >
> > $totals[] = $line;
> >
> > }
> >
> > I want to total $totals[0][4] through $totals[19][4],
> > $totals[0][5] through $totals[19][5], etc. for each stat. I
> > thought of putting them in a for loop and just adding them, but
> > this seemed kind of messy and the long way around
>
> You can use array_sum().

What about "SELECT SUM(Goals), SUM(assists)"?

Leo

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



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Jason Wong
On Sunday 02 March 2003 23:34, Beauford.2002 wrote:
> Hi,
>
> I have an array which I am trying to total but having some problems. Any
> help is appreciated.
>
> Example:  This is a hockey team and there are 20 players - I am selecting
> the goals, assists, and points from each player and then want to have a
> grand total of all goals, assists, and points.
>
> $query = "select goals, assists, points from roster";
>
> while ($line = mysql_fetch_row($result)) {
>
> $totals[] = $line;
>
> }
>
> I want to total $totals[0][4] through $totals[19][4], $totals[0][5] through
> $totals[19][5], etc. for each stat. I thought of putting them in a for loop
> and just adding them, but this seemed kind of messy and the long way around

You can use array_sum().

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Man's unique agony as a species consists in his perpetual conflict between
the desire to stand out and the need to blend in.
-- Sydney J. Harris
*/


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



Re: [PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
It gets a little more complicated than this. There are several teams (each
with 20 players) and then there is the team owner and then there is the
player position, etc.  So to do this I would have to do some kind of a join
and so on - and to date haven't been able to figure this out with sums. I
would also have to do a second query (I am already doing one to get the
points for each player), so I might as well just use it and through the
results in an array and then total it from there - and thus my question of
how I total the array


- Original Message -
From: "Marek Kilimajer" <[EMAIL PROTECTED]>
To: "Beauford.2002" <[EMAIL PROTECTED]>
Cc: "PHP General" <[EMAIL PROTECTED]>
Sent: Sunday, March 02, 2003 11:10 AM
Subject: Re: [PHP] Arrays and MySQL


> Cannot you just make MaSQL count it?
>
> $query = "select sum(goals), sum(assists), sum(points) from roster";
>
>
>
>
> Beauford.2002 wrote:
>
> >Hi,
> >
> >I have an array which I am trying to total but having some problems. Any
> >help is appreciated.
> >
> >Example:  This is a hockey team and there are 20 players - I am selecting
> >the goals, assists, and points from each player and then want to have a
> >grand total of all goals, assists, and points.
> >
> >$query = "select goals, assists, points from roster";
> >
> >while ($line = mysql_fetch_row($result)) {
> >
> >$totals[] = $line;
> >
> >}
> >
> >I want to total $totals[0][4] through $totals[19][4], $totals[0][5]
through
> >$totals[19][5], etc. for each stat. I thought of putting them in a for
loop
> >and just adding them, but this seemed kind of messy and the long way
around
> >
> >Thanks
> >
> >
> >
> >
> >
> >
>
>
> --
> 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] Arrays and MySQL

2003-03-02 Thread Marek Kilimajer
Cannot you just make MaSQL count it?

$query = "select sum(goals), sum(assists), sum(points) from roster";



Beauford.2002 wrote:

Hi,

I have an array which I am trying to total but having some problems. Any
help is appreciated.
Example:  This is a hockey team and there are 20 players - I am selecting
the goals, assists, and points from each player and then want to have a
grand total of all goals, assists, and points.
$query = "select goals, assists, points from roster";

while ($line = mysql_fetch_row($result)) {

$totals[] = $line;

}

I want to total $totals[0][4] through $totals[19][4], $totals[0][5] through
$totals[19][5], etc. for each stat. I thought of putting them in a for loop
and just adding them, but this seemed kind of messy and the long way around
Thanks



 



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


[PHP] Arrays and MySQL

2003-03-02 Thread Beauford.2002
Hi,

I have an array which I am trying to total but having some problems. Any
help is appreciated.

Example:  This is a hockey team and there are 20 players - I am selecting
the goals, assists, and points from each player and then want to have a
grand total of all goals, assists, and points.

$query = "select goals, assists, points from roster";

while ($line = mysql_fetch_row($result)) {

$totals[] = $line;

}

I want to total $totals[0][4] through $totals[19][4], $totals[0][5] through
$totals[19][5], etc. for each stat. I thought of putting them in a for loop
and just adding them, but this seemed kind of messy and the long way around

Thanks




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



[PHP] arrays;session variable; empty variable

2003-02-03 Thread André Rosendaal
Hi,

I have spend several hours on the following issue, and I can't figure out
what I am doing wrong.

Consider the next function:

function CreateFileForRealPlayer () {
  global $playlist;

  $filename = $playlist[0]['url'];
  header("Content-Type: audio/x-pn-realaudio;");
  echo ($filename);
  }

This is a simplified version of the actual function: here, the function
should get a url from a session variable ($playlist), and create a Real file
on-the-fly that references to this file.

The function works in Netscape (both cookies enabled and disabled), and in
IE with cookies disabled, but not in IE when cookies are enabled. For some
reason, in that configuration the value assigned to $filename is an empty
string when it is echoed. However, it DOES have the proper value after the
line

$filename = $playlist[0]['url'];

I am certain there is nothing wrong with the session variable itself (as
said, it works in the configurations I mention above; it's the value of
$filename that behaves strangely in IE. Any ideas? I am using php 4.0.4pl1
on HP-UX, IE 6.0, Win XP client side.

TIA
André Rosendaal



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




Re: [PHP] Arrays of strings from regex

2002-12-31 Thread Marek Kilimajer


David Pratt wrote:


Am working through document to collect pieces that match and then insert 
them into an array so they can be used to construct another file.

Looking in my doc for lines like this:

{\*\cs43 \additive \sbasedon10 db_edition;}
{\*\cs44 \additive \sbasedon10 db_editor;}
{\*\cs45 \additive \sbasedon10 db_email;}

Wrote this regex to find them:

^\{\\\*\\?(cs[0-9]{1,3}) (.*)\\[a-z0-9]+ (.*);\}$
 

^

I suppose this wants to eat the whole line, use ([^ ]*) - all except space,
or switch to perl expressions with its ungreedy match


Now looking for best method for getting the parts in parenthesis () into an
array so it will contain these values by finding the above three lines:

$matches [0][0][0] = cs43 , \additive \sbasedon10, db_edition
$matches [1][1][1] = cs44 , \additive \sbasedon10, db_editor
$matches [2][2][2] = cs45 , \additive \sbasedon10, db_email

Thanks in advance for any pointers.

 



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




[PHP] Arrays of strings from regex

2002-12-31 Thread David Pratt
Am working through document to collect pieces that match and then insert 
them into an array so they can be used to construct another file.

Looking in my doc for lines like this:

{\*\cs43 \additive \sbasedon10 db_edition;}
{\*\cs44 \additive \sbasedon10 db_editor;}
{\*\cs45 \additive \sbasedon10 db_email;}

Wrote this regex to find them:

^\{\\\*\\?(cs[0-9]{1,3}) (.*)\\[a-z0-9]+ (.*);\}$

Now looking for best method for getting the parts in parenthesis () into an
array so it will contain these values by finding the above three lines:

$matches [0][0][0] = cs43 , \additive \sbasedon10, db_edition
$matches [1][1][1] = cs44 , \additive \sbasedon10, db_editor
$matches [2][2][2] = cs45 , \additive \sbasedon10, db_email

Thanks in advance for any pointers.

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




Re: [PHP] *arrays/evaluating - ! urgent !

2002-12-17 Thread Wico de Leeuw
Hiya,

I couldn't read you code really (i think you gotta look into it, eval is 
evil and really not nessacery here)

I suggest you look at this (piece) of code:





value="">value_






Gr,

Wico


At 17:52 17-12-02 +0100, Alexey Lysenkov wrote:
Hello,
another newbie here.

Here is a loop:

for($f=0;$f\n");
echo("$frage5[$f]\n");
for($h=0;$h\n");
 $tempQar = "array_values(\$arq_5_".$hh.")";
 eval("\$tempQar=\"$tempQar\";");
  for($v=0;$v<7;$v++){
   if((int)$tempQar[$f] == $v){
$sel = "selected";
   }else{
$sel = "";
   }
   echo("$v\n");
  }
 echo("\n\n");
}
   }

Arrays hersteller as well as frage5 are set manually, so they are okay.They
are printing out okay as well.
The logic is as follows - not to make (frage5*hersteller) variables, I
manually set 5 empty arrays with the names arq5_1, arq5_2 and
arq5_[hersteller], etc. Now, when the form is submitted and something is
being wrong with the input, it returns the form (practically, goes through
the whole html again) and sets the selected fields to the options, radios
and values already submitted. Supposed to be nice, so you correct only what
you did wrong.
What I am failing to achieve with this code, is keeping the options of the
selects in the manner they were selected when submitting. In the include,
which validates the input it works alright. Here is the code:

for($i=1;$i 3){
 $varsOkay = false;
 $frage5warn = true;
}

If I put print_r($tempQar) after the second "for..." statement, it prints
out the array, which is alright - with every value submitted in its place.
But somehow, almost the same thing doesn't work in the main, so to say,
file. Could anyone help? Please? It's urgent.

Regards,
Alex



--
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] *arrays/evaluating - ! urgent !

2002-12-17 Thread Alexey Lysenkov
Hello,
another newbie here.

Here is a loop:

for($f=0;$f\n");
echo("$frage5[$f]\n");
for($h=0;$h\n");
 $tempQar = "array_values(\$arq_5_".$hh.")";
 eval("\$tempQar=\"$tempQar\";");
  for($v=0;$v<7;$v++){
   if((int)$tempQar[$f] == $v){
$sel = "selected";
   }else{
$sel = "";
   }
   echo("$v\n");
  }
 echo("\n\n");
}
   }

Arrays hersteller as well as frage5 are set manually, so they are okay.They
are printing out okay as well.
The logic is as follows - not to make (frage5*hersteller) variables, I
manually set 5 empty arrays with the names arq5_1, arq5_2 and
arq5_[hersteller], etc. Now, when the form is submitted and something is
being wrong with the input, it returns the form (practically, goes through
the whole html again) and sets the selected fields to the options, radios
and values already submitted. Supposed to be nice, so you correct only what
you did wrong.
What I am failing to achieve with this code, is keeping the options of the
selects in the manner they were selected when submitting. In the include,
which validates the input it works alright. Here is the code:

for($i=1;$i 3){
 $varsOkay = false;
 $frage5warn = true;
}

If I put print_r($tempQar) after the second "for..." statement, it prints
out the array, which is alright - with every value submitted in its place.
But somehow, almost the same thing doesn't work in the main, so to say,
file. Could anyone help? Please? It's urgent.

Regards,
Alex



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




Re: [PHP] arrays

2002-11-05 Thread Khalid El-Kary
hi,
the function array is for making a new array. Observe this code and you will 
get the point

(assuming that you won't to loop for five times)

$myarr= array()
for ($i=0;$i<=5;$i++)
{
 $myarr[$i]=$i;
}

//you can then get the values of the array
echo $myarr[0];
echo $myarr[1]; //and like that

note that this loop simply assigns a number to every array index, this is 
not so useful, but you would probably do something with $i to store a 
particular value.

khalid



_
Protect your PC - get McAfee.com VirusScan Online 
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963


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



Re: [PHP] arrays

2002-11-05 Thread Rick Emery
If I understand your question, you are trying to store values into an array:

for( $=0; $i<5; $i++)
{
...get $picture from somewhere...
$mypics[] = $picture;
}

To retrieve:
foreach($mypics as $pic)
{
...do something with $pic...
}

- Original Message - 
From: "Edward Peloke" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 05, 2002 12:44 PM
Subject: [PHP] arrays


Ok, very basic question, how do I am going through a loop 5 times, each
time, I want to store a value into an array, do I simply set the value of

$picture=array($mypics);

and each time it loops it will take the current value of $picture and then I
can get out each value by $mypics[0], $mypics[1], etc?

Thanks,
Eddie


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

2002-11-05 Thread Edward Peloke
Ok, very basic question, how do I am going through a loop 5 times, each
time, I want to store a value into an array, do I simply set the value of

$picture=array($mypics);

and each time it loops it will take the current value of $picture and then I
can get out each value by $mypics[0], $mypics[1], etc?

Thanks,
Eddie


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




Re: [PHP] Arrays misbehaving!

2002-08-30 Thread Chris Wesley

On Fri, 30 Aug 2002, Cameron Thorne wrote:

> I was hoping I could access by either name OR number, but apparently not.

Just for kicks ... here's something pretty ugly (I'd never use it), but
neat if you're interested (or somehow really have your heart set on using
integers).  There are probably a handful of other ways to do this:

$test = array ( 'a' => 'A', 'b' => 'B', 'c' => 'C');
$test_keys = array_keys( $test );
print $test[$test_keys[2]];  // Prints "C" - Same as print $test['c'];

~Chris


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




Re: [PHP] Arrays misbehaving!

2002-08-30 Thread Cameron Thorne

That does help, yes.  So basically there is no way to access associative
arrays using numerical indices?

I was hoping I could access by either name OR number, but apparently not.

Thanks!

-- Cameron



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




Re: [PHP] Arrays misbehaving!

2002-08-30 Thread Chris Wesley

On Fri, 30 Aug 2002, Cameron Thorne wrote:

> Can anyone explain why the following code operates the way it does in my
> comments?

Sure.

> 
> $test = array ( 'a' => 'A', 'b' => 'B', 'c' => 'C');

An associative array, $test.

>
> if (array_key_exists(2, $test)) echo "It works by key number!";  // Does not
> work.

... for subjective definitions of "work."  It works alright.  Nothing
prints because there isn't an array key '2' in $test.

> if (array_key_exists('c', $test)) echo "It works by key name!";  // Works.

Of course.

> print_r(array_keys($test));// outputs "Array ( [0] => a [1] => b [2] =>
> c ) "

You've done two things with this statement.  (1) Got all the keys from
$test, then (2) printed out the keys in "human readable" format.
print_r() is printing information about the array which was returned from
the call to array_keys().

Examine the output from "print_r($test)" and check the documentation for
print_r() & array_keys() to get a glimpse into what might be the source
of what's got you a bit confused.

> ?>

> Any ideas?  According to the documentation, it seems like I should be able
> to access any key in the array by either name or number (which is what I
> want to do).

You can access array indicies by number for non-associative arrays:
$test = array( "A", "B", "C", "D" );
OR associative arrays that use numbers for keys:
$test = array( 0 => "A", 1 => "B", 3 => "C", 4 => "D" );

echo( $test[2] ); ... will work for either of those,
but the indicies of your original $test:
> $test = array ( 'a' => 'A', 'b' => 'B', 'c' => 'C');
have to accessed with the appropriate key.

hth,
~Chris


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




[PHP] Arrays misbehaving!

2002-08-30 Thread Cameron Thorne

Can anyone explain why the following code operates the way it does in my
comments?

 'A', 'b' => 'B', 'c' => 'C');

if (array_key_exists(2, $test)) echo "It works by key number!";  // Does not
work.
if (array_key_exists('c', $test)) echo "It works by key name!";  // Works.

print_r(array_keys($test));// outputs "Array ( [0] => a [1] => b [2] =>
c ) "

?>

Any ideas?  According to the documentation, it seems like I should be able
to access any key in the array by either name or number (which is what I
want to do).

-- Cameron



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




Re: [PHP] Arrays within arrays question

2002-08-28 Thread Brent Baisley

I always put an if(is_array($var)) to check if an array was actually 
return.

On Wednesday, August 28, 2002, at 04:49 AM, Jean-Christian Imbeault 
wrote:

> Jason Wong wrote:
>> If $aProds can contain more than 1 item then what you're doing now is 
>> correct.
>
> Thanks. The problem was that I was doing this:
>
> $return[] = get_array_of_prods();
>
> the [] was creating the extra array level ...
>
> The problem I now face is that foreach keeps crapping out if I pass it 
> an "unitialized" (i.e. has no value) array. Foreach is happy with empty 
> arrays but not arrays that have not been assigned anything yet ...
>
> Jc
>
> -- PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577


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




Re: [PHP] Arrays within arrays question

2002-08-28 Thread Jean-Christian Imbeault

Jason Wong wrote:
> 
> If $aProds can contain more than 1 item then what you're doing now is correct. 

Thanks. The problem was that I was doing this:

$return[] = get_array_of_prods();

the [] was creating the extra array level ...

The problem I now face is that foreach keeps crapping out if I pass it 
an "unitialized" (i.e. has no value) array. Foreach is happy with empty 
arrays but not arrays that have not been assigned anything yet ...

Jc


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




Re: [PHP] Arrays within arrays question

2002-08-28 Thread Jason Wong

On Wednesday 28 August 2002 15:31, Jean-Christian Imbeault wrote:
> I have the following loop to insert data into an array:
>
> while ($data = pg_fetch_object($res)) {
>  $aProds[] = array('id' => $data->prod_id, 'quantity' =>
> $data->quantity);
>}
>
> But when I print this out using print_r I get the following:
>
> Array
> (
>  [0] => Array
>  (
>  [0] => Array
>  (
>  [id] => 289000100024
>  [quantity] => 1
>  )
>
>  [1] => Array
>  (
>  [id] => 289000100050
>  [quantity] => 1
>  )
>
>  )
>
> )
>
> This array has only one element in it; not what I wanted. I wanted
> something like this:
>
> Array
> (
>  [0] => Array
>  (
>  [id] => 289000100024
>  [quantity] => 1
>  )
>  [1] => Array
>  (
>  [id] => 289000100050
>  [quantity] => 1
>  )
> )
>
> How can I achieve this?

If $aProds can contain more than 1 item then what you're doing now is correct. 

If $aProds will only ever contain 1 item then use:

  $aProds = array('id' => $data->prod_id, 'quantity' => $data->quantity);

But then you can drop the while-loop and probably can just do:
  
  $aProds = pg_fetch_object($res);

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Q:  What is the difference between a duck?
A:  One leg is both the same.
*/


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




Re: [PHP] Arrays within arrays question

2002-08-28 Thread Jean-Christian Imbeault

Justin French wrote:
> Okay, it may be the end of a long day here, but I can't tell the difference
> between the two arrays you posted!

One array contains only one element. That one element contains two 
elements, each and array with two elements.

The other array contains two elements, each element being an array 
itself with two elements.

Jc


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




Re: [PHP] Arrays within arrays question

2002-08-28 Thread Justin French

Okay, it may be the end of a long day here, but I can't tell the difference
between the two arrays you posted!

Justin



on 28/08/02 5:31 PM, Jean-Christian Imbeault ([EMAIL PROTECTED])
wrote:

> I have the following loop to insert data into an array:
> 
> while ($data = pg_fetch_object($res)) {
> $aProds[] = array('id' => $data->prod_id, 'quantity' =>
> $data->quantity);
> }
> 
> But when I print this out using print_r I get the following:
> 
> Array
> (
> [0] => Array
> (
> [0] => Array
> (
> [id] => 289000100024
> [quantity] => 1
> )
> 
> [1] => Array
> (
> [id] => 289000100050
> [quantity] => 1
> )
> 
> )
> 
> )
> 
> This array has only one element in it; not what I wanted. I wanted
> something like this:
> 
> Array
> (
> [0] => Array
> (
> [id] => 289000100024
> [quantity] => 1
> )
> [1] => Array
> (
> [id] => 289000100050
> [quantity] => 1
> )
> )
> 
> How can I achieve this?
> 
> Thanks!
> 
> Jc
> 


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




[PHP] Arrays within arrays question

2002-08-28 Thread Jean-Christian Imbeault

I have the following loop to insert data into an array:

while ($data = pg_fetch_object($res)) {
 $aProds[] = array('id' => $data->prod_id, 'quantity' => 
$data->quantity);
   }

But when I print this out using print_r I get the following:

Array
(
 [0] => Array
 (
 [0] => Array
 (
 [id] => 289000100024
 [quantity] => 1
 )

 [1] => Array
 (
 [id] => 289000100050
 [quantity] => 1
 )

 )

)

This array has only one element in it; not what I wanted. I wanted 
something like this:

Array
(
 [0] => Array
 (
 [id] => 289000100024
 [quantity] => 1
 )
 [1] => Array
 (
 [id] => 289000100050
 [quantity] => 1
 )
)

How can I achieve this?

Thanks!

Jc


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




Re: [PHP] Arrays and Regs

2002-07-18 Thread Analysis & Solutions

Martin:

On Thu, Jul 18, 2002 at 03:55:13PM -0400, Martin Clifford wrote:
> 
> Just a performance question, if anyone knows for sure.  Within a large 
> array, would using numerical indices be quicker than associative?  I'm 
> talking about a *noticeable* difference in performance, here.

The difference is marginal.  The longer the variable name, the more 
resources used, but it's not something that you're really going to notice.  
More important is code readability.

But, the difference between turning line wrapping on (~77 columns) in your
email client will save significant time for people replying to your posts.


> $text = eregi_replace("([abc]+)", " red\">\\1", $text);
> 
> Would this replace any occurences of the pattern with the same pattern 
> match in red text?  I'm not sure exactly how the \\1, \\2, etc. works.

It matches sub-patterns, which are the things in parentheses.  The number 
corresponds to the parenthetical order.
  
> $text = eregi_replace("(a)(b)(c)", "\\1", $text);
> 
> Does this output only the 'a'?

Exactly.

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




[PHP] Arrays and Regs

2002-07-18 Thread Martin Clifford

Howdy,

Just a performance question, if anyone knows for sure.  Within a large array, would 
using numerical indices be quicker than associative?  I'm talking about a *noticeable* 
difference in performance, here.

Also, on Regular Expression replacements:

$text = eregi_replace("([abc]+)", "\\1", $text);

Would this replace any occurences of the pattern with the same pattern match in red 
text?  I'm not sure exactly how the \\1, \\2, etc. works.  So, does:

$text = eregi_replace("(a)(b)(c)", "\\1", $text);

Does this output only the 'a'?  I find this confusing for some reason, hehe.  Any help 
would be great!

Martin Clifford
Homepage: http://www.completesource.net
Developer's Forums: http://www.completesource.net/forums/



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




Re: [PHP] [arrays] reading from a form.

2002-06-13 Thread Stuart Dallas

On Thursday, June 13, 2002 at 6:38:10 PM, you wrote:
> I have a example.html
> ---
> 
> function add()
> {
>  var res=0;
>  for(x=0;x<3;x++)res=res+parseFloat(example.text[x].value);
>  example.result.value=res;
> }
> 
> 
> 
>  
>  
>  
>  
>  
>  
> 
> 
> ---
> and show.php
> ---
> 
>  echo $text[0]."+".$text[1]."+".$text[2]."=";
> echo $result;
?>>
> 

> PHP return the error:
> Notice: Uninitialized string offset: 1 in show.php on line 4

> How could I know the values of the text? without modify example.html

The easiest way would be to modify example.html and change each instance of
name="text" to name="text[]". However, since you say you cannot do that, try
echoing $_SERVER['QUERY_STRING']. If that contains all 3 then you can parse
that to get the values out.

-- 
Stuart


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




[PHP] [arrays] reading from a form.

2002-06-13 Thread Àlex Camps

I have a example.html
---

function add()
{
 var res=0;
 for(x=0;x<3;x++)res=res+parseFloat(example.text[x].value);
 example.result.value=res;
}



 
 
 
 
 
 


---
and show.php
---




PHP return the error:
Notice: Uninitialized string offset: 1 in show.php on line 4

How could I know the values of the text? without modify example.html







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




RE: [PHP] Arrays

2002-06-11 Thread Lazor, Ed

Create two database tables.  One for categories and one for links.  Here are
the fields you want for categories:

- ID
- ParentID
- Title

The ParentID field allows  you to create a hierarchy of categories - one
category and it's sub-categories.  For example:

ID  ParentIDTitle

1   0   Home
2   1   Books
3   1   Movies
4   2   Sci-Fi
5   2   Adventure
6   3   Sci-Fi
7   3   Adventure

Will create the following hierarchy:


Home (0)
  |
-
|   |
Books   Movies
|   |
-   -
|   |   |   |
   Sci-Fi Adventure Sci-Fi
Adventure


Your Links table will have the following fields:

- ID
- ParentID
- Title



Create forms for adding, editing, and deleting categories.
Create forms for adding, editing, and deleting links.

Set up a main page the CatID should be 0 at this point.

List categories with ParentID = 0 and have a link to add categories and
links.  

The add category form will store the current CatID as ParentID.

The add link form will operate the same way.

Then it's just an issue of creating a page that lists all of the categories
and links that have the current CatID as the ParentID.  When you list them,
create links for them to the same page that references the ID



and just loop through that for all of the result set and you're on your
way...

ok... I'm pretty sure this might be somewhat vague... sorry, I'm trying to
help as much as I can with only a short amount of time at the moment.  Feel
free to ask questions, but try to research this and see how much you can
figure out on your own first =)

-Ed



> -Original Message-
> From: Daniel Broome [mailto:[EMAIL PROTECTED]]
> Sent: Monday, June 10, 2002 4:08 PM
> To: Lazor, Ed
> Subject: Re: [PHP] Arrays
> 
> 
> I dont know how to explane this.. what I need to do is, I 
> have a menu with
> sub links that are desplayed when the topic is clicked.
> 
> what I need to do is create a script that is easy to edit, at 
> the moment I
> am having to write all the HTML inside the PHP script.. e.g
> $sub="link goes here etc.
> for each topic I have a script.
> 
> What I would like to do is say, if $menu = contact foreach 
> array in topic
> echo "thier $link and $name"
> 
> I think I can do it myself but I need help on what commands I 
> can use and
> what is the best way to use them.
> 
> thanks for helping.
> 
> Dan
> 
> - Original Message -
> From: "Lazor, Ed" <[EMAIL PROTECTED]>
> To: "'Dan'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Tuesday, June 11, 2002 10:45 AM
> Subject: RE: [PHP] Arrays
> 
> 
> > Get the number of items in the array using the count 
> function and then use
> a
> > for statement to loop through them from start to finish.  Here's an
> example:
> >
> >
> > $Total = count($link);
> >
> > for ($i = 0;$i < $Total;$i++)
> > print "$name";
> >
> > Of course, the link names will all be the same, so you'll 
> probably want to
> > store that in the array as well...
> >
> > for ($i = 0;$i < $Total;$i++)
> > print " > href='".$link[$i][url]."'>".$link[$i][name]."";
> >
> >
> > -Original Message-
> > From: Dan [mailto:[EMAIL PROTECTED]]
> > Sent: Monday, June 10, 2002 3:01 PM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Arrays
> >
> >
> > I'm trying to get my head around arrays and how to munipulate them.
> >
> > what I need to do is add html around the arrays eg.
> > ".$name.";
> >
> > I have my head around that but I the number of lines the I 
> need to create
> is
> > going to change so I need the script to repeat untill all 
> the arrays are
> > used.
> >
> > --
> > -
> > Daniel Broome, siliconBLUE Ltd, Web Author,
> > http://siliconblue.com
> > Mob: 64-21-178-5120
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> **

RE: [PHP] Arrays

2002-06-10 Thread Lazor, Ed

Get the number of items in the array using the count function and then use a
for statement to loop through them from start to finish.  Here's an example:


$Total = count($link);

for ($i = 0;$i < $Total;$i++)
print "$name";

Of course, the link names will all be the same, so you'll probably want to
store that in the array as well...

for ($i = 0;$i < $Total;$i++)
print "".$link[$i][name]."";


-Original Message-
From: Dan [mailto:[EMAIL PROTECTED]]
Sent: Monday, June 10, 2002 3:01 PM
To: [EMAIL PROTECTED]
Subject: [PHP] Arrays


I'm trying to get my head around arrays and how to munipulate them.

what I need to do is add html around the arrays eg.
".$name.";

I have my head around that but I the number of lines the I need to create is
going to change so I need the script to repeat untill all the arrays are
used.

--
-
Daniel Broome, siliconBLUE Ltd, Web Author,
http://siliconblue.com
Mob: 64-21-178-5120



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

This message is intended for the sole use of the individual and entity to
whom it is addressed, and may contain information that is privileged,
confidential and exempt from disclosure under applicable law.  If you are
not the intended addressee, nor authorized to receive for the intended
addressee, you are hereby notified that you may not use, copy, disclose or
distribute to anyone the message or any information contained in the
message.  If you have received this message in error, please immediately
advise the sender by reply email and delete the message.  Thank you very
much.   

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




[PHP] Arrays

2002-06-10 Thread Dan

I'm trying to get my head around arrays and how to munipulate them.

what I need to do is add html around the arrays eg.
".$name.";

I have my head around that but I the number of lines the I need to create is
going to change so I need the script to repeat untill all the arrays are
used.

--
-
Daniel Broome, siliconBLUE Ltd, Web Author,
http://siliconblue.com
Mob: 64-21-178-5120



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




[PHP] RE: Possible bug? (was Re: [PHP] Arrays: Please help before I go insane?)

2002-06-06 Thread Scott Hurring

When i run your code, the result is 100% correct, even
though you're outputting the wrong text label to go along
with the value 
you say "branch[one][two]" = $branch[one]
and since $branch[one] *IS* an Array, the output is correct
(even though "branch[one][two]" is NOT an Array --
very very important difference)

Here's my output of the code below:

SET == SET
Passing to getParentNodes:
currentBranch[one][two] = Array




---
Scott Hurring
Systems Programmer
EAC Corporation
[EMAIL PROTECTED]
Voice: 201-462-2149
Fax: 201-288-1515

> -Original Message-
> From: Chris Boget [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 06, 2002 4:43 PM
> To: Scott Hurring; Php-General (E-mail)
> Subject: Possible bug? (was Re: [PHP] Arrays: Please help before I go
> insane?)
> 
> 
> > In that case, split it up into two-steps, to only init the
> > array if you need to i'm not really sure how the rest of
> > your code is -- you could probably do this a nicer way,
> > but this will work:
> > if (!is_array($ary["this"]))
> > $ary["this"] = array();
> > $ary["this"]["that"] = 1;
> 
> This is all well and good.  But I'm already doing that last 
> one and it's 
> that last that is getting messed up.
> 
> Again, if you look at the page I gave the link for, you'll 
> see where it 
> says:
> 
> currentBranch[other][joe] = Array
> 
> (all good) but the next line it says:
> 
> Passing to getParentNodes: currentBranch[joe][monster] = SET
> 
> which it shouldn't.  Where it says "SET" it should say "Array".  This
> is what my code is doing:
> 
> --
> 
> $currentBranch["$nodeName"]["{$nodeInfo[parent]}"] = "SET";
> 
> echo "Passing to getParentNodes: 
> currentBranch[$nodeName][{$nodeInfo[parent]}] = " . 
> $currentBranch["$nodeName"] . "\n";
> 
> --
> 
> $nodeInfo[parent] is a valid value.  So $currentBranch["$nodeName"]
> should be an array after that.  However, by some miracle (or bug in 
> PHP), instead of printing out "Array", it's print out "SET".  
> And I have
> no idea why it's doing that in my code.  The above works fine 
> by itself,
> however in my function it doesn't *even though they are doing the same
> things with no other code between*.
> 
> Chris
> 
> 

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




[PHP] Possible bug? (was Re: [PHP] Arrays: Please help before I go insane?)

2002-06-06 Thread Chris Boget

> In that case, split it up into two-steps, to only init the
> array if you need to i'm not really sure how the rest of
> your code is -- you could probably do this a nicer way,
> but this will work:
> if (!is_array($ary["this"]))
> $ary["this"] = array();
> $ary["this"]["that"] = 1;

This is all well and good.  But I'm already doing that last one and it's 
that last that is getting messed up.

Again, if you look at the page I gave the link for, you'll see where it 
says:

currentBranch[other][joe] = Array

(all good) but the next line it says:

Passing to getParentNodes: currentBranch[joe][monster] = SET

which it shouldn't.  Where it says "SET" it should say "Array".  This
is what my code is doing:

--

$currentBranch["$nodeName"]["{$nodeInfo[parent]}"] = "SET";

echo "Passing to getParentNodes: 
currentBranch[$nodeName][{$nodeInfo[parent]}] = " . 
$currentBranch["$nodeName"] . "\n";

--

$nodeInfo[parent] is a valid value.  So $currentBranch["$nodeName"]
should be an array after that.  However, by some miracle (or bug in 
PHP), instead of printing out "Array", it's print out "SET".  And I have
no idea why it's doing that in my code.  The above works fine by itself,
however in my function it doesn't *even though they are doing the same
things with no other code between*.

Chris



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




RE: [PHP] Arrays: Please help before I go insane?

2002-06-06 Thread Scott Hurring

In that case, split it up into two-steps, to only init the
array if you need to i'm not really sure how the rest of
your code is -- you could probably do this a nicer way,
but this will work:

if (!is_array($ary["this"]))
$ary["this"] = array();

$ary["this"]["that"] = 1;

---
Scott Hurring
Systems Programmer
EAC Corporation
[EMAIL PROTECTED]
Voice: 201-462-2149
Fax: 201-288-1515

> -Original Message-
> From: Chris Boget [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 06, 2002 3:43 PM
> To: Scott Hurring
> Cc: PHP General
> Subject: Re: [PHP] Arrays: Please help before I go insane?
> 
> 
> > Try:  $ary["this"] = array("that" => 1);
> 
> That works great until "this" has 2 children.  The second child 
> overwrites the first. :(
> 
> Chris
> 
> 

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




Re: [PHP] Arrays: Please help before I go insane?

2002-06-06 Thread Chris Boget

> Try:  $ary["this"] = array("that" => 1);

That works great until "this" has 2 children.  The second child 
overwrites the first. :(

Chris



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




RE: [PHP] Arrays: Please help before I go insane?

2002-06-06 Thread Scott Hurring

Try:  $ary["this"] = array("that" => 1);



---
Scott Hurring
Systems Programmer
EAC Corporation
[EMAIL PROTECTED]
Voice: 201-462-2149
Fax: 201-288-1515

> -Original Message-
> From: Chris Boget [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 06, 2002 1:48 PM
> To: PHP General
> Subject: Re: [PHP] Arrays: Please help before I go insane?
> 
> 
> > Now, what I'm trying to do is build a tree based on the 
> data in the DB.  
> > It's working relatively ok if I uncomment the code that is 
> on line 48 and 
> > comment out line 49.  However, what I really want to do is 
> build a fully 
> > associative array doing this and now** an array that has 
> string keys but 
> > then, those arrays having numeric keys (copy and run this code 
> > un/commenting the lines above and you'll see what I mean).
> 
> ** should be "not"
> 
> To elaborate, what I'm trying to do is build an array that 
> looks like this:
> 
> $array["this"]["that"] = "whatever";
> $array["this"]["other"] = "whatever";
> 
> and not one that looks like this:
> 
> $array["this"][0] = "that";
> $array["this"][1] = "other";
> 
> because I just want to be able to get the keys and not have to worry
> about when I should be using the value of the key or the value of the
> array element.
> 
> Again, the problem that I'm having (as demonstrated by the code) is
> that when I'm trying to set it up so that it's like the first 
> example above,
> 
> $array["this"]
> 
> isn't always evaluating as an array, though it always should.
> 
> Chris
> 
> 
> 
> 
> 
> -- 
> 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] Arrays: Please help before I go insane?

2002-06-06 Thread Chris Boget

> Now, what I'm trying to do is build a tree based on the data in the DB.  
> It's working relatively ok if I uncomment the code that is on line 48 and 
> comment out line 49.  However, what I really want to do is build a fully 
> associative array doing this and now** an array that has string keys but 
> then, those arrays having numeric keys (copy and run this code 
> un/commenting the lines above and you'll see what I mean).

** should be "not"

To elaborate, what I'm trying to do is build an array that looks like this:

$array["this"]["that"] = "whatever";
$array["this"]["other"] = "whatever";

and not one that looks like this:

$array["this"][0] = "that";
$array["this"][1] = "other";

because I just want to be able to get the keys and not have to worry
about when I should be using the value of the key or the value of the
array element.

Again, the problem that I'm having (as demonstrated by the code) is
that when I'm trying to set it up so that it's like the first example above,

$array["this"]

isn't always evaluating as an array, though it always should.

Chris





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




[PHP] Arrays: Please help before I go insane?

2002-06-06 Thread Chris Boget

To see what I'm working with, go here:

http://www.melancholy.org/test_tree.php

You may want to copy the source and the (mySQL) db structure and 
set it up on your system there to test it out.  Though, if you don't want 
to do that, I show the output at the very bottom of the page.

One note: I took out all the code that connects to the db and what not.  
It's not really relevant and it has logins, etc. 

Now, what I'm trying to do is build a tree based on the data in the DB.  
It's working relatively ok if I uncomment the code that is on line 48 and 
comment out line 49.  However, what I really want to do is build a fully 
associative array doing this and now an array that has string keys but 
then, those arrays having numeric keys (copy and run this code 
un/commenting the lines above and you'll see what I mean).

What is going wrong is that for whatever reason (and I can't see why, it 
should be working and I'm getting ready to become certifiable any time 
now), though it works at the beginning, what is getting passed to 
getParentNodes() on line 55 eventually stops being an array.  What's 
getting passed is the word "SET" (something I'm just putting in there.  I'm 
not really interested in the value, just the keys of the various arrays).  Why 
is that?  $currentBranch["$nodeName"] should *always* be an array in that 
section of the code...

if you define

$array["this"]["that"] = 1;

$array["this"] is an array.  However, in my code, the array that I'm using
is not being treated as such and I have no idea why.

One other thing of note about the data from the DB: I realize that "this"
and "briggs" are looping back on one another.  The code that I have at
lines 45 and 47 keep it from infinitely looping.

Please, can someone offer any explanation as to why I'm getting the
problem that I am?

Chris



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




Re: [PHP] arrays and same index

2002-05-30 Thread Ed Gorski

Well what exactly are you trying to do?  You can't name an index of an 
array the same thing and expect different values

ed

At 03:36 PM 5/30/2002 +0200, Victor Spång Arthursson wrote:
>Hi!
>
>I want to create an array that looks like follows:
>
>$array["untitled_1.jpg"][] = 0
>$array["untitled_1.jpg"][] = 3
>$array["untitled_1.jpg"][] = 4
>$array["untitled_2.jpg"][] = 0
>$array["untitled_3.jpg"][] = 1
>
>What I'm thinking about is accessing all "untitled_1.jpg" values by doing 
>the following:
>
>$newarray = $array["untitled_1.jpg"];
>
>and receive an array with 3 indexes which has the values 0,3,4...
>
>This doesn't works...
>
>$array["untitled_1.jpg"][] = 3 seems to overwrite 
>$array["untitled_1.jpg"][] = 0 and then $array["untitled_1.jpg"][] = 4 
>overwrites $array["untitled_1.jpg"][] = 3...
>
>How should I solve this?
>
>Sincerely
>
>Victor
>
>
>--
>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] arrays and same index

2002-05-30 Thread Stuart Dallas

Victor Spång Arthursson <[EMAIL PROTECTED]> wrote:
> I want to create an array that looks like follows:
>
> $array["untitled_1.jpg"][] = 0
> $array["untitled_1.jpg"][] = 3
> $array["untitled_1.jpg"][] = 4
> $array["untitled_2.jpg"][] = 0
> $array["untitled_3.jpg"][] = 1
>
> What I'm thinking about is accessing all "untitled_1.jpg" values by
> doing the following:
>
> $newarray = $array["untitled_1.jpg"];
>
> and receive an array with 3 indexes which has the values 0,3,4...
>
> This doesn't works...
>
> $array["untitled_1.jpg"][] = 3 seems to overwrite
> $array["untitled_1.jpg"][] = 0 and then $array["untitled_1.jpg"][] = 4
> overwrites $array["untitled_1.jpg"][] = 3...
>
> How should I solve this?

It seems to work for me. The file...



The result: http://www.devserver.org/arraytest.php

--
Stuart


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




RE: [PHP] arrays and same index

2002-05-30 Thread Cal Evans

$array["untitled_1.jpg"] = array(0,3,4,0,1)

Or you could :
$array["untitled_1.jpg"] = array();

$array["untitled_1.jpg"][0]=0
$array["untitled_1.jpg"][1]=3
$array["untitled_1.jpg"][2]=4
$array["untitled_1.jpg"][3]=0
$array["untitled_1.jpg"][4]=1


Then you can access them by using:
echo $array["untitled_1.jpg"][0] // = 0;
echo $array["untitled_1.jpg"][1] // = 3;
echo $array["untitled_1.jpg"][2] // = 4;
echo $array["untitled_1.jpg"][3] // = 0;
echo $array["untitled_1.jpg"][4] // = 1;

or:
$x = $array["untitled_1.jpg"];
echo $x[0];
echo $x[1];
echo $x[2];
echo $x[3];
echo $x[4];

HTH,
=C=
*
* Cal Evans
* Journeyman Programmer
* Techno-Mage
* http://www.calevans.com
*
 

-Original Message-----
From: Victor Spang Arthursson [mailto:[EMAIL PROTECTED]]
Sent: Thursday, May 30, 2002 8:37 AM
To: [EMAIL PROTECTED]
Subject: [PHP] arrays and same index


Hi!

I want to create an array that looks like follows:

$array["untitled_1.jpg"][] = 0
$array["untitled_1.jpg"][] = 3
$array["untitled_1.jpg"][] = 4
$array["untitled_2.jpg"][] = 0
$array["untitled_3.jpg"][] = 1

What I'm thinking about is accessing all "untitled_1.jpg" values by 
doing the following:

$newarray = $array["untitled_1.jpg"];

and receive an array with 3 indexes which has the values 0,3,4...

This doesn't works...

$array["untitled_1.jpg"][] = 3 seems to overwrite 
$array["untitled_1.jpg"][] = 0 and then $array["untitled_1.jpg"][] = 4 
overwrites $array["untitled_1.jpg"][] = 3...

How should I solve this?

Sincerely

Victor


-- 
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] arrays and same index

2002-05-30 Thread Victor Spång Arthursson

Hi!

I want to create an array that looks like follows:

$array["untitled_1.jpg"][] = 0
$array["untitled_1.jpg"][] = 3
$array["untitled_1.jpg"][] = 4
$array["untitled_2.jpg"][] = 0
$array["untitled_3.jpg"][] = 1

What I'm thinking about is accessing all "untitled_1.jpg" values by 
doing the following:

$newarray = $array["untitled_1.jpg"];

and receive an array with 3 indexes which has the values 0,3,4...

This doesn't works...

$array["untitled_1.jpg"][] = 3 seems to overwrite 
$array["untitled_1.jpg"][] = 0 and then $array["untitled_1.jpg"][] = 4 
overwrites $array["untitled_1.jpg"][] = 3...

How should I solve this?

Sincerely

Victor


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




Re: [PHP] arrays

2002-05-26 Thread Philip Olson


> Can arrays be passed to functions just like a simple variable?

Yes.

> Can arrays be passed as values in hidden form fields just like a
> simple variable?

Yes, with a little work.

> I've been playing around with these and getting inconsistent 
> results.  I've been trying things like serialize and urlencode, 
> but still haven't worked out a straightforward 'rule' or policy.

For example:

  $arr = array('color' => 'red', 'fruit' => 'apple');

  $str_arr = urlencode(serialize($arr));

  

And in the action script, do:

  $arr = unserialize(stripslashes($_REQUEST['foo']));

Notes:

  a) stripslashes may be needed, in case magical quotes 
 get in the way (magic_quotes_gpc).
  b) am using $_REQUEST, you may use $_GET or $_POST or 
 whatever contains the form value.
  c) hidden, text, textarea ... doesn't matter.
  d) a way to test if what _should_ be an array 
 is really an array is with print_r() and/or 
 is_array().  print_r($arr);
  e) we don't need urldecode() because that'll 
 happen automatically when going through the form.
  f) you could use implode() instead of serialize too.

> Can someone throw some light on this? 

I hope so :)

Regards,
Philip Olson


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




<    1   2   3   >