Re: [PHP-DB] array issue

2007-11-27 Thread Jason Gerfen
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Clare Media wrote:
> Guys really in need of some assistance here.
> 
> I am reading an xml file and want to loop through the entire file and
> display the information.
> 
> Unfortunately I am only showing 1 item. how can I go about showing all news
> item?
> 
> I've tried array and loop however I am not versed with any of them.
> 
> Thanks in advance
> 
>  
> 
>  
> 
> eg.
> 
> -
> 
> 
> 
> title 1
> 
> Description 1
> 
> 
> 
> 
> 
> title 2
> 
> Description 2
> 
> 
> 
> 
> 
> title 3
> 
> Description 3
> 
> 
> 
> -
> 
>  
> 
> My current code
> 
> +
> 
> function getNews() 
> 
> {
> 
> $file = NEWS_FILE.".xml";
>
> if(!file_exists($file) || filemtime($file) <
> time() - 43200) {
> 
> $this->data =
> @file_get_contents("http://feeds.mydomain.com/dailynews";);
> 
> $fp = @fopen($file, 'w');
> 
> @fwrite($fp, $this->data);
> 
> @fclose($fd);
> 
> }
> 
> else $this->data =
> @file_get_contents($file);
> 
> if(strlen($this->data) <= 0) return;
> 
> 
Count the elements in $this->data = @file_get_contents( $file );
If more then one then loop else use the code below:

ex:
if( count( $this->data = @file_get_contents( $file ) < 1 ) ) {
 foreach( $this->data as $key => $value ) {
  // show your titles etc.
 }
} else {
> 
> // get the location
> 
> $attr = explode('<', $this->tag('item'));
> 
> 
> $return['title'] = $attr[1];
> 
> $return['title'] = substr($return['title'],
> 6);
> 
>  
> 
> $return['description'] = $attr[7];
> 
> $return['description'] =
> substr($return['description'], 2);
> 
>  
> 
> return $return;
> 
> }
> 
> 
> 
> function view_news()
> 
> {
> 
> 
> 
> $currentNews = newsfeed::getNews();
> 
> 
> 
> $NEWS=
> ''.$currentNews['title'].''.$currentNews['description']
> ..'';
> 
> 
> 
> return $NEWS;
> 
> 
> 
> }
> 
>  
> 
> function tag($tag, $skip=0) 
> 
> {
> 
> $start = -1;
> 
> for($i = 0; $i <= $skip; $i++)
> 
> $start = strpos($this->data,
> "<{$tag}", $start + 1);
> 
> if($start === false) return false;
> 
> $start += strlen($tag) + 1;
> 
> $end = strpos($this->data, "",
> $start);
> 
> if($end === false)
> 
> $end = strpos($this->data,
> '/>', $start);
> 
> return trim(substr($this->data, $start, $end
> - $start));
> 
> }
> 
> 


- --
Jason Gerfen

"I practice my religion
 while stepping on your
 toes..."
~The Ditty Bops
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFHTGMM5vk8bwKVAaIRAhAjAJ9FklveFH1PORVl0HC9nCb+klgcUACeOren
RgXSIP0bl/bt9rI6g9a/6Uk=
=y9XX
-END PGP SIGNATURE-

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



RE: [PHP-DB] array

2007-03-29 Thread Bastien Koert
That is not a two dimensional array. Its two one dimensional arrays and yo 
do it like this


while ($row = mysql_fetch_array($result))
{

 $title[]   =$row['title'];
 $description[]  =$row['description'];

 }



bastien


From: elk dolk <[EMAIL PROTECTED]>
To: "php-db@lists.php.net" 
Subject: [PHP-DB] array
Date: Thu, 29 Mar 2007 13:29:45 -0700 (PDT)

Hi all,
I want to put result of query in a two dimensional array like this:

title[0]=x   description [0]=y
title[1]=z   description [1]=w
.

any idea would be appreciated

$query = "SELECT * FROM photo";
$result=mysql_query($query);


while ($row = mysql_fetch_array($result))
{

  $title=$row['title'];
  $description=$row['description'];

  }

-
Don't pick lemons.
See all the new 2007 cars at Yahoo! Autos.


_
Check Out Our List Of Trendy Restaurants. You'll Eat It Up! 
http://local.live.com/?mkt=en-ca/?v=2&cid=A6D6BDB4586E357F!378


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



Re: [PHP-DB] array field type

2007-03-06 Thread Mark
Sancar Saran wrote:

> Thanks for all those replies. It seems there was no easy solution (and or
> serializing was better solution) for us.
> 
> Our arrays contains lots of things.. XML may not fit because content of
> array may broke xml structure.
> 

Before you give up, take a look at the XMLDBX PHP extension at
http://www.mohawksoft.org

It uses XML and works really well.

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



Re: [PHP-DB] array field type

2007-03-06 Thread Micah Stevens


Wrong! Take a look at the SET datatype 
http://dev.mysql.com/doc/refman/4.1/en/set.html. This allows you to have an 
array of values in a single field, and the user can select any number of 
them.


  
Sort of, but not really: This is a really specialized keyword, and 
depends on binary mapping of enum-ish sets. As a results you have a 
maximum of 64 possible values, and only 1 dimension. Large or 
multdimensional arrays wouldn't work with this.


-Micah

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



Re: [PHP-DB] array field type

2007-03-06 Thread Tony Marston

"Sancar Saran" <[EMAIL PROTECTED]> wrote in message 
news:[EMAIL PROTECTED]
> On Sunday 04 March 2007 23:04, Sancar Saran wrote:
>> Hi,
>>
>> I want to know is there any db server around there for store php arrays
>> natively.
>>
>> Regards
>>
>> Sancar
> Thanks for responses, it seems I have to give more info about situation.
>
> In my current project, we had tons of arrays. They are very deep and
> unpredictable nested arrays.
>
> Currently we are using serialize/unserialize and it seems it comes with 
> own
> cpu cost. Xdebug shows some serializing cost blips. Sure it was not SO BIG
> deal (for now of course).
>
> My db expertise covers a bit mysql and mysql does not have any array type
> field (enum just so simple).

Wrong! Take a look at the SET datatype 
http://dev.mysql.com/doc/refman/4.1/en/set.html. This allows you to have an 
array of values in a single field, and the user can select any number of 
them.

-- 
Tony Marston
http://www.tonymarston.net
http://www.radicore.org

> I just want to know is there any way to keep array data type natively in a 
> sql
> field.
>
> Regards.
>
> Sancar 

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



Re: [PHP-DB] array field type

2007-03-05 Thread Sancar Saran
Thanks for all those replies. It seems there was no easy solution (and or 
serializing was better solution) for us.

Our arrays contains lots of things.. XML may not fit because content of array 
may broke xml structure. 

Thanks for help.

Regards

Sancar.

> >>>Hi,
> >>>
> >>>I want to know is there any db server around there for store php arrays
> >>>natively.
> >>>
> >>>Regards
> >>>
> >>>Sancar
> >>
> >>Thanks for responses, it seems I have to give more info about situation.
> >>
> >>In my current project, we had tons of arrays. They are very deep and
> >>unpredictable nested arrays.
> >>
> >>Currently we are using serialize/unserialize and it seems it comes with
> >>own cpu cost. Xdebug shows some serializing cost blips. Sure it was not
> >> SO BIG deal (for now of course).
> >>
> >>My db expertise covers a bit mysql and mysql does not have any array type
> >>field (enum just so simple).
> >>
> >>I just want to know is there any way to keep array data type natively in
> >> a sql field.
> >>
> >>Regards.
> >>
> >>Sancar
>
> _
> Win a trip for four to a concert anywhere in the world!
> http://www.mobilelivetour.ca/

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



Re: [PHP-DB] array field type

2007-03-05 Thread Bastien Koert

another option might be to store xml snippets that match the array.

if you are using large numbers of arrays, perhaps a revamping of the db 
structure to map the arrays to sub-tables might be in order


bastien



From: Micah Stevens <[EMAIL PROTECTED]>
To: Sancar Saran <[EMAIL PROTECTED]>
CC: php-db@lists.php.net,  php-general@lists.php.net
Subject: Re: [PHP-DB] array field type
Date: Sun, 04 Mar 2007 15:04:42 -0800

Not a single field, but there's several methods of storing trees of 
information, which is what an array is. Here's one:


Nested Array storage table:

ArrayID (int, autonumber)
keyname (text)
parent   (int)
data (bigtext or whatever would be appropriate for the data you're storing)

For an array like this:

array('one'=>1, 'two'=>array('three'=>3, 'four'=>4))

the table would store these rows:

1, 'one', 0, 1
2, 'two', 0, 2
3, 'three', 2, 3
4, 'four', 2, 4

You can use a recursive function to restore the array, unless you require 
the granular functionality this type of process would give you such as 
sorting and filtering and statistics gathering.


-Micah

However, I think in the long run, you'd be better off serializing the data.

-Micah


On 03/04/2007 02:15 PM, Sancar Saran wrote:

On Sunday 04 March 2007 23:04, Sancar Saran wrote:


Hi,

I want to know is there any db server around there for store php arrays
natively.

Regards

Sancar


Thanks for responses, it seems I have to give more info about situation.

In my current project, we had tons of arrays. They are very deep and 
unpredictable nested arrays.


Currently we are using serialize/unserialize and it seems it comes with 
own cpu cost. Xdebug shows some serializing cost blips. Sure it was not SO 
BIG deal (for now of course).


My db expertise covers a bit mysql and mysql does not have any array type 
field (enum just so simple).


I just want to know is there any way to keep array data type natively in a 
sql field.


Regards.

Sancar




_
Win a trip for four to a concert anywhere in the world! 
http://www.mobilelivetour.ca/


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



Re: [PHP-DB] array field type

2007-03-04 Thread Micah Stevens
Not a single field, but there's several methods of storing trees of 
information, which is what an array is. Here's one:


Nested Array storage table:

ArrayID (int, autonumber)
keyname (text)
parent   (int)
data (bigtext or whatever would be appropriate for the data you're storing)

For an array like this:

array('one'=>1, 'two'=>array('three'=>3, 'four'=>4))

the table would store these rows:

1, 'one', 0, 1
2, 'two', 0, 2
3, 'three', 2, 3
4, 'four', 2, 4

You can use a recursive function to restore the array, unless you 
require the granular functionality this type of process would give you 
such as sorting and filtering and statistics gathering.


-Micah

However, I think in the long run, you'd be better off serializing the data.

-Micah


On 03/04/2007 02:15 PM, Sancar Saran wrote:

On Sunday 04 March 2007 23:04, Sancar Saran wrote:
  

Hi,

I want to know is there any db server around there for store php arrays
natively.

Regards

Sancar


Thanks for responses, it seems I have to give more info about situation.

In my current project, we had tons of arrays. They are very deep and 
unpredictable nested arrays.


Currently we are using serialize/unserialize and it seems it comes with own 
cpu cost. Xdebug shows some serializing cost blips. Sure it was not SO BIG 
deal (for now of course).


My db expertise covers a bit mysql and mysql does not have any array type 
field (enum just so simple). 

I just want to know is there any way to keep array data type natively in a sql 
field.


Regards.

Sancar

  


Re: [PHP-DB] array field type

2007-03-04 Thread Sancar Saran
On Sunday 04 March 2007 23:04, Sancar Saran wrote:
> Hi,
>
> I want to know is there any db server around there for store php arrays
> natively.
>
> Regards
>
> Sancar
Thanks for responses, it seems I have to give more info about situation.

In my current project, we had tons of arrays. They are very deep and 
unpredictable nested arrays.

Currently we are using serialize/unserialize and it seems it comes with own 
cpu cost. Xdebug shows some serializing cost blips. Sure it was not SO BIG 
deal (for now of course).

My db expertise covers a bit mysql and mysql does not have any array type 
field (enum just so simple). 

I just want to know is there any way to keep array data type natively in a sql 
field.

Regards.

Sancar

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



RE: [PHP-DB] Array

2006-09-29 Thread Shaun A Riches
Title: RE: [PHP-DB] Array






This is hardly database related but nonetheless.


$myString = "Check one two three four.  You did well to count to four.";
$myString = str_replace(".","",$myString);
$myString = strtolower($myString);

$myWords = explode(" ", $myString);

// do stuff here with your array
?>

How is that?

___
Shaun Riches
Computer Science Student
http://www.sh4un.co.uk



-Original Message-
From: Ron Piggott (PHP) [mailto:[EMAIL PROTECTED]]
Sent: Fri 29/09/2006 16:21
To: PHP DB
Subject: [PHP-DB] Array

If I have the sentences

Check one two three four.  You did well to count to four.

how do I put each word into an array (so there would be 12 components in
the array) as well as remove the period and make the C in Check and the
Y in You lower case

Ron







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

RE: [PHP-DB] Array

2006-09-29 Thread Hutchins, Richard
Use the strtolower function to reduce all letters to lower case.

Then use the stripos() function to find where the spaces are in the string
and use that position in the substr() function to parse out the individual
words in the string. From there you can put the chunks into an array or a
query or whatever you're going to do with them.

You can also consider using the str_word_count(mystring, 1) to obtain an
array containing the words in the string. Check out the function in the
documentation to see how it treats different string types though - the
results may not be what you need.

You can also use the above strategy to find the periods in the sentences and
either remove them or just exclude them from whatever it is you're going to
do with the results of your parsing.

Probably a few other ways to get the results you're looking for including a
couple pre-built functions or classes if you Google for them.

-Original Message-
From: Ron Piggott (PHP) [mailto:[EMAIL PROTECTED] 
Sent: Friday, September 29, 2006 11:21 AM
To: PHP DB
Subject: [PHP-DB] Array

If I have the sentences

Check one two three four.  You did well to count to four.

how do I put each word into an array (so there would be 12 components in the
array) as well as remove the period and make the C in Check and the Y in You
lower case

Ron

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



Re: [PHP-DB] Array

2006-09-29 Thread Niel Archer
Hi Ron,

> how do I put each word into an array (so there would be 12 components in
> the array) as well as remove the period and make the C in Check and the
> Y in You lower case

This isn't a DB question, please ask questions in the appropriate list.

But for reference, look up the str_replace, strtolower, and  explode
functions.

Niel

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



RE: [PHP-DB] Array problem...

2005-09-18 Thread Bastien Koert
Dunno if its relevant, but the recommended way to use sessions is to assign 
stuff to a $_SESSION['varname']...I don't really see anything wrong with the 
code...


Also, what arrays are causing the problems?

bastien



From: "NIPP, SCOTT V (SBCSI)" <[EMAIL PROTECTED]>
To: 
Subject: [PHP-DB] Array problem...
Date: Fri, 16 Sep 2005 09:04:34 -0500

I am migrating a web app from an old server running PHP 4.2.3 to
a new server running 4.3.8.  The problem I am running into at the moment
is building an array and passing it to another page.  This code works
fine on the old server, but the array is not coming across to the new
page on the new server.  Help...

mysql_select_db($database, $Prod);
$shell_list = getEnumOptions('accounts','shell');
$shell_tmp = "\n";
$shell_tmp .= "Default Shell\n";
$shell_tmp .= "-\n";
foreach ($shell_list as $item) {
  $shell_tmp .= "$item\n";
}
$shell_tmp .= "\n";

$query_groups = "SELECT name FROM grps";
$groups_tmp = mysql_query($query_groups, $Prod) or die(mysql_error());
$grp_list = "\n";
$grp_list .= "Primary Group\n";
$grp_list .= "---\n";
while($item2 = mysql_fetch_row($groups_tmp)) {
  $grp_list .= "$item2[0]\n";
}
$grp_list .= "\n";



".$_POST['system'][$cntr]."";
echo "".$shell_tmp."";
echo "".$grp_list."";
echo "";
$tmp = $sbcuid."-".$_POST['system'][$cntr];
$cntr++;
array_push( $accnts, $tmp );
  }
?>

If the systems listed
above are correct, please
proceed. Otherwise, please hit the Back button on your browser and
review your
system selections again. 


Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
Web:  http:\\ldsa.sbcld.sbc.com

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



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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Stuart Felenstein
Hopefully these functions will explain it.
I'm starting the transaction, then provided it takes
with no errors it gets the commit

function begin()
{
mysql_query("BEGIN");
}
function commit()
{
mysql_query("COMMIT");
}
function rollback()
{
mysql_query("ROLLBACK");
}

begin();
$query = "INSERT INTO>...

$result = mysql_query($query);
--- Brent Baisley <[EMAIL PROTECTED]> wrote:

> When are you actually performing the insert into the
> database? The code 
> you posted is only changing the value of the
> variable $query. You also 
> need to have the database function to insert into
> the database. 
> Assuming it MySQL:
> ...
> foreach(...) {
>   $query = "INSERT INTO ...";
>   mysql_query($query);
> }
> 
> On Oct 15, 2004, at 4:40 PM, Stuart Felenstein
> wrote:
> 
> > Yep, I had found it shortly before.
> > Only it's not looping.  It is taking last value
> only.
> >
> > Stuart
> >
> >
> > --- "Matt M." <[EMAIL PROTECTED]> wrote:
> >
> >> if ( is_array( $_SESSION['l_industry'] ) ) {
> >>foreach ( $_SESSION['l_industry'] as $p ) {
> >>$query = "INSERT INTO Profiles_Industries
> >> (ProfileID,IndID) VALUES
> >> ($LID, $p)";
> >>} //foreach ( $_SESSION['l_industry'] as $p )
> >> } //if ( is_array( $_SESSION['l_industry'] ) )
> >>
> >> -- 
> >> PHP Database Mailing List (http://www.php.net/)
> >> To unsubscribe, visit:
> http://www.php.net/unsub.php
> >>
> >>
> >
> > -- 
> > PHP Database 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 Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Brent Baisley
When are you actually performing the insert into the database? The code 
you posted is only changing the value of the variable $query. You also 
need to have the database function to insert into the database. 
Assuming it MySQL:
...
foreach(...) {
	$query = "INSERT INTO ...";
	mysql_query($query);
}

On Oct 15, 2004, at 4:40 PM, Stuart Felenstein wrote:
Yep, I had found it shortly before.
Only it's not looping.  It is taking last value only.
Stuart
--- "Matt M." <[EMAIL PROTECTED]> wrote:
if ( is_array( $_SESSION['l_industry'] ) ) {
foreach ( $_SESSION['l_industry'] as $p ) {
$query = "INSERT INTO Profiles_Industries
(ProfileID,IndID) VALUES
($LID, $p)";
} //foreach ( $_SESSION['l_industry'] as $p )
} //if ( is_array( $_SESSION['l_industry'] ) )
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

--
PHP Database 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 Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Stuart Felenstein
Actually it did just loop.  I need to test again.  

The insert statement is the the one $query = 
So it's after yes, but contained in the braces, like
you diagram below.

Stuart
--- "Matt M." <[EMAIL PROTECTED]> wrote:

> where is your insert statement? I am guessing it is
> after your loop
> 
> 
> if ( is_array( $_SESSION['l_industry'] ) ) {
>   foreach ( $_SESSION['l_industry'] as $p ) {
>   $query = "INSERT INTO Profiles_Industries
> (ProfileID,IndID) VALUES
> ($LID, $p)";
> /This is where your insert
> statement should
> be**/
>   } //foreach ( $_SESSION['l_industry'] as $p )
> } //if ( is_array( $_SESSION['l_industry'] ) )
> 

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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Matt M.
where is your insert statement? I am guessing it is after your loop


if ( is_array( $_SESSION['l_industry'] ) ) {
foreach ( $_SESSION['l_industry'] as $p ) {
$query = "INSERT INTO Profiles_Industries (ProfileID,IndID) VALUES
($LID, $p)";
/This is where your insert statement should
be**/
} //foreach ( $_SESSION['l_industry'] as $p )
} //if ( is_array( $_SESSION['l_industry'] ) )

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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Stuart Felenstein
Yep, I had found it shortly before.
Only it's not looping.  It is taking last value only.

Stuart


--- "Matt M." <[EMAIL PROTECTED]> wrote:

> if ( is_array( $_SESSION['l_industry'] ) ) {
>   foreach ( $_SESSION['l_industry'] as $p ) {
>   $query = "INSERT INTO Profiles_Industries
> (ProfileID,IndID) VALUES
> ($LID, $p)";
>   } //foreach ( $_SESSION['l_industry'] as $p )
> } //if ( is_array( $_SESSION['l_industry'] ) )
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 

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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Matt M.
if ( is_array( $_SESSION['l_industry'] ) ) {
foreach ( $_SESSION['l_industry'] as $p ) {
$query = "INSERT INTO Profiles_Industries (ProfileID,IndID) VALUES
($LID, $p)";
} //foreach ( $_SESSION['l_industry'] as $p )
} //if ( is_array( $_SESSION['l_industry'] ) )

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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Stuart Felenstein
Where would that go?

Stuart

--- "Matt M." <[EMAIL PROTECTED]> wrote:

> > if ( is_array( $_SESSION['l_industry'] ) ) {
> > foreach ( $_SESSION['l_industry'] as $p )
> {
> > $query = "INSERT INTO Profiles_Industries
> (ProfileID,
> > IndID)
> > VALUES ($LID, $p)";
> > }
> 
> do you have a } for the if statement?
> 

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



Re: [PHP-DB] Array and insert statement throws error

2004-10-15 Thread Matt M.
> if ( is_array( $_SESSION['l_industry'] ) ) {
> foreach ( $_SESSION['l_industry'] as $p ) {
> $query = "INSERT INTO Profiles_Industries (ProfileID,
> IndID)
> VALUES ($LID, $p)";
> }

do you have a } for the if statement?

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



Re: [PHP-DB] Array

2004-08-26 Thread Micah Stevens
Since you provided no value's it's a little tough, but the general for would 
be:

$parts = array(
  array("PN" => $row1col1, "Desc" => $row1col2, "Qty" => $row1col3),
  array("PN" => $row2col1, "Desc" => $row2col2, "Qty" => $row2col3)
 );

Depending on your implimentation, it maybe easier to use some sort of loop to 
assign things. If you wanted the array to be persistant across pages, you'd 
want to user instead of $parts, $_SESSION['parts']. (assuming of course you 
have initialized a session)

I personally would skip the array stuff and just pop it in a database. 
-Micah 

On Thursday 26 August 2004 02:11 pm, 'Miguel Guirao' wrote:
> Hi!!
>
> I have a table with many options from when the user can select them,
> after that, his/her selections will be stored in a database.
>
> In the mean time, I want to store his/her selections in an array like
> this one:
>
> PNDescQty
>
> |---|--|---|
> |---|--|---|
> |---|--|---|
>
> How do I declare Duch an array like this??, let's call it Parts.
>
>
> Miguel Guirao
> Servicios Datacard
> www.SIASA.com.mx

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



Re: [PHP-DB] Array

2004-08-26 Thread Justin Patrin
$arr = array('key' => array('key2' => 'value', 'key3' => 'value', ...),
...);

$arr['key2'] = array('key2' => 'value', ...);

$arr['key3]['key2'] = 'value';

On Thu, 26 Aug 2004 16:11:27 -0500, Miguel Guirao <[EMAIL PROTECTED]> wrote:
> Hi!!
> 
> I have a table with many options from when the user can select them,
> after that, his/her selections will be stored in a database.
> 
> In the mean time, I want to store his/her selections in an array like
> this one:
> 
> PN  DescQty
> |---|--|---|
> |---|--|---|
> |---|--|---|
> 
> How do I declare Duch an array like this??, let's call it Parts.
> 
> Miguel Guirao
> Servicios Datacard
> www.SIASA.com.mx
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> !DSPAM:412dfd2d29942082615647!
> 
> 


-- 
DB_DataObject_FormBuilder - The database at your fingertips
http://pear.php.net/package/DB_DataObject_FormBuilder

paperCrane --Justin Patrin--

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



Re: [PHP-DB] Array sorting question...

2004-01-23 Thread Kelly Hallman
On Fri, 23 Jan 2004, NIPP, SCOTT V (SBCSI) wrote:

>   I am trying to populate an array from a MySQL database.  I think I
> have the code correct to populate the array, but I need to somehow sort the
> array eliminating duplicate values.  I think I can loop through the array
> doing a comparison and building a new array by discarding the value if it is
> a duplicate, but I was not sure if there was a more efficient way of doing
> this.  I am already looping through the database query results, and I am
> just thinking about efficiency here.

First, you should see if you can optimize your SQL query to do the work 
for you, a la SELECT DISTINCT and/or ORDER BY.

Beyond that, try using an associative array. It cannot contain duplicate 
keys, and it can be sorted by key. For example, assume your data is:

$dbdata = array(
"userid"   => 10,
"display"  => "Smith, Joan",
"username" => "jsmith",
"location" => "Kalamazoo" );

$keydata = $dbdata['display'] . $dbdata['userid']; // key format
$storage[$keydata] = $dbdata;  // store data

ksort($storage);   // sort array by key
foreach($storage as $v) { print_r($v); }   // loop sorted values

In the case that you might have two Joan Smiths, the key is the display
name and the userid concatenated. It can be anything that sorts well...

>do {
>   $entry = $list['id_sys'];
>   $id = split('-', $list['id_sys'], 1);
>   $sbcuid = $id[0];
>   $users[] = '$sbcuid';  
>   } while ($list = mysql_fetch_assoc($result));
> ?>

Some problems here... you might try while() { } instead of do { } while()
which makes your loop run once without $list being set. Also, list is a
reserved word, so even if it works as a variable $list, don't do that...
Further, you mean $users[] = $sbcuid; not $users[] = '$sbcuid';

-- 
Kelly Hallman
// Ultrafancy

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



RE: [PHP-DB] Array sorting question...

2004-01-23 Thread Katie Evans-Young
NIPP, SCOTT V (SBCSI) wrote:
>   I am trying to populate an array from a MySQL database.  I think I
> have the code correct to populate the array, but I need to somehow
> sort the array eliminating duplicate values.  I think I can loop
> through the array doing a comparison and building a new array by
> discarding the value if it is a duplicate, but I was not sure if
> there was a more efficient way of doing this.

You can ask for only unique values to be returned in the database result.

Try something like this:

$sql = "SELECT UNIQUE username FROM table WHERE where_clause ORDER BY
username";

Katie Dewees
Web Developer/PHP Programmer
[EMAIL PROTECTED]
http://www.evans-young.com

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



Re: [PHP-DB] array

2003-12-11 Thread peppe
Hi
Pete I forgot to write that $acces is a field from Db and there are values
1,2,3,4
a need to split those values to make that IF
Brettking thanx mate I think that is a solution


"Brettking" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
>
> Hi
>
> From what I can work out you need to use a function called
> in_array(value,array);
> http://www.php.net/manual/en/function.in-array.php here is the php manual
> link
>
> Hope this is what you want
> Brett
> -Original Message-
> From: peppe [mailto:[EMAIL PROTECTED]
> Sent: 11 December 2003 16:07
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] array
>
>
> Hi
> I have a variable cold $access and there are values 1,2,3,4,5
> How can I check for example
> If ($access =='2'){
> echo "go further";
> }
> How can I make this work
> Thanx in advance
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
> Email has been scanned for viruses by www.emf-systems.com

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



RE: [PHP-DB] array

2003-12-11 Thread brettking

Hi

>From what I can work out you need to use a function called
in_array(value,array);
http://www.php.net/manual/en/function.in-array.php here is the php manual
link

Hope this is what you want
Brett
-Original Message-
From: peppe [mailto:[EMAIL PROTECTED]
Sent: 11 December 2003 16:07
To: [EMAIL PROTECTED]
Subject: [PHP-DB] array


Hi
I have a variable cold $access and there are values 1,2,3,4,5
How can I check for example
If ($access =='2'){
echo "go further";
}
How can I make this work
Thanx in advance

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


Email has been scanned for viruses by www.emf-systems.com

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



Re: [PHP-DB] Array question

2003-11-25 Thread CPT John W. Holmes
From: "ShortStay" <[EMAIL PROTECTED]>

> How do you delete a value and key from an array?  I know the value.

You need to know the key.

unset($Array[$key]);

There are various array functions that'll find the key for you if you know
the value.

> Is it OK to post array questions to the db list?

Not really... use php-general

---John Holmes...

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



RE: [PHP-DB] array issue

2003-08-17 Thread Aaron Wolski
Hey,

That's what we're here for :)

As for serialize? It's a great function if you need to preserve an array
in its original form.

Useful for sending back and forth between pages in the URL. Though, I'd
never use on an open URL for the general public. Maybe in an
Administration system not seen by many users.

Aaron

> -Original Message-
> From: OpenSource [mailto:[EMAIL PROTECTED]
> Sent: August 17, 2003 12:28 PM
> To: Aaron Wolski
> Cc: PHP-DB; [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] array issue
> Importance: High
> 
> Hey guys thanks a lot
> your method worked perfect Aaron, thanks
> and that serialize() function, hummm i got to go do some reading and
> testing.
> 
> thanks for enlightenment and the assistance guys.
> 
> RedHat.OpenSource.bz
> 
> - Original Message -
> From: "Aaron Wolski" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Cc: "'PHP-DB'" <[EMAIL PROTECTED]>; "'OpenSource'"
> <[EMAIL PROTECTED]>
> Sent: Sunday, August 17, 2003 10:04 AM
> Subject: RE: [PHP-DB] array issue
> 
> 
> > Good point and nice find, Jeff!
> >
> > I wasn't sure where he was going with the data.. was he trying to
save
> > the actual array, intact, for say a chaching exercise or did he want
to
> > insert the contents of that array into a file?
> >
> > Could go either way I suppose :)
> >
> > Aaron
> >
> > P.S. Working on a Sunday too?
> >
> > > -Original Message-
> > > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > > Sent: August 17, 2003 11:48 AM
> > > To: Aaron Wolski
> > > Cc: 'PHP-DB'; 'OpenSource'
> > > Subject: RE: [PHP-DB] array issue
> > >
> > >
> > > This may or may not make sense for your issue.  but if you have
the
> > whole
> > > array in memory you can serialize()  it and write the string that
the
> > > function returns to the file.
> > >
> > > $fp = fopen("yourfilename.txt", "w");
> > > $my_array_s = serialize($my_array);
> > > if (isset($fp)) {
> > >   fwrite($fp, $my_array_s);
> > > }
> > >
> > > //to get it back into the same array as it was written, use
> > > $fp_cache = fopen("yourfilename.txt", "r") or die("can't open
file");
> > > $fp_readc = fread($fp_cache, filesize("yourfilename.txt");
> > > $my_array_new = unserialize($fp_readc);
> > >
> > > the data is exactly as it was returned from the db after you
looped
> > > through
> > > the record set.
> > >
> > > another idea.
--http://www.php.net/manual/en/function.serialize.php
> > > hth
> > > jeff
> > >
> > >
> > >
> > >   "Aaron Wolski"
> > >   <[EMAIL PROTECTED]To:
> > "'OpenSource'"
> > > <[EMAIL PROTECTED]>, "'PHP-DB'" <[EMAIL PROTECTED]>
> > >   z.com>   cc:
> > >Subject:  RE:
[PHP-DB]
> > > array issue
> > >   08/17/2003 11:33
> > >   AM
> > >
> > >
> > >
> > >
> > >
> > >
> > > First, are you sure there is data in $my_array?
> > >
> > > Add this after you set the array:
> > >
> > > echo """.print_r($my_array)."";
> > >
> > > You'll need to loop through the array , writing each line in the
file
> > at
> > > a time.
> > >
> > > Something like:
> > >
> > > //open the file stuff here
> > > foreach ($my_array AS $values)
> > > {
> > >
> > >  fputs($fp, $value);
> > >
> > > }
> > > //close the file stuff here
> > >
> > > HTH
> > >
> > > Aaron
> > >
> > > > -Original Message-
> > > > From: OpenSource [mailto:[EMAIL PROTECTED]
> > > > Sent: August 17, 2003 11:31 AM
> > > > To: PHP-DB
> > > > Subject: [PHP-DB] array issue
> > > > Importance: High
> > > >
> > > > hi ya'll
> > > >
> > > > I am having a nightmare on this issue of mine.
> > > > I've got this array that I need to write to a file...
> > > >  sample code below 
> > > >
> > > > while (something);
> > > > {
> > > > query data base
> > > >
> > > > $r_ul=ifx_fetch_row($sideQuery4);
> > > >
> > > > $type1 = array($rotation."\n");
> > > >
> > > > switch ($r_ul['number'])
> > > >{
> > > > case '4';
> > > > $linea = $type1;
> > > > break;
> > > >}
> > > >
> > > > $final = $linea[0];
> > > >
> > > > $my_array = array();
> > > > array_push ($my_array, $final);
> > > >
> > > > }
> > > >
> > > > $file = 'db_dump.dat';
> > > > $fp = fopen($file, "w");
> > > > fputs($fp, $my_array); <--- I would like to write the complete
array
> > > into
> > > > the file
> > > > fclose($fp);
> > > >
> > > > kindly assist with this issue..
> > > >
> > > > Thanks in advance
> > >
> > >
> > >
> > > --
> > > PHP Database Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php




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



Re: [PHP-DB] array issue

2003-08-17 Thread OpenSource
Hey guys thanks a lot
your method worked perfect Aaron, thanks
and that serialize() function, hummm i got to go do some reading and
testing.

thanks for enlightenment and the assistance guys.

RedHat.OpenSource.bz

- Original Message - 
From: "Aaron Wolski" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: "'PHP-DB'" <[EMAIL PROTECTED]>; "'OpenSource'" <[EMAIL PROTECTED]>
Sent: Sunday, August 17, 2003 10:04 AM
Subject: RE: [PHP-DB] array issue


> Good point and nice find, Jeff!
>
> I wasn't sure where he was going with the data.. was he trying to save
> the actual array, intact, for say a chaching exercise or did he want to
> insert the contents of that array into a file?
>
> Could go either way I suppose :)
>
> Aaron
>
> P.S. Working on a Sunday too?
>
> > -Original Message-
> > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> > Sent: August 17, 2003 11:48 AM
> > To: Aaron Wolski
> > Cc: 'PHP-DB'; 'OpenSource'
> > Subject: RE: [PHP-DB] array issue
> >
> >
> > This may or may not make sense for your issue.  but if you have the
> whole
> > array in memory you can serialize()  it and write the string that the
> > function returns to the file.
> >
> > $fp = fopen("yourfilename.txt", "w");
> > $my_array_s = serialize($my_array);
> > if (isset($fp)) {
> >   fwrite($fp, $my_array_s);
> > }
> >
> > //to get it back into the same array as it was written, use
> > $fp_cache = fopen("yourfilename.txt", "r") or die("can't open file");
> > $fp_readc = fread($fp_cache, filesize("yourfilename.txt");
> > $my_array_new = unserialize($fp_readc);
> >
> > the data is exactly as it was returned from the db after you looped
> > through
> > the record set.
> >
> > another idea. --http://www.php.net/manual/en/function.serialize.php
> > hth
> > jeff
> >
> >
> >
> >   "Aaron Wolski"
> >   <[EMAIL PROTECTED]To:
> "'OpenSource'"
> > <[EMAIL PROTECTED]>, "'PHP-DB'" <[EMAIL PROTECTED]>
> >   z.com>   cc:
> >Subject:  RE: [PHP-DB]
> > array issue
> >   08/17/2003 11:33
> >   AM
> >
> >
> >
> >
> >
> >
> > First, are you sure there is data in $my_array?
> >
> > Add this after you set the array:
> >
> > echo """.print_r($my_array)."";
> >
> > You'll need to loop through the array , writing each line in the file
> at
> > a time.
> >
> > Something like:
> >
> > //open the file stuff here
> > foreach ($my_array AS $values)
> > {
> >
> >  fputs($fp, $value);
> >
> > }
> > //close the file stuff here
> >
> > HTH
> >
> > Aaron
> >
> > > -Original Message-
> > > From: OpenSource [mailto:[EMAIL PROTECTED]
> > > Sent: August 17, 2003 11:31 AM
> > > To: PHP-DB
> > > Subject: [PHP-DB] array issue
> > > Importance: High
> > >
> > > hi ya'll
> > >
> > > I am having a nightmare on this issue of mine.
> > > I've got this array that I need to write to a file...
> > >  sample code below 
> > >
> > > while (something);
> > > {
> > > query data base
> > >
> > > $r_ul=ifx_fetch_row($sideQuery4);
> > >
> > > $type1 = array($rotation."\n");
> > >
> > > switch ($r_ul['number'])
> > >{
> > > case '4';
> > > $linea = $type1;
> > > break;
> > >}
> > >
> > > $final = $linea[0];
> > >
> > > $my_array = array();
> > > array_push ($my_array, $final);
> > >
> > > }
> > >
> > > $file = 'db_dump.dat';
> > > $fp = fopen($file, "w");
> > > fputs($fp, $my_array); <--- I would like to write the complete array
> > into
> > > the file
> > > fclose($fp);
> > >
> > > kindly assist with this issue..
> > >
> > > Thanks in advance
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> >
> >
>
>
>
>
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


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



RE: [PHP-DB] array issue

2003-08-17 Thread Aaron Wolski
Good point and nice find, Jeff!

I wasn't sure where he was going with the data.. was he trying to save
the actual array, intact, for say a chaching exercise or did he want to
insert the contents of that array into a file?

Could go either way I suppose :)

Aaron

P.S. Working on a Sunday too?

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> Sent: August 17, 2003 11:48 AM
> To: Aaron Wolski
> Cc: 'PHP-DB'; 'OpenSource'
> Subject: RE: [PHP-DB] array issue
> 
> 
> This may or may not make sense for your issue.  but if you have the
whole
> array in memory you can serialize()  it and write the string that the
> function returns to the file.
> 
> $fp = fopen("yourfilename.txt", "w");
> $my_array_s = serialize($my_array);
> if (isset($fp)) {
>   fwrite($fp, $my_array_s);
> }
> 
> //to get it back into the same array as it was written, use
> $fp_cache = fopen("yourfilename.txt", "r") or die("can't open file");
> $fp_readc = fread($fp_cache, filesize("yourfilename.txt");
> $my_array_new = unserialize($fp_readc);
> 
> the data is exactly as it was returned from the db after you looped
> through
> the record set.
> 
> another idea. --http://www.php.net/manual/en/function.serialize.php
> hth
> jeff
> 
> 
> 
>   "Aaron Wolski"
>   <[EMAIL PROTECTED]    To:
"'OpenSource'"
> <[EMAIL PROTECTED]>, "'PHP-DB'" <[EMAIL PROTECTED]>
>   z.com>   cc:
>Subject:  RE: [PHP-DB]
> array issue
>   08/17/2003 11:33
>   AM
> 
> 
> 
> 
> 
> 
> First, are you sure there is data in $my_array?
> 
> Add this after you set the array:
> 
> echo """.print_r($my_array)."";
> 
> You'll need to loop through the array , writing each line in the file
at
> a time.
> 
> Something like:
> 
> //open the file stuff here
> foreach ($my_array AS $values)
> {
> 
>  fputs($fp, $value);
> 
> }
> //close the file stuff here
> 
> HTH
> 
> Aaron
> 
> > -Original Message-
> > From: OpenSource [mailto:[EMAIL PROTECTED]
> > Sent: August 17, 2003 11:31 AM
> > To: PHP-DB
> > Subject: [PHP-DB] array issue
> > Importance: High
> >
> > hi ya'll
> >
> > I am having a nightmare on this issue of mine.
> > I've got this array that I need to write to a file...
> >  sample code below 
> >
> > while (something);
> > {
> > query data base
> >
> > $r_ul=ifx_fetch_row($sideQuery4);
> >
> > $type1 = array($rotation."\n");
> >
> > switch ($r_ul['number'])
> >{
> > case '4';
> > $linea = $type1;
> > break;
> >}
> >
> > $final = $linea[0];
> >
> > $my_array = array();
> > array_push ($my_array, $final);
> >
> > }
> >
> > $file = 'db_dump.dat';
> > $fp = fopen($file, "w");
> > fputs($fp, $my_array); <--- I would like to write the complete array
> into
> > the file
> > fclose($fp);
> >
> > kindly assist with this issue..
> >
> > Thanks in advance
> 
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 
> 
> 




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



RE: [PHP-DB] array issue

2003-08-17 Thread jeffrey_n_Dyke

This may or may not make sense for your issue.  but if you have the whole
array in memory you can serialize()  it and write the string that the
function returns to the file.

$fp = fopen("yourfilename.txt", "w");
$my_array_s = serialize($my_array);
if (isset($fp)) {
  fwrite($fp, $my_array_s);
}

//to get it back into the same array as it was written, use
$fp_cache = fopen("yourfilename.txt", "r") or die("can't open file");
$fp_readc = fread($fp_cache, filesize("yourfilename.txt");
$my_array_new = unserialize($fp_readc);

the data is exactly as it was returned from the db after you looped through
the record set.

another idea. --http://www.php.net/manual/en/function.serialize.php
hth
jeff


   

  "Aaron Wolski"   

  <[EMAIL PROTECTED]To:   "'OpenSource'" <[EMAIL 
PROTECTED]>, "'PHP-DB'" <[EMAIL PROTECTED]>  
  z.com>   cc:                 

   Subject:  RE: [PHP-DB] array issue  

  08/17/2003 11:33 

  AM   

   

   





First, are you sure there is data in $my_array?

Add this after you set the array:

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

You'll need to loop through the array , writing each line in the file at
a time.

Something like:

//open the file stuff here
foreach ($my_array AS $values)
{

 fputs($fp, $value);

}
//close the file stuff here

HTH

Aaron

> -Original Message-
> From: OpenSource [mailto:[EMAIL PROTECTED]
> Sent: August 17, 2003 11:31 AM
> To: PHP-DB
> Subject: [PHP-DB] array issue
> Importance: High
>
> hi ya'll
>
> I am having a nightmare on this issue of mine.
> I've got this array that I need to write to a file...
>  sample code below 
>
> while (something);
> {
> query data base
>
> $r_ul=ifx_fetch_row($sideQuery4);
>
> $type1 = array($rotation."\n");
>
> switch ($r_ul['number'])
>{
> case '4';
> $linea = $type1;
> break;
>}
>
> $final = $linea[0];
>
> $my_array = array();
> array_push ($my_array, $final);
>
> }
>
> $file = 'db_dump.dat';
> $fp = fopen($file, "w");
> fputs($fp, $my_array); <--- I would like to write the complete array
into
> the file
> fclose($fp);
>
> kindly assist with this issue..
>
> Thanks in advance



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






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



RE: [PHP-DB] array issue

2003-08-17 Thread Aaron Wolski
First, are you sure there is data in $my_array?

Add this after you set the array:

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

You'll need to loop through the array , writing each line in the file at
a time.

Something like:

//open the file stuff here
foreach ($my_array AS $values)
{

fputs($fp, $value);

}
//close the file stuff here

HTH

Aaron

> -Original Message-
> From: OpenSource [mailto:[EMAIL PROTECTED]
> Sent: August 17, 2003 11:31 AM
> To: PHP-DB
> Subject: [PHP-DB] array issue
> Importance: High
> 
> hi ya'll
> 
> I am having a nightmare on this issue of mine.
> I've got this array that I need to write to a file...
>  sample code below 
> 
> while (something);
> {
> query data base
> 
> $r_ul=ifx_fetch_row($sideQuery4);
> 
> $type1 = array($rotation."\n");
> 
> switch ($r_ul['number'])
>{
> case '4';
> $linea = $type1;
> break;
>}
> 
> $final = $linea[0];
> 
> $my_array = array();
> array_push ($my_array, $final);
> 
> }
> 
> $file = 'db_dump.dat';
> $fp = fopen($file, "w");
> fputs($fp, $my_array); <--- I would like to write the complete array
into
> the file
> fclose($fp);
> 
> kindly assist with this issue..
> 
> Thanks in advance



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



Re: [PHP-DB] array fill/sort question

2003-06-11 Thread Sean Burlington
Snijders, Mark wrote:
hi,

no the both sollutions won't work cause:

I can't sort within a query cause subnetaddr is a varchar ("10.10.10.10")

so it will be ordere like this

10.10.10.10
100.10.10.10
60.10.10.10
and that's not good cause 60 is smaller as 100, so with the function
ip2long() i will first make an integer of it
the second array solution you gave, won't work, cause I need ALL the query
results in the array, and that's the problem I can't handle
if I would do it like you said, I can sort it, but then I have a sorted
array and for each element I have to do a query again to get the other
fields of the table, and that's not good (2500 rows)
so can please still somebody help me with this?


can you change the database format ?

store the address  as four ints - then you can concatenate them when you 
need to, and sort as you wish

SELECT s_id, subnet_name, concat(subnetaddr1, '.', subnetaddr2, '.', 
subnetaddr3, '.', subnetaddr4) as subnetaddr ,subnetmask,dnsdomain, 
location, contact, ccn
FROM subnets
ORDER BY subnetaddr1, subnetaddr2, subnetaddr3, subnetaddr4;

--

Sean

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


Re: [PHP-DB] array fill/sort question

2003-06-11 Thread Ignatius Reilly
Another approach:

1. Load all results from the query in an array
2. Sort the array using a custom-defined user-defined comparison function
( usort() ). Study the example in the PHP manual.
Writing your own comparison function is easy:
- explode your IP addresses in 4 items each ( explode() )
- compare successively item by item

HTH
Ignatius
_
- Original Message -
From: "Snijders, Mark" <[EMAIL PROTECTED]>
To: "'Becoming Digital'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, June 11, 2003 8:33 AM
Subject: RE: [PHP-DB] array fill/sort question


> hi,
>
> no the both sollutions won't work cause:
>
> I can't sort within a query cause subnetaddr is a varchar ("10.10.10.10")
>
> so it will be ordere like this
>
> 10.10.10.10
> 100.10.10.10
> 60.10.10.10
>
> and that's not good cause 60 is smaller as 100, so with the function
> ip2long() i will first make an integer of it
>
>
> the second array solution you gave, won't work, cause I need ALL the query
> results in the array, and that's the problem I can't handle
>
>
> if I would do it like you said, I can sort it, but then I have a sorted
> array and for each element I have to do a query again to get the other
> fields of the table, and that's not good (2500 rows)
>
> so can please still somebody help me with this?
>
>
>
>
> -Original Message-
> From: Becoming Digital [mailto:[EMAIL PROTECTED]
> Sent: dinsdag 10 juni 2003 15:42
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] array fill/sort question
>
>
> I might be overlooking something, but can't you just do this?
>
> $query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain,
> location, contact, ccn FROM subnets ORDER BY subnetaddr";
>
>
> If you can't, you can sort the array like this.
>
>  $query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain,
> location, contact, ccn FROM subnets";
> $results = mysql_query( $query );
>
> while ( $iptable = mysql_fetch_array( $result ) ) {
> $iptable['subnetaddr'] = ip2long( $iptable['subnetaddr'] );
> }
> ?>
>
> You can subsequently sort the array for the desired result.
>
> Edward Dudlik
> Becoming Digital
> www.becomingdigital.com
>
>
> - Original Message -
> From: "Snijders, Mark" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>
> Sent: Tuesday, 10 June, 2003 08:55
> Subject: [PHP-DB] array fill/sort question
>
>
> hi,
>
> I'm working on a ipaddres/subnet programm
>
> now i have a talbe with a lot of information about ip-addresses
>
> i'm having this query:
>
> SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location,
contact,
> ccn FROM subnets
>
> the subnetaddr field looks like this : 100.20.20.1  and is ofcourse a
> varchar field
>
> BUT before displaying it on the screen i have to sort it by subnetaddr and
> then show it
>
> but i have to sort it as integer, so i use the php-function ip2long();
>
> so you get a decimal...
>
> so what i have to do:
>
> do the query> make a decimal field of the 'subnetaddr' put it in an array,
> sort it and display it
>
>
> BUT how can i put ALL of the fields in the query in an array, sort it, and
> then display it?
>
> please help me, I can't work it out :(
>
> thanks, Mark
>
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>


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



RE: [PHP-DB] array fill/sort question

2003-06-10 Thread Snijders, Mark
hi,

no the both sollutions won't work cause:

I can't sort within a query cause subnetaddr is a varchar ("10.10.10.10")

so it will be ordere like this

10.10.10.10
100.10.10.10
60.10.10.10

and that's not good cause 60 is smaller as 100, so with the function
ip2long() i will first make an integer of it


the second array solution you gave, won't work, cause I need ALL the query
results in the array, and that's the problem I can't handle


if I would do it like you said, I can sort it, but then I have a sorted
array and for each element I have to do a query again to get the other
fields of the table, and that's not good (2500 rows)

so can please still somebody help me with this?




-Original Message-
From: Becoming Digital [mailto:[EMAIL PROTECTED]
Sent: dinsdag 10 juni 2003 15:42
To: [EMAIL PROTECTED]
Subject: Re: [PHP-DB] array fill/sort question


I might be overlooking something, but can't you just do this?

$query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain,
location, contact, ccn FROM subnets ORDER BY subnetaddr";


If you can't, you can sort the array like this.



You can subsequently sort the array for the desired result.

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message - 
From: "Snijders, Mark" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, 10 June, 2003 08:55
Subject: [PHP-DB] array fill/sort question


hi,

I'm working on a ipaddres/subnet programm

now i have a talbe with a lot of information about ip-addresses

i'm having this query:

SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact,
ccn FROM subnets

the subnetaddr field looks like this : 100.20.20.1  and is ofcourse a
varchar field

BUT before displaying it on the screen i have to sort it by subnetaddr and
then show it

but i have to sort it as integer, so i use the php-function ip2long();

so you get a decimal...

so what i have to do:

do the query> make a decimal field of the 'subnetaddr' put it in an array,
sort it and display it


BUT how can i put ALL of the fields in the query in an array, sort it, and
then display it?

please help me, I can't work it out :(

thanks, Mark




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



Re: [PHP-DB] array fill/sort question

2003-06-10 Thread Becoming Digital
I might be overlooking something, but can't you just do this?

$query = "SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain,
location, contact, ccn FROM subnets ORDER BY subnetaddr";


If you can't, you can sort the array like this.



You can subsequently sort the array for the desired result.

Edward Dudlik
Becoming Digital
www.becomingdigital.com


- Original Message - 
From: "Snijders, Mark" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, 10 June, 2003 08:55
Subject: [PHP-DB] array fill/sort question


hi,

I'm working on a ipaddres/subnet programm

now i have a talbe with a lot of information about ip-addresses

i'm having this query:

SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact,
ccn FROM subnets

the subnetaddr field looks like this : 100.20.20.1  and is ofcourse a
varchar field

BUT before displaying it on the screen i have to sort it by subnetaddr and
then show it

but i have to sort it as integer, so i use the php-function ip2long();

so you get a decimal...

so what i have to do:

do the query> make a decimal field of the 'subnetaddr' put it in an array,
sort it and display it


BUT how can i put ALL of the fields in the query in an array, sort it, and
then display it?

please help me, I can't work it out :(

thanks, Mark




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



Re: [PHP-DB] array fill/sort question

2003-06-10 Thread Kieu D. Trang
hi,

you can add the ip2long() function into your SELECT statement and have
an ORDER BY clause at the end like this...

SELECT s_id, subnet_name, ip2long('subnetaddr'), subnetmask,dnsdomain,
location, contact, ccn FROM subnets ORDER BY subnetaddrr;

hope it helps.
KD


On Tue, 10 Jun 2003, Snijders, Mark wrote:

> hi,
>
> I'm working on a ipaddres/subnet programm
>
> now i have a talbe with a lot of information about ip-addresses
>
> i'm having this query:
>
> SELECT s_id, subnet_name,subnetaddr,subnetmask,dnsdomain, location, contact,
> ccn FROM subnets
>
> the subnetaddr field looks like this : 100.20.20.1  and is ofcourse a
> varchar field
>
> BUT before displaying it on the screen i have to sort it by subnetaddr and
> then show it
>
> but i have to sort it as integer, so i use the php-function ip2long();
>
> so you get a decimal...
>
> so what i have to do:
>
> do the query> make a decimal field of the 'subnetaddr' put it in an array,
> sort it and display it
>
>
> BUT how can i put ALL of the fields in the query in an array, sort it, and
> then display it?
>
> please help me, I can't work it out :(
>
> thanks, Mark
>
>

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



Re: [PHP-DB] Array Pointer

2003-06-05 Thread Chris Mach
My database is set up in this way:

fan_roster: has player id (play_id) , week, and stats on that player for
that week. So there are 20 records for each player, because there are 20
weeks.

So what I need to do is add up all the players weekly totals. so pass_yrd1
for week1 + pass_yrd1 for week2 etc.

Then I need to put the season total for that players passing yards into my
roster table under pass_yrd. The roster table only as 1 record per player
and has season stats instead of weekly stats.

So when my loop goes through and doesn't match $i with ros_id. I need to
advance $i one but ros_id needs to stay the same until there is a match.

As you can see form this url:
http://55yardline.cflmain.com/55main/2003/fantasy/tests/update.php
it's kind of working, except where there are holes in the roster table..
for example, there is no ros_id equal to 12 so it should echo "12 no player"
but it seems to skip.

Hope that makes sense.


"Mike Ford" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> > -Original Message-
> > From: Ian Fingold [mailto:[EMAIL PROTECTED]
> > Sent: 03 June 2003 16:58
> >
> > Ok I'm trying to write this function to up date some fields
> > in my database
> > so i'm grabbing some info from a query and throwing it into
> > an array (with
> > mysql_fetch_array).
> >
> > one of the values i'm puting into that array is the table id. I'm then
> > comparing the table id with the value of $i in my loop. Now
> > my problem is
> > when I loop through and the table id is not equal to $i I
> > need to add 1 to
> > $i but I need to move the array pointer back one.
> >
> > In the code below I used prev() but i'm getting warnings
> > about the "Passed
> > variable is not an array".
> > http://55yardline.cflmain.com/55main/2003/fantasy/tests/update.php
> >
> > I'm thinking that prev() must not view an array fetch from a
> > database the
> > same or something. But what else can I use besides prev() to
> > rewind the
> > pointer by 1?
> >
> > Thanks,
> >
> >
> >  >
> > include "function.php";
> > connect1();
> >
> > //query roster database and put results into an array.
> > $num1 = mysql_query("SELECT * FROM roster");
> > $num2 = mysql_fetch_array($num1);
> > //set i to zero
> > $i = 0;
> >
> > //start loop to determine if $i matches the current roster id
> > do {
> >   $i = $i + 1;
> >   if ($num2["ros_id"] == $i) {
> > //if a match is found, query the fan_roster database
> > where the play_id =
> > $i
> > //and put the results into a array
> > $upd = mysql_query("SELECT * FROM fan_roster WHERE play_id='$i'");
> > $updr = mysql_fetch_array($upd);
> > //loop through the passing field and add them up
> > do {
> > $passing = $passing + $updr["pass_yrd1"];
> > } while($updr = mysql_fetch_array($upd));
> >
> > //Print feedback
> > echo "Player:$i total Passing: $passing $updr[play_id]";
> >
> > //update the roster table with the total $passing where ros_id=$i
> > $upd1 = mysql_query("UPDATE roster SET pass_yrd='$passing' WHERE
> > ros_id='$i'");
> > //reset passing for next loop
> > $passing = 0;
> >   } else {
> > //if there isn't a match, add 1 to $i
> > $i = $i + 1;
> >
> > //print feedback
> > echo "$i no player";
> >
> > //put the array pointer back one for next loop
> > $num2 = prev($num2["ros_id"];
>
> (1) prev() takes an array as its argument, not an individual element, so
prev($num2) would be syntactically correct (but I doubt it's what you really
mean).
> (2) anyway, this whole statement is pointless as you immediately do:
>
> >   }
> > } while($num2 = mysql_fetch_array($num1));
>
> Which promptly overwrites the value of $num2 you just put there!
>
> What are you *really* trying to do?
> > ?>
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >



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



RE: [PHP-DB] Array Pointer

2003-06-04 Thread Ford, Mike [LSS]
> -Original Message-
> From: Ian Fingold [mailto:[EMAIL PROTECTED]
> Sent: 03 June 2003 16:58
> 
> Ok I'm trying to write this function to up date some fields 
> in my database
> so i'm grabbing some info from a query and throwing it into 
> an array (with
> mysql_fetch_array).
> 
> one of the values i'm puting into that array is the table id. I'm then
> comparing the table id with the value of $i in my loop. Now 
> my problem is
> when I loop through and the table id is not equal to $i I 
> need to add 1 to
> $i but I need to move the array pointer back one.
> 
> In the code below I used prev() but i'm getting warnings 
> about the "Passed
> variable is not an array".
> http://55yardline.cflmain.com/55main/2003/fantasy/tests/update.php
> 
> I'm thinking that prev() must not view an array fetch from a 
> database the
> same or something. But what else can I use besides prev() to 
> rewind the
> pointer by 1?
> 
> Thanks,
> 
> 
>  
> include "function.php";
> connect1();
> 
> //query roster database and put results into an array.
> $num1 = mysql_query("SELECT * FROM roster");
> $num2 = mysql_fetch_array($num1);
> //set i to zero
> $i = 0;
> 
> //start loop to determine if $i matches the current roster id
> do {
>   $i = $i + 1;
>   if ($num2["ros_id"] == $i) {
> //if a match is found, query the fan_roster database 
> where the play_id =
> $i
> //and put the results into a array
> $upd = mysql_query("SELECT * FROM fan_roster WHERE play_id='$i'");
> $updr = mysql_fetch_array($upd);
> //loop through the passing field and add them up
> do {
> $passing = $passing + $updr["pass_yrd1"];
> } while($updr = mysql_fetch_array($upd));
> 
> //Print feedback
> echo "Player:$i total Passing: $passing $updr[play_id]";
> 
> //update the roster table with the total $passing where ros_id=$i
> $upd1 = mysql_query("UPDATE roster SET pass_yrd='$passing' WHERE
> ros_id='$i'");
> //reset passing for next loop
> $passing = 0;
>   } else {
> //if there isn't a match, add 1 to $i
> $i = $i + 1;
> 
> //print feedback
> echo "$i no player";
> 
> //put the array pointer back one for next loop
> $num2 = prev($num2["ros_id"];

(1) prev() takes an array as its argument, not an individual element, so prev($num2) 
would be syntactically correct (but I doubt it's what you really mean).
(2) anyway, this whole statement is pointless as you immediately do:

>   }
> } while($num2 = mysql_fetch_array($num1));

Which promptly overwrites the value of $num2 you just put there!

What are you *really* trying to do?
> ?>
> 
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 

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



Re: [PHP-DB] Array Question

2003-06-03 Thread CPT John W. Holmes
> Hello everyone.  If I wanted to pass a item ID along with a quantity to an
> associative array called "CartArray" how would I pass it to the PHP
script?
>
> I'll get this shopping cart working yet !!

If the question is how do you pass an array to another PHP page, you
serialize() and urlencode() it, then pass it in the URL. On the following
page you unserialize() it.

---John Holmes...


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



RE: [PHP-DB] Array Question

2003-06-03 Thread Gary . Every
JaYup you could do that or:

$CartArray = array(
'itemid'=>'$itemid',
'qty'=>'$qty'
);

That's one way, the other is what I said earlier:

$CartArray can also be multiple arrays, done thusly:
$CartArray[0]['itemid']="1";
$CartArray[0]['qty']="24";

$CartArray[1]['itemid']="2";
$CartArray[1]['qty']="32";

Now, $CartArray[0] has an itemid and a qty and $CartArray[1] does too.

Substitute the numeric subs for, say, shopping cart id's or something as
well:
$CartArray['userid1']['itemid']="1";
$CartArray['userid1']['qty']="24";

$CartArray['userid2']['itemid']="2";
$CartArray['userid2']['qty']="32";



Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:[EMAIL PROTECTED]
http://accessingram.com


> -Original Message-
> From: Boa Constructor [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 02, 2003 2:39 PM
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP-DB] Array Question
> 
> 
> RE: [PHP-DB] Array QuestionCheers Gary, and in the html would 
> I put something like:
> 
> buy this item
> 
> Simple question I know!
> 
> 
> Jay, yup thats all I want to do, just assign two values into an array.
> 
> 
> Thank you,
> 
> Graeme :)
>   - Original Message - 
>   From: [EMAIL PROTECTED] 
>   To: [EMAIL PROTECTED] ; [EMAIL PROTECTED] 
>   Sent: Monday, June 02, 2003 8:30 PM
>   Subject: RE: [PHP-DB] Array Question
> 
> 
>   CartArray['itemid'] = $itemid; 
> 
>
>   where $qty = CartArray['qty']; 
>
> 
> 
> 
>   Gary Every 
>   Sr. UNIX Administrator 
>   Ingram Entertainment 
>   (615) 287-4876 
>   "Pay It Forward" 
>   mailto:[EMAIL PROTECTED] 
>   http://accessingram.com 
> 
> 
> 
>   > -Original Message- 
>   > From: Boa Constructor [mailto:[EMAIL PROTECTED] 
>   > Sent: Monday, June 02, 2003 2:27 PM 
>   > To: [EMAIL PROTECTED] 
>   > Subject: [PHP-DB] Array Question 
>   > 
>   > 
>   > Hello everyone.  If I wanted to pass a item ID along with a 
>   > quantity to an 
>   > associative array called "CartArray" how would I pass it to 
>   > the PHP script? 
>   > 
>   > I'll get this shopping cart working yet !! 
>   > 
>   > Cheers, 
>   > 
>   > Graeme :) 
>   > 
>   > 
>   > -- 
>   > PHP Database Mailing List (http://www.php.net/) 
>   > To unsubscribe, visit: http://www.php.net/unsub.php 
>   > 
> 


Re: [PHP-DB] Array Question

2003-06-03 Thread Boa Constructor
RE: [PHP-DB] Array QuestionCheers Gary, and in the html would I put something like:

buy this item

Simple question I know!


Jay, yup thats all I want to do, just assign two values into an array.


Thank you,

Graeme :)
  - Original Message - 
  From: [EMAIL PROTECTED] 
  To: [EMAIL PROTECTED] ; [EMAIL PROTECTED] 
  Sent: Monday, June 02, 2003 8:30 PM
  Subject: RE: [PHP-DB] Array Question


  CartArray['itemid'] = $itemid; 

   
  where $qty = CartArray['qty']; 
   



  Gary Every 
  Sr. UNIX Administrator 
  Ingram Entertainment 
  (615) 287-4876 
  "Pay It Forward" 
  mailto:[EMAIL PROTECTED] 
  http://accessingram.com 



  > -Original Message- 
  > From: Boa Constructor [mailto:[EMAIL PROTECTED] 
  > Sent: Monday, June 02, 2003 2:27 PM 
  > To: [EMAIL PROTECTED] 
  > Subject: [PHP-DB] Array Question 
  > 
  > 
  > Hello everyone.  If I wanted to pass a item ID along with a 
  > quantity to an 
  > associative array called "CartArray" how would I pass it to 
  > the PHP script? 
  > 
  > I'll get this shopping cart working yet !! 
  > 
  > Cheers, 
  > 
  > Graeme :) 
  > 
  > 
  > -- 
  > PHP Database Mailing List (http://www.php.net/) 
  > To unsubscribe, visit: http://www.php.net/unsub.php 
  > 


RE: [PHP-DB] Array Question

2003-06-03 Thread Gary . Every
CartArray['itemid'] = $itemid;


where $qty = CartArray['qty'];



Gary Every
Sr. UNIX Administrator
Ingram Entertainment
(615) 287-4876
"Pay It Forward"
mailto:[EMAIL PROTECTED]
http://accessingram.com


> -Original Message-
> From: Boa Constructor [mailto:[EMAIL PROTECTED]
> Sent: Monday, June 02, 2003 2:27 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Array Question
> 
> 
> Hello everyone.  If I wanted to pass a item ID along with a 
> quantity to an
> associative array called "CartArray" how would I pass it to 
> the PHP script?
> 
> I'll get this shopping cart working yet !!
> 
> Cheers,
> 
> Graeme :)
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


Re: [PHP-DB] Array key problem

2003-02-25 Thread Jason Wong
On Wednesday 26 February 2003 00:37, Jorge Miguel Fonseca Martins wrote:

As this has nothing to do with databases you should post to the php-general 
list.

>  $test[]="a";
>  $test[]="b";
>
>  foreach ($test as $key=>$value)
>  {
>   if($key == "something") echo $key
>  }
>
> even though theres no key in the array named "something" the code will
> print the key "0"

PHP is doing automatic type conversion for you. Use:

  if ($key === "something" { ... }

instead. See manual for details.

-- 
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-db
--
/*
If I were a grave-digger or even a hangman, there are some people I could
work for with a great deal of enjoyment.
-- Douglas Jerrold
*/


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



RE: [PHP-DB] array with two dimensions

2003-02-17 Thread Kelly Protsko
There are really a few ways that you can solve this problem. I would use
and associative array to do this. 

Making the array associative would work like this:
$ALL_VALUES["$year"] += $value;

To retrieve the information back you would use the following loop:

While($element = each($ALL_VALUES))
{
echo $element[ "key" ]; //this would display the year
echo $element[ "value" ]; //displays the value associated with
the year

}

Hope that helps, I have tested it and it works for me

Kelly Protsko


-Original Message-
From: Lars Rasmussen [mailto:[EMAIL PROTECTED]] 
Sent: February 17, 2003 8:28 AM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] array with two dimensions

Hi all,
 
Got a little problem here,
 
I have a mysql query that looks like this
SELECT SUM(value) as value, YEAR(dileveret) as year FROM table GROUP BY
YEAR(dileveret)
 
It works just fine, but i need to make a array that can could do
somthing like this (know it doesent work)
$ALL_VALUES[$year] += $value;
 
The script is running the script up to 100 times to get all the specific
data's, i hope that you know a way that i can hold the values, and year
and later print one value for each year..
 
THANKS A LOT!
 
Regards
Lasse (newbie)



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




Re: [PHP-DB] Array trouble

2003-01-24 Thread Jason Wong
On Friday 24 January 2003 14:18, Tyler Whitesides wrote:

> I have been having a lot of trouble getting an array into the MySQL table
> like I want it.  This is supposed to take the current maintenance tasks
> from a table in the database on apple.php each of these is given a name
> $item[autoNo] where autoNo is the auto_increment id that task is associated
> with.  This is passed to data.php where it is supposed to make a row in the
> maintenanceditems table, then in a loop directly below that it is supposed
> to run the array and place each array value into its associated column in
> the database.  Considering all of the columns exist, I think the problem
> just has to do with how I am pulling the array values out and placing them
> into their column.  Any help would be appreciated. Thanks in advance,

Please post your code and DB schema.

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


/*
Don't worry if you're a kleptomaniac; you can always take something for it.
*/


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




Re: [PHP-DB] Array problems

2003-01-22 Thread Paul Burney
on 1/22/03 12:08 AM, Michael Conway at [EMAIL PROTECTED] appended the
following bits to my mbox:

> I find myself stuck in coming up with a way to cycle through this
> array of db results for porting to a graphing script that I did not
> write.  My latest attempt to get around this problem is below.  Outside
> of the $graph->SetDataValues(array( ));, echoing $array[$i] produces the
> desired results for three sets of two bar graphs with the corresponding
> title.  However, inside the $graph function, I get only the last
> expected set of bar graphs and title.  I originally iterated through
> each anticipated result from mysql_fetch_array($result) and plugged each
> of these values into an array calling the columns individually. I got
> the desired graph, but, of course this is bad programming and not useful
> for queries producing a greater number of rows (I simply needed to know
> it worked).  Any help would be appreciated.

What exactly is the Graph class expecting in terms of data?  Is it supposed
to generate several graphs when you give it the data, or one graph per
specified dataset?

If it's the latter, move the $graph->DrawGraph(); call inside your while
loop. 

If not, let us know what format it needs the data in and we'll help you
figure out how to get it from the database into that format.

If you can't figure out what format of data the class needs, you should let
us see the graph class source.

HTH.

Sincerely,

Paul Burney
http://paulburney.com/




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




Re: [PHP-DB] Array Issue help please

2003-01-20 Thread Jason Wong
On Monday 20 January 2003 17:50, Dave Carrera wrote:

> I have nearly got this working but it dose not seem to loop though or
> return the result
>
> I have done something wrong and I ask one of you coders that are much
> cleverer that I to glance over my code to see the obvious mistake / s.

Can you describe in more detail how your code doesn't behave the way you 
expected it to behave? 

So do you see anything at all?

What exactly does it do?

Error messages?

Have you checked the logs?

Have you tried echo() on the important variables to see what they contain?

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


/*
The last time I saw him he was walking down Lover's Lane holding his own hand.
-- Fred Allen
*/


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




Re: [PHP-DB] Array help please

2003-01-19 Thread Peter Beckman

$arr = array(".co.uk",".com",".net",".me.uk");
echo "Top Level Domains: ";
while(list(,$tld)=each($arr)) {
   echo $tld.", ";
}

On Sun, 19 Jan 2003, Dave Carrera wrote:

> Hi All
> I am trying to create a tld lookup script for uk and main us domains.
>
> I have success by creating multiple function hardcode the whois server
> and tld but I would love to be able to make an array of tlds then step
> through the array to check availability of domain.
>
> Example
>
> $arr = array(‘.co.uk’,’.com’,’.net’,’.me.uk’);
>
> How do I step though one at a time and give a viewable result?
>
> I know I have to check the value of the array and assign the relevant
> whois server. How do I do that?
>
> Any help, guidance, code examples will be very much appreciated.
>
> Thank you in advance as always
>
> Dave Carrera
>
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.443 / Virus Database: 248 - Release Date: 10/01/2003
>
>

---
Peter Beckman  Internet Guy
[EMAIL PROTECTED] http://www.purplecow.com/
---

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




Re: [PHP-DB] array sorting

2002-11-12 Thread Ignatius Reilly
Just loop through the first index, then search on the second index:

while ( list( $key, $value ) = each( $my_arr ) ) {

// now $value is your ( [0] => 10 [1] => 40 [2] => 50 [3] => 80 [4] =>
130 [5] => 220 [6] => 320 ) array
// sort your array by values
sort( $value ) ;
// get the last value
$last_value = array_pop( $value ) ;
// do something with this value...

}

But it seems to me there still misses a link between your two series of data
(years, values)

So try to get an array where keys are years, not numerical indexes?

HTH
Ignatius

- Original Message -
From: "Martin Allan Jensen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 12, 2002 1:37 PM
Subject: [PHP-DB] array sorting


Hi everyone...


I got a bit longer now..

But i have some trouble sorting my arrays

I get this array returned.

Array ( [0] => Array ( [0] => 10 [1] => 40 [2] => 50 [3] => 80 [4] => 130
[5] => 220 [6] => 320 ) [1] => Array ( [0] => 10 [1] => 40 [2] => 50 [3] =>
80 [4] => 130 [5] => 220 [6] => 320 [7] => 440 [8] => 570 ) [2] => )

I ain't good at it, but i guess this is a two dimesioned array...

The question is now,  i need to get the highest values of each "sub" array
witch would be 320 & 570 in THIS CASE ??

Thanks so much!!

Martin Allan Jensen


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




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




Re: [PHP-DB] Array question

2002-11-08 Thread Maxim Maletsky
to precise:

$array = Array('name'=>'Maxim', 'surname'=>'Maletsky');

unset($array['name']);

// now array has this structure:
// Array('surname'=>'Maletsky')


--
Maxim Maletsky
[EMAIL PROTECTED]



Jason Wong <[EMAIL PROTECTED]> wrote... :

> On Friday 08 November 2002 17:25, nikos wrote:
> > Does anybody know how to remove an item from an array?
> > Let's say
> >
> > $array('banna', 'apple','cherry')
> > foreach ($array as $value) {
> > if ($value=='chery') DELETE $value FROM $array
> > ...
> 
> unset().
> 
> 
> -- 
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications Development *
> 
> 
> /*
> Kiss me, Kate, we will be married o' Sunday.
>   -- William Shakespeare, "The Taming of the Shrew"
> */
> 
> 
> -- 
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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




Re: [PHP-DB] Array question

2002-11-08 Thread Jason Wong
On Friday 08 November 2002 17:25, nikos wrote:
> Does anybody know how to remove an item from an array?
> Let's say
>
> $array('banna', 'apple','cherry')
> foreach ($array as $value) {
> if ($value=='chery') DELETE $value FROM $array
> ...

unset().


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


/*
Kiss me, Kate, we will be married o' Sunday.
-- William Shakespeare, "The Taming of the Shrew"
*/


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




RE: [PHP-DB] Array Initialization

2002-10-13 Thread John W. Holmes

$newInfo[$stripped] = $value;

---John Holmes...

> -Original Message-
> From: Rich Hutchins [mailto:[EMAIL PROTECTED]]
> Sent: Sunday, October 13, 2002 3:42 PM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Array Initialization
> 
> Please forgive me ahead of time, but I didn't want to subscribe to the
> high-vol general list for a single question. Actually, I need this to
prep
> data to be passed to a db, so it's kind of close.
> 
> I have a variable number of hidden fields being passed from page A
into
> page
> B via POST. On page B, I want to take those hidden fields and turn
them
> into
> an associative array. I am able to get the data out of the
$HTTP_POST_VARS
> and make it look the way I want with the following code:
> 
> 
> 
> 
>   foreach ($HTTP_POST_VARS as $key => $value) {
>   if (preg_match("/mySelect_/", $key ))
>   {
>   echo("Found a match.");
>   $stripped = substr_replace($key, "", 0, 9);
>   echo("Content ID=".$stripped."");
>   echo("Its text value is: ".$value);
>   echo("");
> 
>   $newInfo = array($stripped => $value);
>   }
>   }
> 
>   print_r($newInfo);
> 
> The resulting sample HTML data looks like this:
> Found a match.
> Content ID=10
> Its text value is: Miami
> 
> Found a match.
> Content ID=20
> Its text value is: New England
> 
> Found a match.
> Content ID=30
> Its text value is: Buffalo
> 
> Found a match.
> Content ID=40
> Its text value is: New York
> 
> Array ( [40] => New York ) //here's the problem
> 
> The problem is in the $newInfo = array($strippd => $value); and it's
the
> last line of the sample HTML code.
> 
> What I want to achieve is:
> Array ( [10] => Miami, [20] => New England, [30] => Buffalo, [40] =>
New
> York ).
> 
> Any ideas how to get there?
> 
> Thanks in advance.
> 
> 
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php




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




Re: [PHP-DB] array problem

2002-06-21 Thread Jason Wong

On Thursday 20 June 2002 23:26, Richard Black wrote:
> By passing a second parameter to mysql_fetch_array, MYSQL_ASSOC
>
> This means you only get back an array with the values indexed by
> fieldname.

Or just use mysql_fetch_assoc().

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

/*
disks spinning backwards - toggle the hemisphere jumper.
*/


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




Re: [PHP-DB] Array HELL!!!!

2002-02-25 Thread biorn

Try putting the hidden element statement down inside the while loop in he 
second page, but change it to "" and add 

$id=$row['id']; 

before it.

I will show below where it should go. 

HTH

MB

jas <[EMAIL PROTECTED]> said:

> I have made the changes you suggested which if you ask me have been the most
> informative answers I have recieved thus far.  I did run into a slight snag
> on line 21 which is this on my confirmation page " NAME=\"id[]\" VALUE=\"$id[]\">" and the parse error is as follows...
> Parse error: parse error, expecting `STRING' or `NUM_STRING' or `'$'' in
> /php/rem_conf_t.php3 on line 21
> Wouldn't I need to adjust the value=\"$id[]\" to something like
> value=\".$id[].\" because we passed an array not a string?  Not sure. Thanks
> again.  You are sincerely helping me understand this whole php bit. =)
> Jas
> <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Ok, you have almost got it.  I have made little remarks further down in
> your
> > code which should just about do it for you.
> >
> >
> > jas <[EMAIL PROTECTED]> said:
> >
> > > I don't know what it is but I am having a hell of a time trying to get
> some
> > > results of a query setup into an array or variable (too much of a newbie
> to
> > > know which) that can be passed to a confirmation page before deleting
> the
> > > record from a table.  I have given up working on this but for those of
> you
> > > that want to finish it here is the code and the table structure...
> > >
> > > [Table Structure]
> > > id int(30) DEFAULT '0' NOT NULL auto_increment,
> > >car_type varchar(30),
> > >car_model varchar(30),
> > >car_year varchar(15),
> > >car_price varchar(15),
> > >car_vin varchar(25),
> > >dlr_num varchar(25),
> > >PRIMARY KEY (id)
> > >
> > > [Page 1 - Queries DB table for records]
> > >  > > require '../path/to/db.php';
> > > $result = @mysql_query("SELECT * FROM cur_inv",$dbh) or die("Could not
> > > execute query, please try again later");
> > > echo " > > name=\"rem_inv\" method=\"post\" action=\"rem_conf.php3\">
> > > Current
> > > Inventory";
> > > $count = -1;
> >
> > $count should start at 0 and then increment at the bottom of the while
> loop
> >
> > > while ($myrow = mysql_fetch_array($result)) {
> > >  $id = $row["id"];
> >
> > $row should be $myrow since that is what it is called above (or change
> $myrow
> > above to $row)
> >
> >
> > >  $car_type = $row["car_type"];
> > >  $car_model = $row["car_model"];
> > >  $car_year = $row["car_year"];
> > >  $car_price = $row["car_price"];
> > >  $car_vin = $row["car_vin"];
> > >  $count ++;
> >
> > $count ++; should be moved to the bottom of the loop just before it is
> closed
> >
> > > echo "Type Of Car: ";
> > > printf(mysql_result($result,$count,"car_type"));
> >
> > mysql_result is not needed here, you have defined the variable $car_type
> to
> > be this here as well as the rows below, so replace mysql_result($result,
> > $count, "car_type") with just $car_type
> >
> > > echo " > > value=\"".$myrow[id]."\">remove\n";
> >
> > replace $myrow[id] with $id since it is already defined above
> > when id[] is passed to page 2, it will contain an array of the id numbers
> > that got checked
> >
> >
> > > echo "Model Of Car: ";
> > > printf(mysql_result($result,$count,"car_model"));
> >
> > same as above, replace mysql_result($result,$count,"car_model") with
> > $car_model
> >
> > > echo "\n";
> > > echo "Year Of Car: ";
> > > printf(mysql_result($result,$count,"car_year"));
> >
> > same as above replace with $car_year
> >
> > > echo "\n";
> > > echo "Price Of Car: $";
> > > printf(mysql_result($result,$count,"car_price"));
> >
> > same as above replace with $care_price
> >
> > > echo "\n";
> > > echo "VIN Of Car: ";
> > > printf(mysql_result($result,$count,"car_vin"));
> >
> > same as above replace with $car_vin
> >
> > > echo " color=\"33\">\n";
> >
> > $count ++; should go here
> >
> > > }
> > > echo " > > value=\"delete\">";
> > > ?>
> > >
> > > [Page 2 - Takes records and confirms which ones to be deleted]
> > >  > > print("
> > > 
> > > 
> >
> > send id[] array passed from previous page to the next page:
> > 
> >
> > If you are planning on deleting multiple items at a time, you won't need
> the
> > following hidden elements at all, just make a database call at this point
> > using the id[] array passed to this page from the first page.  The only
> value
> > it needs for the 3rd page is the id value since that is what it uses to
> > determine what to delete.
> >
> > Here is an example of the database call to make:
> >
> > $i=0;
> > while ($id[$i]) {
> > $result = @mysql_query("SELECT * FROM cur_inv where id=$id[$i]",$dbh) or
> die
> > ("Could not execute query, please try again later");
> > $row=mysql_fetch_array($result);


Add here:
$id=$row['id'];


> > $car_type=$row['car_type'];
> > $car_model=$row['car_model'];
> > $car_year=$row['car_year'];
> > $car_price=$row['car_price'];
> > $car_vin=$row[

Re: [PHP-DB] Array HELL!!!!

2002-02-22 Thread jas

I have made the changes you suggested which if you ask me have been the most
informative answers I have recieved thus far.  I did run into a slight snag
on line 21 which is this on my confirmation page "" and the parse error is as follows...
Parse error: parse error, expecting `STRING' or `NUM_STRING' or `'$'' in
/php/rem_conf_t.php3 on line 21
Wouldn't I need to adjust the value=\"$id[]\" to something like
value=\".$id[].\" because we passed an array not a string?  Not sure. Thanks
again.  You are sincerely helping me understand this whole php bit. =)
Jas
<[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Ok, you have almost got it.  I have made little remarks further down in
your
> code which should just about do it for you.
>
>
> jas <[EMAIL PROTECTED]> said:
>
> > I don't know what it is but I am having a hell of a time trying to get
some
> > results of a query setup into an array or variable (too much of a newbie
to
> > know which) that can be passed to a confirmation page before deleting
the
> > record from a table.  I have given up working on this but for those of
you
> > that want to finish it here is the code and the table structure...
> >
> > [Table Structure]
> > id int(30) DEFAULT '0' NOT NULL auto_increment,
> >car_type varchar(30),
> >car_model varchar(30),
> >car_year varchar(15),
> >car_price varchar(15),
> >car_vin varchar(25),
> >dlr_num varchar(25),
> >PRIMARY KEY (id)
> >
> > [Page 1 - Queries DB table for records]
> >  > require '../path/to/db.php';
> > $result = @mysql_query("SELECT * FROM cur_inv",$dbh) or die("Could not
> > execute query, please try again later");
> > echo " > name=\"rem_inv\" method=\"post\" action=\"rem_conf.php3\">
> > Current
> > Inventory";
> > $count = -1;
>
> $count should start at 0 and then increment at the bottom of the while
loop
>
> > while ($myrow = mysql_fetch_array($result)) {
> >  $id = $row["id"];
>
> $row should be $myrow since that is what it is called above (or change
$myrow
> above to $row)
>
>
> >  $car_type = $row["car_type"];
> >  $car_model = $row["car_model"];
> >  $car_year = $row["car_year"];
> >  $car_price = $row["car_price"];
> >  $car_vin = $row["car_vin"];
> >  $count ++;
>
> $count ++; should be moved to the bottom of the loop just before it is
closed
>
> > echo "Type Of Car: ";
> > printf(mysql_result($result,$count,"car_type"));
>
> mysql_result is not needed here, you have defined the variable $car_type
to
> be this here as well as the rows below, so replace mysql_result($result,
> $count, "car_type") with just $car_type
>
> > echo " > value=\"".$myrow[id]."\">remove\n";
>
> replace $myrow[id] with $id since it is already defined above
> when id[] is passed to page 2, it will contain an array of the id numbers
> that got checked
>
>
> > echo "Model Of Car: ";
> > printf(mysql_result($result,$count,"car_model"));
>
> same as above, replace mysql_result($result,$count,"car_model") with
> $car_model
>
> > echo "\n";
> > echo "Year Of Car: ";
> > printf(mysql_result($result,$count,"car_year"));
>
> same as above replace with $car_year
>
> > echo "\n";
> > echo "Price Of Car: $";
> > printf(mysql_result($result,$count,"car_price"));
>
> same as above replace with $care_price
>
> > echo "\n";
> > echo "VIN Of Car: ";
> > printf(mysql_result($result,$count,"car_vin"));
>
> same as above replace with $car_vin
>
> > echo "\n";
>
> $count ++; should go here
>
> > }
> > echo " > value=\"delete\">";
> > ?>
> >
> > [Page 2 - Takes records and confirms which ones to be deleted]
> >  > print("
> > 
> > 
>
> send id[] array passed from previous page to the next page:
> 
>
> If you are planning on deleting multiple items at a time, you won't need
the
> following hidden elements at all, just make a database call at this point
> using the id[] array passed to this page from the first page.  The only
value
> it needs for the 3rd page is the id value since that is what it uses to
> determine what to delete.
>
> Here is an example of the database call to make:
>
> $i=0;
> while ($id[$i]) {
> $result = @mysql_query("SELECT * FROM cur_inv where id=$id[$i]",$dbh) or
die
> ("Could not execute query, please try again later");
> $row=mysql_fetch_array($result);
> $car_type=$row['car_type'];
> $car_model=$row['car_model'];
> $car_year=$row['car_year'];
> $car_price=$row['car_price'];
> $car_vin=$row['car_vin'];
>
>
> > 
> > 
> > 
> > 
> > 
> > 
> >   
> > Confirm
Record
> > Deletion
> >   
> >   
> > Type Of Car: 
> >  $car_type
> >   
> >   
> > Model Of Car: 
> >  $car_model
> >   
> >   
> > Year Of Car: 
> >  $car_year
> >   
> >   
> > Price Of Car: 
> >  $car_price
> >   
> >   
> > VIN Of Car: 
> >  $car_vin
> >   
>
>
> $i++;
>
> end loop here or after hr (wherever you prefer if you want hr between each
> item end after hr)
>
> 
>
>
> >   
> > 
> >   
> >   
> > 
> >   
> > 
> > ");
> > ?>
> >
> > [Page 3 - Connects to DB and deletes selected records]
> >  >

Re: [PHP-DB] Array HELL!!!!

2002-02-22 Thread biorn

Ok, you have almost got it.  I have made little remarks further down in your 
code which should just about do it for you.


jas <[EMAIL PROTECTED]> said:

> I don't know what it is but I am having a hell of a time trying to get some
> results of a query setup into an array or variable (too much of a newbie to
> know which) that can be passed to a confirmation page before deleting the
> record from a table.  I have given up working on this but for those of you
> that want to finish it here is the code and the table structure...
> 
> [Table Structure]
> id int(30) DEFAULT '0' NOT NULL auto_increment,
>car_type varchar(30),
>car_model varchar(30),
>car_year varchar(15),
>car_price varchar(15),
>car_vin varchar(25),
>dlr_num varchar(25),
>PRIMARY KEY (id)
> 
> [Page 1 - Queries DB table for records]
>  require '../path/to/db.php';
> $result = @mysql_query("SELECT * FROM cur_inv",$dbh) or die("Could not
> execute query, please try again later");
> echo " name=\"rem_inv\" method=\"post\" action=\"rem_conf.php3\">
> Current
> Inventory";
> $count = -1;

$count should start at 0 and then increment at the bottom of the while loop

> while ($myrow = mysql_fetch_array($result)) {
>  $id = $row["id"]; 

$row should be $myrow since that is what it is called above (or change $myrow 
above to $row)


>  $car_type = $row["car_type"];
>  $car_model = $row["car_model"];
>  $car_year = $row["car_year"];
>  $car_price = $row["car_price"];
>  $car_vin = $row["car_vin"];
>  $count ++;

$count ++; should be moved to the bottom of the loop just before it is closed

> echo "Type Of Car: ";
> printf(mysql_result($result,$count,"car_type"));

mysql_result is not needed here, you have defined the variable $car_type to 
be this here as well as the rows below, so replace mysql_result($result, 
$count, "car_type") with just $car_type

> echo " value=\"".$myrow[id]."\">remove\n";

replace $myrow[id] with $id since it is already defined above
when id[] is passed to page 2, it will contain an array of the id numbers 
that got checked


> echo "Model Of Car: ";
> printf(mysql_result($result,$count,"car_model"));

same as above, replace mysql_result($result,$count,"car_model") with 
$car_model

> echo "\n";
> echo "Year Of Car: ";
> printf(mysql_result($result,$count,"car_year"));

same as above replace with $car_year

> echo "\n";
> echo "Price Of Car: $";
> printf(mysql_result($result,$count,"car_price"));

same as above replace with $care_price

> echo "\n";
> echo "VIN Of Car: ";
> printf(mysql_result($result,$count,"car_vin"));

same as above replace with $car_vin

> echo "\n";

$count ++; should go here

> }
> echo " value=\"delete\">";
> ?>
> 
> [Page 2 - Takes records and confirms which ones to be deleted]
>  print("
> 
> 

send id[] array passed from previous page to the next page:


If you are planning on deleting multiple items at a time, you won't need the 
following hidden elements at all, just make a database call at this point 
using the id[] array passed to this page from the first page.  The only value 
it needs for the 3rd page is the id value since that is what it uses to 
determine what to delete.

Here is an example of the database call to make:

$i=0;
while ($id[$i]) {
$result = @mysql_query("SELECT * FROM cur_inv where id=$id[$i]",$dbh) or die
("Could not execute query, please try again later");
$row=mysql_fetch_array($result);
$car_type=$row['car_type'];
$car_model=$row['car_model'];
$car_year=$row['car_year'];
$car_price=$row['car_price'];
$car_vin=$row['car_vin'];


> 
> 
> 
> 
> 
> 
>   
> Confirm Record
> Deletion
>   
>   
> Type Of Car: 
>  $car_type
>   
>   
> Model Of Car: 
>  $car_model
>   
>   
> Year Of Car: 
>  $car_year
>   
>   
> Price Of Car: 
>  $car_price
>   
>   
> VIN Of Car: 
>  $car_vin
>   


$i++;

end loop here or after hr (wherever you prefer if you want hr between each 
item end after hr)




>   
> 
>   
>   
> 
>   
> 
> ");
> ?>
> 
> [Page 3 - Connects to DB and deletes selected records]
>  require '../path/to/db.php';
> $table_name = "cur_inv";

need another loop here to go through id's passed through array

$i=0;
while ($id[$i]) {

> $sql = "DELETE FROM $table_name WHERE id = '$id'";

this should be 
$sql="DELETE FROM $table_name WHERE id = $id[$i]";

Remove '' around $id and add [], it is an integer, so it does not want quotes 
around it
only quote string datatypes

> echo($sql);
> $result = mysql_query($sql,$dbh) or die(mysql_error());

increment array and then close loop

$i++;
}


> print("You have successfully
> removed your items from the database.");
> ?>
> 
> If anyone has the time to finish it or give me some pointers on what the
> hell I am doing wrong please let me know, I would be very glad to hear your
> opinion and the correct way to accomplish this.  (And, yes I went through
> just about every tutorial I could find on how to delete records, which by
> the way did nothing for putting the results of a select st

Re: [PHP-DB] Array HELL!!!!

2002-02-22 Thread jas

Well ok now that I know it isn't an array I am having problems with, how
exactly am I supposed to create a variable (that can be passed to another
page) from a selected set of records?
Thanks again for the politeness,
Jas
"Spyproductions Support Team" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
>
> That's not Array Hell, this is Array Hell:
>
> $Hell = array("satan","fire","brimstone");
>
> -Mike
>
>
> > -Original Message-
> > From: jas [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, February 22, 2002 4:37 AM
> > To: [EMAIL PROTECTED]
> > Subject: [PHP-DB] Array HELL
> >
> >
> > I don't know what it is but I am having a hell of a time trying
> > to get some
> > results of a query setup into an array or variable (too much of a
> > newbie to
> > know which) that can be passed to a confirmation page before deleting
the
> > record from a table.  I have given up working on this but for those of
you
> > that want to finish it here is the code and the table structure...
> >
> > [Table Structure]
> > id int(30) DEFAULT '0' NOT NULL auto_increment,
> >car_type varchar(30),
> >car_model varchar(30),
> >car_year varchar(15),
> >car_price varchar(15),
> >car_vin varchar(25),
> >dlr_num varchar(25),
> >PRIMARY KEY (id)
> >
> > [Page 1 - Queries DB table for records]
> >  > require '../path/to/db.php';
> > $result = @mysql_query("SELECT * FROM cur_inv",$dbh) or die("Could not
> > execute query, please try again later");
> > echo " > name=\"rem_inv\" method=\"post\" action=\"rem_conf.php3\">
> > Current
> > Inventory";
> > $count = -1;
> > while ($myrow = mysql_fetch_array($result)) {
> >  $id = $row["id"];
> >  $car_type = $row["car_type"];
> >  $car_model = $row["car_model"];
> >  $car_year = $row["car_year"];
> >  $car_price = $row["car_price"];
> >  $car_vin = $row["car_vin"];
> >  $count ++;
> > echo "Type Of Car: ";
> > printf(mysql_result($result,$count,"car_type"));
> > echo " > value=\"".$myrow[id]."\">remove\n";
> > echo "Model Of Car: ";
> > printf(mysql_result($result,$count,"car_model"));
> > echo "\n";
> > echo "Year Of Car: ";
> > printf(mysql_result($result,$count,"car_year"));
> > echo "\n";
> > echo "Price Of Car: $";
> > printf(mysql_result($result,$count,"car_price"));
> > echo "\n";
> > echo "VIN Of Car: ";
> > printf(mysql_result($result,$count,"car_vin"));
> > echo "\n";
> > }
> > echo " > value=\"delete\">";
> > ?>
> >
> > [Page 2 - Takes records and confirms which ones to be deleted]
> >  > print("
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> >   
> > Confirm
Record
> > Deletion
> >   
> >   
> > Type Of Car: 
> >  $car_type
> >   
> >   
> > Model Of Car: 
> >  $car_model
> >   
> >   
> > Year Of Car: 
> >  $car_year
> >   
> >   
> > Price Of Car: 
> >  $car_price
> >   
> >   
> > VIN Of Car: 
> >  $car_vin
> >   
> >   
> > 
> >   
> >   
> > 
> >   
> > 
> > ");
> > ?>
> >
> > [Page 3 - Connects to DB and deletes selected records]
> >  > require '../path/to/db.php';
> > $table_name = "cur_inv";
> > $sql = "DELETE FROM $table_name WHERE id = '$id'";
> > echo($sql);
> > $result = mysql_query($sql,$dbh) or die(mysql_error());
> > print("You have successfully
> > removed your items from the database.");
> > ?>
> >
> > If anyone has the time to finish it or give me some pointers on what the
> > hell I am doing wrong please let me know, I would be very glad to
> > hear your
> > opinion and the correct way to accomplish this.  (And, yes I went
through
> > just about every tutorial I could find on how to delete records, which
by
> > the way did nothing for putting the results of a select statement into
an
> > array or variable for futher processing.) Have a good weekend
everyone!!!
> > Pissed and frustrated...
> > Jas
> >
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>



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




RE: [PHP-DB] Array HELL!!!!

2002-02-22 Thread SpyProductions Support Team


That's not Array Hell, this is Array Hell:

$Hell = array("satan","fire","brimstone");

-Mike


> -Original Message-
> From: jas [mailto:[EMAIL PROTECTED]]
> Sent: Friday, February 22, 2002 4:37 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-DB] Array HELL
>
>
> I don't know what it is but I am having a hell of a time trying
> to get some
> results of a query setup into an array or variable (too much of a
> newbie to
> know which) that can be passed to a confirmation page before deleting the
> record from a table.  I have given up working on this but for those of you
> that want to finish it here is the code and the table structure...
>
> [Table Structure]
> id int(30) DEFAULT '0' NOT NULL auto_increment,
>car_type varchar(30),
>car_model varchar(30),
>car_year varchar(15),
>car_price varchar(15),
>car_vin varchar(25),
>dlr_num varchar(25),
>PRIMARY KEY (id)
>
> [Page 1 - Queries DB table for records]
>  require '../path/to/db.php';
> $result = @mysql_query("SELECT * FROM cur_inv",$dbh) or die("Could not
> execute query, please try again later");
> echo " name=\"rem_inv\" method=\"post\" action=\"rem_conf.php3\">
> Current
> Inventory";
> $count = -1;
> while ($myrow = mysql_fetch_array($result)) {
>  $id = $row["id"];
>  $car_type = $row["car_type"];
>  $car_model = $row["car_model"];
>  $car_year = $row["car_year"];
>  $car_price = $row["car_price"];
>  $car_vin = $row["car_vin"];
>  $count ++;
> echo "Type Of Car: ";
> printf(mysql_result($result,$count,"car_type"));
> echo " value=\"".$myrow[id]."\">remove\n";
> echo "Model Of Car: ";
> printf(mysql_result($result,$count,"car_model"));
> echo "\n";
> echo "Year Of Car: ";
> printf(mysql_result($result,$count,"car_year"));
> echo "\n";
> echo "Price Of Car: $";
> printf(mysql_result($result,$count,"car_price"));
> echo "\n";
> echo "VIN Of Car: ";
> printf(mysql_result($result,$count,"car_vin"));
> echo "\n";
> }
> echo " value=\"delete\">";
> ?>
>
> [Page 2 - Takes records and confirms which ones to be deleted]
>  print("
> 
> 
> 
> 
> 
> 
> 
> 
>   
> Confirm Record
> Deletion
>   
>   
> Type Of Car: 
>  $car_type
>   
>   
> Model Of Car: 
>  $car_model
>   
>   
> Year Of Car: 
>  $car_year
>   
>   
> Price Of Car: 
>  $car_price
>   
>   
> VIN Of Car: 
>  $car_vin
>   
>   
> 
>   
>   
> 
>   
> 
> ");
> ?>
>
> [Page 3 - Connects to DB and deletes selected records]
>  require '../path/to/db.php';
> $table_name = "cur_inv";
> $sql = "DELETE FROM $table_name WHERE id = '$id'";
> echo($sql);
> $result = mysql_query($sql,$dbh) or die(mysql_error());
> print("You have successfully
> removed your items from the database.");
> ?>
>
> If anyone has the time to finish it or give me some pointers on what the
> hell I am doing wrong please let me know, I would be very glad to
> hear your
> opinion and the correct way to accomplish this.  (And, yes I went through
> just about every tutorial I could find on how to delete records, which by
> the way did nothing for putting the results of a select statement into an
> array or variable for futher processing.) Have a good weekend everyone!!!
> Pissed and frustrated...
> Jas
>
>
>
> --
> PHP Database Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>



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




RE: [PHP-DB] Array not supported for strings???

2002-01-04 Thread Rick Emery

Need to show us more code...

-Original Message-
From: Andy [mailto:[EMAIL PROTECTED]]
Sent: Friday, January 04, 2002 2:00 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] Array not supported for strings???


Hi there,

I have a problem with an array:

This code:
$country[] = $row->country;

Creates following error msg:
  Fatal error: [] operator not supported for strings

  The wired thing is, that the same procedure works through my whole
application, but not in this case.

  Did anybody make the same experience?

  Thanx for any help buddys.

  Regards Andy



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

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




Re: [PHP-DB] array-problems

2001-10-24 Thread Jim Lucas


- Original Message -
From: "Jim Lucas" <[EMAIL PROTECTED]>
To: "Bart Verbeek" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, October 24, 2001 12:42 PM
Subject: Re: [PHP-DB] array-problems


> Try this:
>
> <<< BEGIN:PHP-CODE >>>
>
> $result = mysql_query ("SELECT DISTINCT date FROM linktracker WHERE name
> LIKE '$PHP_AUTH_USER' GROUP BY date ORDER BY date");
> if (mysql_num_rows($result))
> {
>   for($i=0;$i   {
> $date = array(
>   "begin" => array($i => $row["date"]),
>   "end" => array($i => $row["date"])
>   );
>   }
> } else {
>   print ("Sorry, no record were found.");
> }
>
> function drawSelect($which)
> {
>   global $date;
>   foreach($date[$which] AS $date_begin)
>   {
> ?>
> 
>}
>
> }
>
> ?>
> 
>   
> Begindate
> Enddate
>   
>   
> 
> 
> 
>  drawSelect("begin");
> ?>
> 
> 
> 
>  rsort($date[end]);
>
> drawSelect("end");
> ?>
> 
> 
>   
>   
>  value="Submit">
>   
>
> <<< END:PHP-CODE >>>
>
> btw - you need to watch your closing '>'  you are missing a few.  Plus to
> get distince to work right you need to use the "GROUP BY" clause.
>
> Jim
>
> - Original Message -
> From: "Bart Verbeek" <[EMAIL PROTECTED]>
> To: "Php-General-list" <[EMAIL PROTECTED]>; "PHP-DB mailinglist"
> <[EMAIL PROTECTED]>
> Sent: Wednesday, October 24, 2001 12:23 PM
> Subject: [PHP-DB] array-problems
>
>
> > Hello,
> > Can anyone help me with this script I'm using?
> >
> > I've saved dates in a database and want to make two select-lists of
these
> > dates in a html-form.
> > I want to select each unique date one time (no doubles).
> > List 1 is used to set the begin-date of the query for the report, List 2
> > will
> > set the end-date and must be reversed.
> > When the form is processed the data selected between the begin-date and
> the
> > end-date has to be show.
> >
> > I can't seem to get my code to work: the select-lists stay empty after
> > processing the code below.
> >
> > Can anyone help? Tips...
> >
> > regards,
> >
> > Bart
> >
> >
> > <<< BEGIN:PHP-CODE >>>
> > $i=0;
> >  $result = mysql_query ("SELECT DISTINCT date FROM linktracker WHERE
name
> > LIKE '$PHP_AUTH_USER' ORDER BY date");
> >  if ($row = mysql_fetch_array($result)) {
> > do {
> >   $date = array(
> > "begin" => array($i => $row["date"]),
> > "end" => array($i => $row["date"])
> > );
> > $i++;
> > } while ($row = mysql_fetch_array($result));
> >  } else {print ("Sorry, no record were found.");
> >  } //end else $result
> >
> > print("BegindateEnddate\n".
> > " > name=\"date_select\">".
> > " > value=\"date_select\">".
> > "");
> >
> > while (list($key, $date_begin) = each($date[begin])) {
> > echo "" . $date_begin .
> > "\n";
> > }
> >
> > print("");
> >
> > rsort($date[end]);
> >
> > while (list($key, $date_end) = each($date[end])) {
> >   echo "" . $date_end .
> > "\n";
> > }
> >
> > print("\n".
> >   "".
> >   "");
> >
> > mysql_free_result ($result);
> > mysql_close();
> > <<< END:PHP-CODE >>>
> >
> >
> > --
> > PHP Database Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> >
>


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




Re: [PHP-DB] array-problems

2001-10-24 Thread Bruno Gimenes Pereti

It looks like you need only one array, $date[begin] = $date[end].
Let's see, I think it'll work. I'll write it in your code then you try:

$i=0;
$result = mysql_query ("SELECT DISTINCT date FROM linktracker WHERE name
LIKE '$PHP_AUTH_USER' ORDER BY date");
if ($row = mysql_fetch_array($result)) {
  do {
$date[$i] = $row["date"]);
$i++;
  } while ($row = mysql_fetch_array($result));
} else {print ("Sorry, no record were found.");
} file://end else $result

print("BegindateEnddate\n".
"".
"".
"");

$i = 0;
while ($date[$i]) {
  echo "" . $date_begin .
  "\n";
  $i++;
}

print("");

$i--;
while ($date[$i]) {
  echo "" . $date_end .
  "\n";
  $i--;
}

print("\n".
"".
"");

mysql_free_result ($result);
mysql_close();


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




Re: [PHP-DB] array from html form

2001-10-05 Thread Larry Linthicum

the subarrays contain variable data and I tried to express that by showing
the array structure that way

if I access $needed_data[0]

it would be an array of two pieces of data ( both variable)

$needed_data[1] would also be an array of two variable pieces of data, etc

if I loop through them all I can use each "member_id / position  "  pair to
update a database

but I have no way to know how many such pairs there will be, and the actual
values of $member_id

and of $position will be different in each case

I hope that helps, sorry I'm not more skilled at expressing this



> For one, why are you redefining the array 3 times in that script? ...
> I'm trying to follow here... and its not making sense.
>
> I need to build a multidimensional array from a html form,
> the array  would look like:
>
> $needed_data = array (
> array (id = $member_id,
> points = $position ),
> array ( id = $member_id,
> points =$position),
> array (id=$member_id,
> points = $position);
>
> $member_id  will be used to dynamically build the html form,  $position
> will be an integer entered into a text field in that form similar to
> this:
>
> Fred($member_id=?)   .. [ enter position=? ]
> John)$member_id=?) ..[enter position=?]
> etc
> etc
> [SUBMIT]
>
> IF ( I can get the data into an array like above) {
> I can make the rest of the script work }
>




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




RE: [PHP-DB] array from html form

2001-10-05 Thread Charles Butler

For one, why are you redefining the array 3 times in that script? ...
I'm trying to follow here... and its not making sense.

-Original Message-
From: Larry Linthicum [mailto:[EMAIL PROTECTED]] 
Sent: Friday, October 05, 2001 12:14 PM
To: [EMAIL PROTECTED]
Subject: [PHP-DB] array from html form


Hi
I'm just a PHP "hobbiest" trying to build a points calculating system
for another hobby, please bear with me.

I need to build a multidimensional array from a html form,
the array  would look like:

$needed_data = array (
array (id = $member_id,
points = $position ),
array ( id = $member_id,
points =$position),
array (id=$member_id,
points = $position);

$member_id  will be used to dynamically build the html form,  $position
will be an integer entered into a text field in that form similar to
this:

Fred($member_id=?)   .. [ enter position=? ]
John)$member_id=?) ..[enter position=?]
etc
etc
[SUBMIT]

IF ( I can get the data into an array like above) {
I can make the rest of the script work }

but that is a big "if"  ... how can I stucture the form and get
that multidimen array from the single name/value pairs passed from an
html form?


OR
Maybe I can make a normal array work?
I know that enclosing form field names in [] makes them available as an
array


if the form were dynamically built like

PERSONS NAME (from database via $member_id )
   next PERSONS NAME (from database via $member_id )
  next PERSONS NAME (from database via $member_id )
  etc etc


I "think" I would then send an array containing all the $member_id (s)
and all the entries into the txt fields

first... am I correct in that?

second  ... is the indexing order known and guaranteed?  in other words
is
$data[0] and $data[1]   OR  $data[12] and $data[13]
ALWAYS going to represent a "matched" pair?   ( from "one line" of the
form } or is the indexing of the array subject to variation and may NOT
be in the same order as the [data] fields in the html ?

What if nothing is entered into the txt field?I know that enclosing form
field names in [] makes them available as an array


if the form were dynamically built like

PERSONS NAME (from database via $member_id )
   next PERSONS NAME (from database via $member_id )
  next PERSONS NAME (from database via $member_id )
  etc etc


I "think" I would then send an array containing all the $member_id (s)
and all the entries into the txt fields

first... am I correct in that?

second  ... is the indexing order known and guaranteed?  in other words
is
$data[0] and $data[1]   OR  $data[12] and $data[13]
ALWAYS going to represent a "matched" pair?   ( from "one line" of the
form } or is the indexing of the array subject to variation and may NOT
be in the same order as the [data] fields in the html ?

What if nothing is entered into the txt field?




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


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




Re: [PHP-DB] array in db field -> actual array

2001-09-13 Thread brendan

scratch that, i had a syntax error in the array..
you were completely right dobromir eval() works perfectly..
thanks!


Brendan wrote:

> thanks dobromir,
> unfortunately that doesnt seem to work  ...
> although looking at the php manual you seem to be on the right track..
> could the way the textfield is parsed & passed back affect the array?
> 
> cheers!
> brendan
> 
> Dobromir Velev wrote:
> 
>> Hi,
>> I think you can use the eval() function to execute the stored info. 
>> The code
>> will look something like this
>> $res=mysql_query(...)
>> eval($row_from_query);
>>
>> If you want to change the name of the array you could use
>> eval(str_replace("$array","$newarray",$row_from_query));
>>
>> HTH
>> Dobromir Velev
>>
>> -Original Message-
>> From: brendan <[EMAIL PROTECTED]>
>> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
>> Date: Thursday, September 13, 2001 2:20 PM
>> Subject: [PHP-DB] array in db field -> actual array
>>
>>
>>
>>> hi,
>>> i am currently scouring the web for a solution to this but thought i
>>> would try here as well ..
>>>
>>> i have a text field in a mysql database
>>> the textfield contains an array written out as
>>> //
>>> $array[0][1]="one";
>>> $array[0][2]="two";
>>> $array[0][3]="thre";
>>> $array[1][1]="four";
>>> $array[2][1]="five";
>>> //
>>>
>>> now i need to extract this from the db .. simple
>>> and use it as an array for a function .. not as simple as i thought it
>>> would be
>>>
>>>
>>> ie
>>>
>>> $newarray =mysqlquery('etc','etc','etc')
>>> and $newarray should be
>>> $newarray[0][1]="one";
>>> $newarray[0][2]="two";
>>> $newarray[0][3]="thre";
>>> $newarray[1][1]="four";
>>> $newarray[2][1]="five";
>>>
>>> elp?
>>>
>>> cheers
>>> brendan
>>>
>>>
>>> -- 
>>> PHP Database Mailing List (http://www.php.net/)
>>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>>> For additional commands, e-mail: [EMAIL PROTECTED]
>>> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>>>
>>>
>>>
>>
> 


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




[PHP-DB] Re:[PHP-DB] array in db field -> actual array

2001-09-13 Thread brendan

thanks dobromir,
unfortunately that doesnt seem to work  ...
although looking at the php manual you seem to be on the right track..
could the way the textfield is parsed & passed back affect the array?

cheers!
brendan

Dobromir Velev wrote:

> Hi,
> I think you can use the eval() function to execute the stored info. The code
> will look something like this
> $res=mysql_query(...)
> eval($row_from_query);
> 
> If you want to change the name of the array you could use
> eval(str_replace("$array","$newarray",$row_from_query));
> 
> HTH
> Dobromir Velev
> 
> -Original Message-
> From: brendan <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
> Date: Thursday, September 13, 2001 2:20 PM
> Subject: [PHP-DB] array in db field -> actual array
> 
> 
> 
>>hi,
>>i am currently scouring the web for a solution to this but thought i
>>would try here as well ..
>>
>>i have a text field in a mysql database
>>the textfield contains an array written out as
>>//
>>$array[0][1]="one";
>>$array[0][2]="two";
>>$array[0][3]="thre";
>>$array[1][1]="four";
>>$array[2][1]="five";
>>//
>>
>>now i need to extract this from the db .. simple
>>and use it as an array for a function .. not as simple as i thought it
>>would be
>>
>>
>>ie
>>
>>$newarray =mysqlquery('etc','etc','etc')
>>and $newarray should be
>>$newarray[0][1]="one";
>>$newarray[0][2]="two";
>>$newarray[0][3]="thre";
>>$newarray[1][1]="four";
>>$newarray[2][1]="five";
>>
>>elp?
>>
>>cheers
>>brendan
>>
>>
>>--
>>PHP Database Mailing List (http://www.php.net/)
>>To unsubscribe, e-mail: [EMAIL PROTECTED]
>>For additional commands, e-mail: [EMAIL PROTECTED]
>>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>>
>>
>>
> 


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




Re: [PHP-DB] array in db field -> actual array

2001-09-13 Thread Dobromir Velev

Hi,
I think you can use the eval() function to execute the stored info. The code
will look something like this
$res=mysql_query(...)
eval($row_from_query);

If you want to change the name of the array you could use
eval(str_replace("$array","$newarray",$row_from_query));

HTH
Dobromir Velev

-Original Message-
From: brendan <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Thursday, September 13, 2001 2:20 PM
Subject: [PHP-DB] array in db field -> actual array


>hi,
>i am currently scouring the web for a solution to this but thought i
>would try here as well ..
>
>i have a text field in a mysql database
>the textfield contains an array written out as
>//
>$array[0][1]="one";
>$array[0][2]="two";
>$array[0][3]="thre";
>$array[1][1]="four";
>$array[2][1]="five";
>//
>
>now i need to extract this from the db .. simple
>and use it as an array for a function .. not as simple as i thought it
>would be
>
>
>ie
>
>$newarray =mysqlquery('etc','etc','etc')
>and $newarray should be
>$newarray[0][1]="one";
>$newarray[0][2]="two";
>$newarray[0][3]="thre";
>$newarray[1][1]="four";
>$newarray[2][1]="five";
>
>elp?
>
>cheers
>brendan
>
>
>--
>PHP Database Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>


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




Re: [PHP-DB] array awry

2001-02-27 Thread Darryl Friesen

> Perhaps I've misunderstood.
>
> I thought this IS a PHP list (see Rolf Hopkins below).

It's a PHP/Database list, not just PHP.  POsts should have something to do
with BOTH.

> Secondly, this list is not only for MySQL questions and issues (see Cal
> Evans below).  It is for all database questions, as we've seen from
> questins concerning other databases.

I think what he was getting at was the question had nothing to do with
databases; it was a question about arrays, and therefore should have only
been asked in php-general.


- Darryl

 --
  Darryl Friesen, B.Sc., Programmer/Analyst[EMAIL PROTECTED]
  Education & Research Technology Services, http://gollum.usask.ca/
  Department of Computing Services,
  University of Saskatchewan
 --
  "Go not to the Elves for counsel, for they will say both no and yes"



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




RE: [PHP-DB] array awry

2001-02-27 Thread Rick Emery

All,

Perhaps I've misunderstood.

I thought this IS a PHP list (see Rolf Hopkins below).

Secondly, this list is not only for MySQL questions and issues (see Cal
Evans below).  It is for all database questions, as we've seen from uestins
concerning other databases.

Am I incorrect?

Richard L. Emery
IT Sr. Project Manager

"There is no 'trying'...
There is only 'Do' or 'Not Do' "


-Original Message-
From: Cal Evans [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 27, 2001 6:50 AM
To: Keith Spiller
Cc: [EMAIL PROTECTED]
Subject: RE: [PHP-DB] array awry


Hi Keith,

1: Don't cross-post. It's rude. Especially since this has nothing to do with
MySQL.

2: You are not building a multi-dimensional array. The code below won't even
build a single dimensional array because you didn't put your keys in quotes
so it's probably blowing chunks. At the very least, if you had put quotes
around your key names, it would have overwritten the data each loop.

Try something like this:

  If ($Selection == "3")
  {
  $lcvA++;
  $tabledata[$lcvA] = Array();
  $tabledata[$lcvA]['catid']= $myrow[0];
  $tabledata[$lcvA]['category'] = "$myrow[1]";
  $tabledata[$lcvA]['under']= $myrow[2];
  $tabledata[$lcvA]['corder']   = $myrow[3];
  $tabledata[$lcvA]['active']   = $myrow[4];
  }

This is a multidimensional array. The first dimension is a counter, $lcvA.
Make sure you init it at the top of your function.  Now, each time you add a
row to the array, it' in a new row IN the array.

To access the data you use:

$myCOrder = $tabledata[$rowToAccess]['corder']

HTH,
Cal
http://www.calevans.com

-Original Message-
From: Rolf Hopkins [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 26, 2001 9:10 PM
To: Keith Spiller; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: [PHP-DB] Re: array awry


This is a PHP question and should really be asked on the PHP list.

But a suggestion.  Tried using field names instead of number?  ie.
$myrow["catid"];

I'd have to read up the PHP manual to find out for sure but I'm sure you can
do that just as well as I can.

-Original Message-
From: Keith Spiller [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 26, 2001 8:15 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: [PHP-DB] array awry


This associative array embedded within a function and declared as a global
at the start of the function, is meant to be a multidimensional array, but
with every loop of the while ($myrow = mysql_fetch_row($result)) statement,
it's previous values are replaced by the new ones.  Any ideas on how I can
fix this?

  If ($Selection == "3")
  {
  $tabledata[catid]= $myrow[0];
  $tabledata[category] = "$myrow[1]";
  $tabledata[under]= $myrow[2];
  $tabledata[corder]   = $myrow[3];
  $tabledata[active]   = $myrow[4];
  }

Keith
aka Larentium


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

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




RE: [PHP-DB] array awry

2001-02-27 Thread Cal Evans

Hi Keith,

1: Don't cross-post. It's rude. Especially since this has nothing to do with
MySQL.

2: You are not building a multi-dimensional array. The code below won't even
build a single dimensional array because you didn't put your keys in quotes
so it's probably blowing chunks. At the very least, if you had put quotes
around your key names, it would have overwritten the data each loop.

Try something like this:

  If ($Selection == "3")
  {
  $lcvA++;
  $tabledata[$lcvA] = Array();
  $tabledata[$lcvA]['catid']= $myrow[0];
  $tabledata[$lcvA]['category'] = "$myrow[1]";
  $tabledata[$lcvA]['under']= $myrow[2];
  $tabledata[$lcvA]['corder']   = $myrow[3];
  $tabledata[$lcvA]['active']   = $myrow[4];
  }

This is a multidimensional array. The first dimension is a counter, $lcvA.
Make sure you init it at the top of your function.  Now, each time you add a
row to the array, it' in a new row IN the array.

To access the data you use:

$myCOrder = $tabledata[$rowToAccess]['corder']

HTH,
Cal
http://www.calevans.com


-Original Message-
From: Keith Spiller [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 26, 2001 8:15 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: [PHP-DB] array awry


This associative array embedded within a function and declared as a global
at the start of the function, is meant to be a multidimensional array, but
with every loop of the while ($myrow = mysql_fetch_row($result)) statement,
it's previous values are replaced by the new ones.  Any ideas on how I can
fix this?

  If ($Selection == "3")
  {
  $tabledata[catid]= $myrow[0];
  $tabledata[category] = "$myrow[1]";
  $tabledata[under]= $myrow[2];
  $tabledata[corder]   = $myrow[3];
  $tabledata[active]   = $myrow[4];
  }

Keith
aka Larentium


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




Re: [PHP-DB] array awry

2001-02-27 Thread CC Zona

In article <061201c0a063$08eab5a0$[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] ("Keith Spiller") wrote:

> This associative array embedded within a function and declared as a global at 
> the start of the function, is meant to be a multidimensional array, but with 
> every loop of the while ($myrow = mysql fetch row($result)) statement, it's 
> previous values are replaced by the new ones.  Any ideas on how I can fix 
> this?
> 
>   If ($Selection == "3")
>   {
>   $tabledata[catid]= $myrow[0];
>   $tabledata[category] = "$myrow[1]";
>   $tabledata[under]= $myrow[2];
>   $tabledata[corder]   = $myrow[3];
>   $tabledata[active]   = $myrow[4];
>   }


So what you're saying is that want indexes 'catid', 'category', etc. to 
have a distinct value for each row pulled from the database?  Then you need 
to add another dimension to that array.

-- 
CC

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




Re: [PHP-DB] Array element as object.

2001-02-21 Thread Christian Rishøj



""JJeffman"" <[EMAIL PROTECTED]> wrote in message
000701c09ba2$3b2bb020$f0d4d7c8@jjeffman">news:000701c09ba2$3b2bb020$f0d4d7c8@jjeffman...
> I've already made an object which had a property that was an array. Now I
> need to have an array that can hold objects as its elements is It possible
?
> I didn't get it the expression array[$i]->Object gave me syntax error. Any
> tips ?

$object1 = new someClass;
$object2 = new someClass;

$array = array();

$array[] = $object1;
$array[] = $object2;

The $array now contains copies of the two objects.

You can fill more in like this:

$array[] = new someClass;

Access the objects like this:

$array[0]->someMethod();

/Christian



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