Re: [PHP] setting index of array as 1

2004-10-18 Thread Matthew Sims
 when create an array using:
 $new_array[] = 'something';
 first index of new array is 0

 how can I though set that first index is 1 - except reorganize array
 after is created?

 thanks

 -afan

$new_array = array(1 = 'first','second','third');

echo $new_array[1];  --- Will echo first

-- 
--Matthew Sims
--http://killermookie.org

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



Re: [PHP] setting index of array as 1

2004-10-18 Thread bbonkosk
$new_array[1] = 'something';
- or -
$new_array = array(1='something');

- Original Message -
From: Afan Pasalic [EMAIL PROTECTED]
Date: Monday, October 18, 2004 1:14 pm
Subject: [PHP] setting index of array as 1

 when create an array using:
 $new_array[] = 'something';
 first index of new array is 0
 
 how can I though set that first index is 1 - except reorganize 
 array 
 after is created?
 
 thanks
 
 -afan
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 
 

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



Re: [PHP] setting index of array as 1

2004-10-18 Thread Afan Pasalic
It's not what I was looking for. Looks like I didn't explain very well :)
look at this case:
$query = mysql_query(select name from names order by date desc);
while($result = mysql_fetch_array($query))
{
   $all_names[] = $result['name'];  
}
in this case the array $all_names starts with index 0.
I can't put
   $all_names[1] = $result['name']; 
because every next entry will get index 1 and overwrite old one and on 
the end I'll have an array of just one element :)

-afan
Matthew Sims wrote:
when create an array using:
$new_array[] = 'something';
first index of new array is 0
how can I though set that first index is 1 - except reorganize array
after is created?
thanks
-afan

$new_array = array(1 = 'first','second','third');
echo $new_array[1];  --- Will echo first
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP] setting index of array as 1

2004-10-18 Thread bbonkosk
for ($i=0; $icount($all_names); $i++)
{
  $new_array[$i+1] = $all_names[$i];
}
// just writting to a new array and incrememnting the subscript by 1

-B

- Original Message -
From: Afan Pasalic [EMAIL PROTECTED]
Date: Monday, October 18, 2004 2:33 pm
Subject: Re: [PHP] setting index of array as 1

 It's not what I was looking for. Looks like I didn't explain very 
 well :)
 
 look at this case:
 
 $query = mysql_query(select name from names order by date desc);
 while($result = mysql_fetch_array($query))
 {
$all_names[] = $result['name'];
 }
 
 in this case the array $all_names starts with index 0.
 
 I can't put
 
$all_names[1] = $result['name'];   
 
 because every next entry will get index 1 and overwrite old one 
 and on 
 the end I'll have an array of just one element :)
 
 -afan
 
 
 Matthew Sims wrote:
 when create an array using:
 $new_array[] = 'something';
 first index of new array is 0
 
 how can I though set that first index is 1 - except reorganize 
 arrayafter is created?
 
 thanks
 
 -afan
  
  
  $new_array = array(1 = 'first','second','third');
  
  echo $new_array[1];  --- Will echo first
  
 
 -- 
 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] setting index of array as 1

2004-10-18 Thread Gryffyn, Trevor
In that case, you could do this:

$x = 1;
$query = mysql_query(select name from names order by date desc);
while($result = mysql_fetch_array($query))
{
$all_names[$x] = $result['name'];   
$x++;
}


-TG

 -Original Message-
 From: Afan Pasalic [mailto:[EMAIL PROTECTED] 
 Sent: Monday, October 18, 2004 2:33 PM
 Cc: [EMAIL PROTECTED]
 Subject: Re: [PHP] setting index of array as 1
 
 
 It's not what I was looking for. Looks like I didn't explain 
 very well :)
 
 look at this case:
 
 $query = mysql_query(select name from names order by date desc);
 while($result = mysql_fetch_array($query))
 {
 $all_names[] = $result['name'];   
 }
 
 in this case the array $all_names starts with index 0.
 
 I can't put
 
 $all_names[1] = $result['name'];  
 
 because every next entry will get index 1 and overwrite old 
 one and on 
 the end I'll have an array of just one element :)
 
 -afan
 
 
 Matthew Sims wrote:
 when create an array using:
 $new_array[] = 'something';
 first index of new array is 0
 
 how can I though set that first index is 1 - except 
 reorganize array
 after is created?
 
 thanks
 
 -afan
  
  
  $new_array = array(1 = 'first','second','third');
  
  echo $new_array[1];  --- Will echo first
  
 
 -- 
 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] setting index of array as 1

2004-10-18 Thread Afan Pasalic
this one fit the best... :)
thanks TG.
thanks to all other too for ideas :)
-afan
Gryffyn, Trevor wrote:
In that case, you could do this:
$x = 1;
$query = mysql_query(select name from names order by date desc);
while($result = mysql_fetch_array($query))
{
$all_names[$x] = $result['name'];   
$x++;
}
-TG

-Original Message-
From: Afan Pasalic [mailto:[EMAIL PROTECTED] 
Sent: Monday, October 18, 2004 2:33 PM
Cc: [EMAIL PROTECTED]
Subject: Re: [PHP] setting index of array as 1

It's not what I was looking for. Looks like I didn't explain 
very well :)

look at this case:
$query = mysql_query(select name from names order by date desc);
while($result = mysql_fetch_array($query))
{
   $all_names[] = $result['name'];  
}
in this case the array $all_names starts with index 0.
I can't put
   $all_names[1] = $result['name']; 
because every next entry will get index 1 and overwrite old 
one and on 
the end I'll have an array of just one element :)

-afan
Matthew Sims wrote:
when create an array using:
$new_array[] = 'something';
first index of new array is 0
how can I though set that first index is 1 - except 
reorganize array
after is created?
thanks
-afan

$new_array = array(1 = 'first','second','third');
echo $new_array[1];  --- Will echo first
--
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] setting index of array as 1

2004-10-18 Thread Brian
Why do you want your array to start with 1 so badly?


On Mon, 18 Oct 2004 13:33:22 -0500, Afan Pasalic [EMAIL PROTECTED] wrote:
 It's not what I was looking for. Looks like I didn't explain very well :)
 
 look at this case:
 
 $query = mysql_query(select name from names order by date desc);
 while($result = mysql_fetch_array($query))
 {
$all_names[] = $result['name'];
 }
 
 in this case the array $all_names starts with index 0.
 
 I can't put
 
$all_names[1] = $result['name'];
 
 because every next entry will get index 1 and overwrite old one and on
 the end I'll have an array of just one element :)
 
 -afan
 
 
 
 
 Matthew Sims wrote:
 when create an array using:
 $new_array[] = 'something';
 first index of new array is 0
 
 how can I though set that first index is 1 - except reorganize array
 after is created?
 
 thanks
 
 -afan
 
 
  $new_array = array(1 = 'first','second','third');
 
  echo $new_array[1];  --- Will echo first
 
 
 --
 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] setting index of array as 1

2004-10-18 Thread Afan Pasalic
Because elements of the new array are actually numbers that depend on index.
working on survey and values of offered answers are actually numbers
Question
- input type=radio value=1 offered answer no 1
- input type=radio value=2 offered answer no 2
- input type=radio value=3 offered answer no 3
- input type=radio value=4 offered answer no 4
Qs ans As are pulled from database and I chosen values start with 1 to 
be less confused (value=0 for answer=1, values=1 for answer=2, ...)

And result, which is an array because I set up names of radio buttons 
that way, (after submitting) I stored in database using serialize 
functions.
I have to show some statistics and answers, stored in DB, after 
unserialize() start with 0.
And then was conflict when I pull Qs and As from DB, they start with 1s 
and Results, that start with 0

Hm, pretty complicated, ha?
:)
Now, I have a feeling I didn't go correct way. Because, calculating 
stats from serialize stored results are pain in the neck :)

-afan
Brian wrote:
Why do you want your array to start with 1 so badly?
On Mon, 18 Oct 2004 13:33:22 -0500, Afan Pasalic [EMAIL PROTECTED] wrote:
It's not what I was looking for. Looks like I didn't explain very well :)
look at this case:
$query = mysql_query(select name from names order by date desc);
while($result = mysql_fetch_array($query))
{
  $all_names[] = $result['name'];
}
in this case the array $all_names starts with index 0.
I can't put
  $all_names[1] = $result['name'];
because every next entry will get index 1 and overwrite old one and on
the end I'll have an array of just one element :)
-afan

Matthew Sims wrote:
when create an array using:
$new_array[] = 'something';
first index of new array is 0
how can I though set that first index is 1 - except reorganize array
after is created?
thanks
-afan

$new_array = array(1 = 'first','second','third');
echo $new_array[1];  --- Will echo first
--
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] setting index of array as 1

2004-10-18 Thread Brian
You should just make everything else start with a standard 0, if it's
something you output to the users, just do a +1 on it.


On Mon, 18 Oct 2004 14:35:19 -0500, Afan Pasalic [EMAIL PROTECTED] wrote:
 Because elements of the new array are actually numbers that depend on index.
 
 working on survey and values of offered answers are actually numbers
 
 Question
 - input type=radio value=1 offered answer no 1
 - input type=radio value=2 offered answer no 2
 - input type=radio value=3 offered answer no 3
 - input type=radio value=4 offered answer no 4
 
 Qs ans As are pulled from database and I chosen values start with 1 to
 be less confused (value=0 for answer=1, values=1 for answer=2, ...)
 
 And result, which is an array because I set up names of radio buttons
 that way, (after submitting) I stored in database using serialize
 functions.
 I have to show some statistics and answers, stored in DB, after
 unserialize() start with 0.
 And then was conflict when I pull Qs and As from DB, they start with 1s
 and Results, that start with 0
 
 Hm, pretty complicated, ha?
 :)
 
 Now, I have a feeling I didn't go correct way. Because, calculating
 stats from serialize stored results are pain in the neck :)
 
 -afan
 
 
 
 
 Brian wrote:
  Why do you want your array to start with 1 so badly?
 
 
  On Mon, 18 Oct 2004 13:33:22 -0500, Afan Pasalic [EMAIL PROTECTED] wrote:
 
 It's not what I was looking for. Looks like I didn't explain very well :)
 
 look at this case:
 
 $query = mysql_query(select name from names order by date desc);
 while($result = mysql_fetch_array($query))
 {
$all_names[] = $result['name'];
 }
 
 in this case the array $all_names starts with index 0.
 
 I can't put
 
$all_names[1] = $result['name'];
 
 because every next entry will get index 1 and overwrite old one and on
 the end I'll have an array of just one element :)
 
 -afan
 
 
 
 
 Matthew Sims wrote:
 
 when create an array using:
 $new_array[] = 'something';
 first index of new array is 0
 
 how can I though set that first index is 1 - except reorganize array
 after is created?
 
 thanks
 
 -afan
 
 
 $new_array = array(1 = 'first','second','third');
 
 echo $new_array[1];  --- Will echo first
 
 
 --
 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] setting index of array as 1

2004-10-18 Thread Afan Pasalic
actually, I just decide to redo DB architecture and not use serialize-ed 
info to store in DB. to much troubles with it.

thanks brian.
-afan

Brian wrote:
You should just make everything else start with a standard 0, if it's
something you output to the users, just do a +1 on it.
On Mon, 18 Oct 2004 14:35:19 -0500, Afan Pasalic [EMAIL PROTECTED] wrote:
Because elements of the new array are actually numbers that depend on index.
working on survey and values of offered answers are actually numbers
Question
- input type=radio value=1 offered answer no 1
- input type=radio value=2 offered answer no 2
- input type=radio value=3 offered answer no 3
- input type=radio value=4 offered answer no 4
Qs ans As are pulled from database and I chosen values start with 1 to
be less confused (value=0 for answer=1, values=1 for answer=2, ...)
And result, which is an array because I set up names of radio buttons
that way, (after submitting) I stored in database using serialize
functions.
I have to show some statistics and answers, stored in DB, after
unserialize() start with 0.
And then was conflict when I pull Qs and As from DB, they start with 1s
and Results, that start with 0
Hm, pretty complicated, ha?
:)
Now, I have a feeling I didn't go correct way. Because, calculating
stats from serialize stored results are pain in the neck :)
-afan

Brian wrote:
Why do you want your array to start with 1 so badly?
On Mon, 18 Oct 2004 13:33:22 -0500, Afan Pasalic [EMAIL PROTECTED] wrote:

It's not what I was looking for. Looks like I didn't explain very well :)
look at this case:
$query = mysql_query(select name from names order by date desc);
while($result = mysql_fetch_array($query))
{
 $all_names[] = $result['name'];
}
in this case the array $all_names starts with index 0.
I can't put
 $all_names[1] = $result['name'];
because every next entry will get index 1 and overwrite old one and on
the end I'll have an array of just one element :)
-afan

Matthew Sims wrote:

when create an array using:
$new_array[] = 'something';
first index of new array is 0
how can I though set that first index is 1 - except reorganize array
after is created?
thanks
-afan

$new_array = array(1 = 'first','second','third');
echo $new_array[1];  --- Will echo first
--
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