Re: [PHP] Problems with Arrays and print and echo

2006-04-09 Thread Michael Felt

John Wells wrote:

echo $this-name[5]\n;
echo $this-ID[5]\n;
$a1 = $this-name;
$a2 = $this-ID;
echo \n$a1[5] $a2[5]\n;



use curly brackets to help PHP understand what you're after:

echo {$this-name[5]}\n;

When you're in a string like this, PHP has a hard time knowing when
you're wanting to access a variable, and when you're simply trying to
output text.  Using curly brackets clears it up.

HTH,
John W

Thanks.

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



Re: [PHP] Problems with Arrays and print and echo

2006-04-08 Thread chris smith
On 4/7/06, Michael Felt [EMAIL PROTECTED] wrote:
 Slowly I am getting the output I want.

 Trying to use dynamic arrays, does creat the array I want, but getting
 the info is sometimes surprising.

 I notice a difference between arrays used locally in a function, and
 arrays used as a 'var' in a class function (all in PHP 4 atm).

 Code snippet:
  echo ROWS returned are: $max\n;
  $this-count = $max;

  while ($max--) {
  $row = mysql_fetch_row($result);
  $this-name[$max] = sprintf(%s, $row[0]);
  $Name[$max] = sprintf(%s, $row[0]);
 echo init \$this-Xame[$max] = $row[0];
 echo  $Name[$max] $this-name[$max]\n;
  $regionID[$max] = $row[1];
  $constellationID[$max] = $row[2];
  $this-ID[$max] = $row[3];
 printf(%d:%d/%d/%s\n,$max,$regionID[$max],$constellationID[$max],
 $this-name[$max]);
  }
 
 Line wrap is messing things up a bit.
 Was trying sprintf to see if the was a buffer problem coming from mysql.
 Problem seems to be the same, regardless.
 Also, the names changes ($this-name[] versus $Name[]) are deliberate,
 for just in case
 

 Output (debuging):
 ROWS returned are: 7
 init $this-Xame[6] = 8-TFDX 8-TFDX Array[6]

Is the problem that you're getting array[6] instead of the value?
Explain what you see and what you expect to see.

What is var $name originally set to, ie:

var $name = array(); (or '' or ) ?

--
Postgresql  php tutorials
http://www.designmagick.com/

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



Re: [PHP] Problems with Arrays and print and echo

2006-04-08 Thread Michael Felt

chris smith wrote:

On 4/7/06, Michael Felt [EMAIL PROTECTED] wrote:


Slowly I am getting the output I want.

Trying to use dynamic arrays, does creat the array I want, but getting
the info is sometimes surprising.

I notice a difference between arrays used locally in a function, and
arrays used as a 'var' in a class function (all in PHP 4 atm).

Code snippet:
echo ROWS returned are: $max\n;
$this-count = $max;

while ($max--) {
$row = mysql_fetch_row($result);
$this-name[$max] = sprintf(%s, $row[0]);
$Name[$max] = sprintf(%s, $row[0]);
echo init \$this-Xame[$max] = $row[0];
echo  $Name[$max] $this-name[$max]\n;
$regionID[$max] = $row[1];
$constellationID[$max] = $row[2];
$this-ID[$max] = $row[3];
printf(%d:%d/%d/%s\n,$max,$regionID[$max],$constellationID[$max],
   $this-name[$max]);
}

Line wrap is messing things up a bit.
Was trying sprintf to see if the was a buffer problem coming from mysql.
Problem seems to be the same, regardless.
Also, the names changes ($this-name[] versus $Name[]) are deliberate,
for just in case


Output (debuging):
ROWS returned are: 7
init $this-Xame[6] = 8-TFDX 8-TFDX Array[6]



Is the problem that you're getting array[6] instead of the value?
Explain what you see and what you expect to see.

What is var $name originally set to, ie:


$row = mysql_fetch_row($result);
$this-name[$max] = sprintf(%s, $row[0]);
$Name[$max] = sprintf(%s, $row[0]);

Is the actual assignment of variables. What surprises me is that the 
'local' variable echos what I expect, but the 'class' variable does not.


function init($id)
{
$this-ID[0] = ERROR;
$this-name[0] = ;

Hope this answers your question.

And yes, I am not happy the the 'Array[X]' output, I am expecting the 
value, not what it is.


I have already tried establishing an array type early in the function...



var $name = array(); (or '' or ) ?

--
Postgresql  php tutorials
http://www.designmagick.com/


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



Re: [PHP] Problems with Arrays and print and echo

2006-04-08 Thread Michael Felt

Michael Felt wrote:

OK . a rewrite, bit shorter...

1. A class construct with two arrays:

var $name;
var $ID;

function init($id) {
$this-name = array();
$this-ID = array();


# firther in code assignment done from a mysql database:
while ($max--)
read
$this-name[$max] = $row[0];
$this-ID[$max]   = $row[1];
$Name[$max] = $row[0];
$ID[$max]   = $row[1];
}

and now some debug code
print_r($this-name);
print_r($this-ID);
echo \n$Name[5]\n;

echo $this-name[5]\n;
echo $this-ID[5]\n;
$a1 = $this-name;
$a2 = $this-ID;
echo \n$a1[5] $a2[5]\n;

Output:
Array
(
[6] = 8-TFDX
[5] = B-E3KQ
[4] = BR-6XP
[3] = G5ED-Y
[2] = O-LR1H
[1] = UL-4ZW
[0] = Y5J-EU
)
Array
(
[6] = 3312
[5] = 3307
[4] = 3311
[3] = 3310
[2] = 3309
[1] = 3313
[0] = 3308
)

B-E3KQ

Array[5]
Array[5]

B-E3KQ 3307

chris smith wrote:



var $name = array(); (or '' or ) ?

--
Postgresql  php tutorials
http://www.designmagick.com/


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



Re: [PHP] Problems with Arrays and print and echo

2006-04-08 Thread Michael Felt

Michael Felt wrote:
echo \n. $this-name[5] .   . $this-ID[5]. \n;
This give the same output as:
$a1 = $this-name;
$a2 = $this-ID;
echo \n$a1[5] $a2[5]\n;

Looks like I may need to use the '.' constructor more often

Who can explain this (please)?


Michael Felt wrote:

OK . a rewrite, bit shorter...

1. A class construct with two arrays:

var $name;
var $ID;

function init($id) {
$this-name = array();
$this-ID = array();

.
# firther in code assignment done from a mysql database:
while ($max--)
read
$this-name[$max] = $row[0];
$this-ID[$max]   = $row[1];
$Name[$max] = $row[0];
$ID[$max]   = $row[1];
}

and now some debug code
print_r($this-name);
print_r($this-ID);
echo \n$Name[5]\n;

echo $this-name[5]\n;
echo $this-ID[5]\n;
$a1 = $this-name;
$a2 = $this-ID;
echo \n$a1[5] $a2[5]\n;

Output:
Array
(
[6] = 8-TFDX
[5] = B-E3KQ
[4] = BR-6XP
[3] = G5ED-Y
[2] = O-LR1H
[1] = UL-4ZW
[0] = Y5J-EU
)
Array
(
[6] = 3312
[5] = 3307
[4] = 3311
[3] = 3310
[2] = 3309
[1] = 3313
[0] = 3308
)

B-E3KQ

Array[5]
Array[5]

B-E3KQ 3307


chris smith wrote:



var $name = array(); (or '' or ) ?

--
Postgresql  php tutorials
http://www.designmagick.com/


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



Re: [PHP] Problems with Arrays and print and echo

2006-04-08 Thread John Wells
  echo $this-name[5]\n;
  echo $this-ID[5]\n;
  $a1 = $this-name;
  $a2 = $this-ID;
  echo \n$a1[5] $a2[5]\n;

use curly brackets to help PHP understand what you're after:

echo {$this-name[5]}\n;

When you're in a string like this, PHP has a hard time knowing when
you're wanting to access a variable, and when you're simply trying to
output text.  Using curly brackets clears it up.

HTH,
John W

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



Re: [PHP] Problems with arrays

2004-06-17 Thread Oliver Hankeln
Phpu wrote:
Hi,
I have this array:
$array = array(element1, element2, element3, element4)
I want to list all elements of this array, so i used:
  foreach ($array as $index = $element) {
$InputString = $element;
 echo $InputString;
   }
but this code lists the elements like this: element1 element2 element3 element4
How can i list my elements like this: 
element1
element2
element3
element4
That's not a problem with arrays. This is one with outputting. You need 
to add a newline to your echo Statement. Either echo $InputString\n; 
or echo $InputStringbr; depending on wether you use html or plain text.

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


Re: [PHP] Problems with arrays

2004-06-17 Thread Steve Douville
What are you outputting? html, text, email body...??
- Original Message - 
From: Phpu [EMAIL PROTECTED]
To: Oliver Hankeln [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 9:06 AM
Subject: Re: [PHP] Problems with arrays


 I've tried this but it is not working ...

 Thanks anyway
 - Original Message -
 From: Oliver Hankeln [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, June 17, 2004 4:04 PM
 Subject: Re: [PHP] Problems with arrays


  Phpu wrote:
 
   Hi,
  
   I have this array:
  
   $array = array(element1, element2, element3, element4)
  
   I want to list all elements of this array, so i used:
  
 foreach ($array as $index = $element) {
   $InputString = $element;
echo $InputString;
  }
  
   but this code lists the elements like this: element1 element2 element3
 element4
  
   How can i list my elements like this:
   element1
   element2
   element3
   element4
 
  That's not a problem with arrays. This is one with outputting. You need
  to add a newline to your echo Statement. Either echo $InputString\n;
  or echo $InputStringbr; depending on wether you use html or plain
 text.
 
  Oliver
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 

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






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



Re: [PHP] Problems with arrays

2004-06-17 Thread Phpu
I want the element of the array to be displayed in a select field



- Original Message -
From: Steve Douville [EMAIL PROTECTED]
To: Phpu [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 4:12 PM
Subject: Re: [PHP] Problems with arrays


 What are you outputting? html, text, email body...??
 - Original Message -
 From: Phpu [EMAIL PROTECTED]
 To: Oliver Hankeln [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Thursday, June 17, 2004 9:06 AM
 Subject: Re: [PHP] Problems with arrays


  I've tried this but it is not working ...
 
  Thanks anyway
  - Original Message -
  From: Oliver Hankeln [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Thursday, June 17, 2004 4:04 PM
  Subject: Re: [PHP] Problems with arrays
 
 
   Phpu wrote:
  
Hi,
   
I have this array:
   
$array = array(element1, element2, element3, element4)
   
I want to list all elements of this array, so i used:
   
  foreach ($array as $index = $element) {
$InputString = $element;
 echo $InputString;
   }
   
but this code lists the elements like this: element1 element2
element3
  element4
   
How can i list my elements like this:
element1
element2
element3
element4
  
   That's not a problem with arrays. This is one with outputting. You
need
   to add a newline to your echo Statement. Either echo $InputString\n;
   or echo $InputStringbr; depending on wether you use html or plain
  text.
  
   Oliver
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 
 
 


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



Re: [PHP] Problems with arrays

2004-06-17 Thread Steve Douville
Can you give us the code from select to /select?
- Original Message - 
From: Phpu [EMAIL PROTECTED]
To: Steve Douville [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 9:14 AM
Subject: Re: [PHP] Problems with arrays


 I want the element of the array to be displayed in a select field



 - Original Message -
 From: Steve Douville [EMAIL PROTECTED]
 To: Phpu [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Thursday, June 17, 2004 4:12 PM
 Subject: Re: [PHP] Problems with arrays


  What are you outputting? html, text, email body...??
  - Original Message -
  From: Phpu [EMAIL PROTECTED]
  To: Oliver Hankeln [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Sent: Thursday, June 17, 2004 9:06 AM
  Subject: Re: [PHP] Problems with arrays
 
 
   I've tried this but it is not working ...
  
   Thanks anyway
   - Original Message -
   From: Oliver Hankeln [EMAIL PROTECTED]
   To: [EMAIL PROTECTED]
   Sent: Thursday, June 17, 2004 4:04 PM
   Subject: Re: [PHP] Problems with arrays
  
  
Phpu wrote:
   
 Hi,

 I have this array:

 $array = array(element1, element2, element3, element4)

 I want to list all elements of this array, so i used:

   foreach ($array as $index = $element) {
 $InputString = $element;
  echo $InputString;
}

 but this code lists the elements like this: element1 element2
 element3
   element4

 How can i list my elements like this:
 element1
 element2
 element3
 element4
   
That's not a problem with arrays. This is one with outputting. You
 need
to add a newline to your echo Statement. Either echo $InputString\n
;
or echo $InputStringbr; depending on wether you use html or
plain
   text.
   
Oliver
   
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
   
  
   --
   PHP General Mailing List (http://www.php.net/)
   To unsubscribe, visit: http://www.php.net/unsub.php
  
  
  
  
  
 

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







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



Re: [PHP] Problems with arrays

2004-06-17 Thread Phpu
Here is the code:

select name=model class=gform onchange=model_jump('parent', this)
   option value=0
  ?
  foreach ($nav_model_names as $index = $element) {
$InputString = $element;
 echo $InputString;
   }
 ?/option
  /select


- Original Message -
From: Steve Douville [EMAIL PROTECTED]
To: Phpu [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 4:23 PM
Subject: Re: [PHP] Problems with arrays


 Can you give us the code from select to /select?
 - Original Message -
 From: Phpu [EMAIL PROTECTED]
 To: Steve Douville [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Thursday, June 17, 2004 9:14 AM
 Subject: Re: [PHP] Problems with arrays


  I want the element of the array to be displayed in a select field
 
 
 
  - Original Message -
  From: Steve Douville [EMAIL PROTECTED]
  To: Phpu [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Sent: Thursday, June 17, 2004 4:12 PM
  Subject: Re: [PHP] Problems with arrays
 
 
   What are you outputting? html, text, email body...??
   - Original Message -
   From: Phpu [EMAIL PROTECTED]
   To: Oliver Hankeln [EMAIL PROTECTED]
   Cc: [EMAIL PROTECTED]
   Sent: Thursday, June 17, 2004 9:06 AM
   Subject: Re: [PHP] Problems with arrays
  
  
I've tried this but it is not working ...
   
Thanks anyway
- Original Message -
From: Oliver Hankeln [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 4:04 PM
Subject: Re: [PHP] Problems with arrays
   
   
 Phpu wrote:

  Hi,
 
  I have this array:
 
  $array = array(element1, element2, element3, element4)
 
  I want to list all elements of this array, so i used:
 
foreach ($array as $index = $element) {
  $InputString = $element;
   echo $InputString;
 }
 
  but this code lists the elements like this: element1 element2
  element3
element4
 
  How can i list my elements like this:
  element1
  element2
  element3
  element4

 That's not a problem with arrays. This is one with outputting. You
  need
 to add a newline to your echo Statement. Either echo
$InputString\n
 ;
 or echo $InputStringbr; depending on wether you use html or
 plain
text.

 Oliver

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

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


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



Re: [PHP] Problems with arrays

2004-06-17 Thread Steve Douville
I'm going to take a leap and make an assumption that what you want to end up
with is a select list of model names. I'm not sure what the value should be,
whether you want the value returned to you to be the $index the model or the
$element value. You can adjust either way. (By the way, you don't need to
set $InputString at all in this loop, you could just use $element.)

select name=model class=gform onchange=model_jump('parent', this)
   option value=0/option
  ?
  foreach ($nav_model_names as $index = $element) {
$InputString = $element;
 echo option value=$InputString$InputString/option\n;
   }
 ?
  /select

Hope that helps.
Steve

- Original Message - 
From: Phpu [EMAIL PROTECTED]
To: Steve Douville [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 9:26 AM
Subject: Re: [PHP] Problems with arrays


 Here is the code:

 select name=model class=gform onchange=model_jump('parent', this)
option value=0
   ?
   foreach ($nav_model_names as $index = $element) {
 $InputString = $element;
  echo $InputString;
}
  ?/option
   /select


 - Original Message -
 From: Steve Douville [EMAIL PROTECTED]
 To: Phpu [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Sent: Thursday, June 17, 2004 4:23 PM
 Subject: Re: [PHP] Problems with arrays


  Can you give us the code from select to /select?
  - Original Message -
  From: Phpu [EMAIL PROTECTED]
  To: Steve Douville [EMAIL PROTECTED]
  Cc: [EMAIL PROTECTED]
  Sent: Thursday, June 17, 2004 9:14 AM
  Subject: Re: [PHP] Problems with arrays
 
 
   I want the element of the array to be displayed in a select field
  
  
  
   - Original Message -
   From: Steve Douville [EMAIL PROTECTED]
   To: Phpu [EMAIL PROTECTED]
   Cc: [EMAIL PROTECTED]
   Sent: Thursday, June 17, 2004 4:12 PM
   Subject: Re: [PHP] Problems with arrays
  
  
What are you outputting? html, text, email body...??
- Original Message -
From: Phpu [EMAIL PROTECTED]
To: Oliver Hankeln [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Sent: Thursday, June 17, 2004 9:06 AM
Subject: Re: [PHP] Problems with arrays
   
   
 I've tried this but it is not working ...

 Thanks anyway
 - Original Message -
 From: Oliver Hankeln [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Thursday, June 17, 2004 4:04 PM
 Subject: Re: [PHP] Problems with arrays


  Phpu wrote:
 
   Hi,
  
   I have this array:
  
   $array = array(element1, element2, element3, element4)
  
   I want to list all elements of this array, so i used:
  
 foreach ($array as $index = $element) {
   $InputString = $element;
echo $InputString;
  }
  
   but this code lists the elements like this: element1 element2
   element3
 element4
  
   How can i list my elements like this:
   element1
   element2
   element3
   element4
 
  That's not a problem with arrays. This is one with outputting.
You
   need
  to add a newline to your echo Statement. Either echo
 $InputString\n
  ;
  or echo $InputStringbr; depending on wether you use html or
  plain
 text.
 
  Oliver
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 

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





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






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



Re: [PHP] Problems with arrays

2004-06-17 Thread Daniel Clark
 echo $InputString . 'BR';   // for HTML

 echo $InputString\n;  // for output to screen

Hi,

I have this array:

$array = array(element1, element2, element3, element4)

I want to list all elements of this array, so i used:

  foreach ($array as $index = $element) {
$InputString = $element;
 echo $InputString;
   }

but this code lists the elements like this: element1 element2 element3 element4

How can i list my elements like this: 
element1
element2
element3
element4


Thanks


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



RE: [PHP] Problems with arrays

2004-06-17 Thread Ford, Mike [LSS]
On 17 June 2004 14:27, Phpu wrote:

 Here is the code:
 
 select name=model class=gform
 onchange=model_jump('parent', this)
option value=0
   ?
   foreach ($nav_model_names as $index = $element) {
 $InputString = $element;
  echo $InputString;
}
  /option
   /select

Each option needs to be in, er, option/option tags, do you want something like:

   foreach ($nav_model_names as $index = $element) {
  echo option value='$index'$element/option\n;
   }

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Headingley Campus, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 

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