[PHP] problem with array

2007-07-15 Thread Ross
I am using postcode anywhere for a 'where's my nearest' function.

All the geographical info is contained in an array, which when dumped looks 
like this

var_dump ($result);

array(1) { [0]= array(13) { [origin_postcode]= string(7) EH2 2BE 
[destination_postcode]= string(6) EH2 2BE [distance]= string(3) 
0.0 [id]= string(1) 1 [description]= string(8) good man 
[grid_east_m]= string(6) 326513 [grid_north_m]= string(6) 675115 
[longitude]= string(17) -3.17731851516552 [latitude]= string(16) 
55.9634587262473 [os_reference]= string(14) NT 26513 75115 
[wgs84_longitude]= string(17) -3.17876048499117 [wgs84_latitude]= 
string(16) 55.9634451567764 [name]= string(12) Jim Smith } }

however, when I try and echo out a single index by name I get an undefined 
index.

echo $result[description];

I can't seem to extract the bits I want from it.


Thanks,


R. 

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



Re: [PHP] problem with array

2007-07-15 Thread Jim Lucas

Ross wrote:

I am using postcode anywhere for a 'where's my nearest' function.

All the geographical info is contained in an array, which when dumped looks 
like this


var_dump ($result);

array(1) { [0]= array(13) { [origin_postcode]= string(7) EH2 2BE 
[destination_postcode]= string(6) EH2 2BE [distance]= string(3) 
0.0 [id]= string(1) 1 [description]= string(8) good man 
[grid_east_m]= string(6) 326513 [grid_north_m]= string(6) 675115 
[longitude]= string(17) -3.17731851516552 [latitude]= string(16) 
55.9634587262473 [os_reference]= string(14) NT 26513 75115 
[wgs84_longitude]= string(17) -3.17876048499117 [wgs84_latitude]= 
string(16) 55.9634451567764 [name]= string(12) Jim Smith } }


however, when I try and echo out a single index by name I get an undefined 
index.


echo $result[description];

I can't seem to extract the bits I want from it.


Thanks,


R. 



Access this like this

echo $result[0]['description'];

notice the sub-array...

--
Jim Lucas

   Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them.

Twelfth Night, Act II, Scene V
by William Shakespeare

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



[PHP] PHP problem with array keys / pointers

2006-12-17 Thread julian haffegee

Hi all,

I've a problem thats been bothering me for a week now

I have an array $animals

keys and values like this

1 = cat
2 = dog
3 = mouse
4 = horse

I want to be able to access them using either a key or a pointer, however 
the key/pointer will be a variable


without variables, if I want dog, I can either use $animals[1] or 
$animals['2']


but with a variable , eg. $x = 2
$animals[$x] will always give me 'mouse'

what syntax do I need to use for $animals[$x] to give me 'dog' when $x=2  ?

I've tried all manner of apostrophes and escaped apostrophes, but no luck. 
Can anyone help me

Thanks for your time!
jules

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



Re: [PHP] PHP problem with array keys / pointers

2006-12-17 Thread Pintér Tibor



1 = cat
2 = dog
3 = mouse
4 = horse

iwfm with array(1='cat',2='dog',3='mouse',4='horse'):

output:
Array
(
   [1] = cat
   [2] = dog
   [3] = mouse
   [4] = horse
)
dog

source:
?
$animals=array(1='cat',2='dog',3='mouse',4='horse');
print_r($animals);
$x=2;
echo $animals[$x].\n;
?

t

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



Re: [PHP] PHP problem with array keys / pointers

2006-12-17 Thread Satyam


- Original Message - 
From: julian haffegee [EMAIL PROTECTED]

To: php-general@lists.php.net
Sent: Sunday, December 17, 2006 7:31 PM
Subject: [PHP] PHP problem with array keys / pointers



Hi all,

I've a problem thats been bothering me for a week now

I have an array $animals

keys and values like this

1 = cat
2 = dog
3 = mouse
4 = horse

I want to be able to access them using either a key or a pointer, however 
the key/pointer will be a variable


without variables, if I want dog, I can either use $animals[1] or 
$animals['2']


but with a variable , eg. $x = 2
$animals[$x] will always give me 'mouse'

what syntax do I need to use for $animals[$x] to give me 'dog' when $x=2 
?


I would think that you have string keys instead of integer ones.   Perhaps 
there is some whitespace in the variable using to set the key?


For example:

$array = array(' 2' = 'dog');  // there is a whitespace before the number 2

will set the element of ordinal number 0 and key ' 2'  to 'dog'.  To get 
that value you would either ask for $array[0] or $array[' 2'].


Doing a print_r() or var_dump() on the array will let you know what the 
actual contents of both the keys and values are.


Satyam

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



Re: [PHP] PHP problem with array keys / pointers

2006-12-17 Thread Jochem Maas
don't hijack an existing thread. (i.e.
don't reply to someone elses' post/reply if your
asking a new question.

you need to learn to use var_dump(), and if you look at
the line of code below you should have everything you need
to know about numeric array keys:

$a = array(2 = foo); $b = array(2 = foo); var_dump($a, $b, ($a === $b));

julian haffegee wrote:
 Hi all,
 
 I've a problem thats been bothering me for a week now
 
 I have an array $animals
 
 keys and values like this
 
 1 = cat
 2 = dog
 3 = mouse
 4 = horse
 
 I want to be able to access them using either a key or a pointer,
 however the key/pointer will be a variable
 
 without variables, if I want dog, I can either use $animals[1] or
 $animals['2']
 
 but with a variable , eg. $x = 2
 $animals[$x] will always give me 'mouse'
 
 what syntax do I need to use for $animals[$x] to give me 'dog' when $x=2  ?
 
 I've tried all manner of apostrophes and escaped apostrophes, but no
 luck. Can anyone help me
 Thanks for your time!
 jules
 

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



Re: [PHP] PHP problem with array keys / pointers

2006-12-17 Thread julian haffegee



will set the element of ordinal number 0 and key ' 2'  to 'dog'.  To get
that value you would either ask for $array[0] or $array[' 2'].



thanks for all the comments so far, i'm not sure you are understanding what 
I am asking for.

My problem is NOT knowing what is in the arrays, but how to access them.

My ordial number/key is a variable, and I need to sometimes use it as a key, 
and sometimes as an ordial


so I need 2 ways of writing $array[$x],

one being equivalent to $array[0] - $x is treated as an integer
and one being equivalentt to $array['0'] - $x is treated as a string

so far I can only get it to work as an ordial number not a string. Any 
attempt at apostrophes around $x brings up an error


Any ideas?

Jules 


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



Re: [PHP] PHP problem with array keys / pointers

2006-12-17 Thread Robert Cummings
On Sun, 2006-12-17 at 23:19 +, julian haffegee wrote:
  will set the element of ordinal number 0 and key ' 2'  to 'dog'.  To get
  that value you would either ask for $array[0] or $array[' 2'].
 
 
 thanks for all the comments so far, i'm not sure you are understanding what 
 I am asking for.
 My problem is NOT knowing what is in the arrays, but how to access them.
 
 My ordial number/key is a variable, and I need to sometimes use it as a key, 
 and sometimes as an ordial
 
 so I need 2 ways of writing $array[$x],
 
 one being equivalent to $array[0] - $x is treated as an integer
 and one being equivalentt to $array['0'] - $x is treated as a string

$array['0'] and $array[0] are identical in PHP. The string '0' will be
automatically juggled to an integer when used as an index. You CANNOT
differentiate even if you want.

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



[PHP] Problem with array

2005-06-17 Thread Ross
As with my previous post the problem is the pieces of the array can vary 
from 1 to 4 items. So pieces 3 and 4 are often undefined giving the 
'undefined index' notice. All I really want to do is display the array 
pieces if they EXIST. But as they are inside a echo statement so I can't 
even to a for loop...can I?


Any ideas?

R.


if ($quantity == 0){

}
   else {

 $pieces = explode( , $quantity);


   $formatted_price = sprintf('%0.2f', $pricecode);
  echo table width=\240\ border=\0\ cellpadding=\2\ 
cellspacing=\5\trtd valign=\top\ align=\right\ 
width=\40\$pieces[0]/tdtd align=\left\ width=\60\/tdtd 
align=\left\ width=\200\$pieces[1]  $pieces[2] $pieces[3] 
$pieces[4]/tdtd valign=\top\ align=\left\ 
width=\80\$formatted_price/td/tr/table;





   }
   }

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



Re: [PHP] Problem with array

2005-06-17 Thread Rory Browne
Not sure if it works for numeric indices, but maybe you could replace
$piece[3] with (array_key_exists(3, $piece) ?  $piece[3] : ). If you
want you could abstract that into a function, like

function array_access_element($key, $srch_array, $def=){
return array_key_exists($key, $srch_array) ? $srch_array[$key] : $def;
}


On 6/17/05, Ross [EMAIL PROTECTED] wrote:
 As with my previous post the problem is the pieces of the array can vary
 from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
 'undefined index' notice. All I really want to do is display the array
 pieces if they EXIST. But as they are inside a echo statement so I can't
 even to a for loop...can I?
 
 
 Any ideas?
 
 R.
 
 
 if ($quantity == 0){
 
 }
else {
 
  $pieces = explode( , $quantity);
 
 
$formatted_price = sprintf('%0.2f', $pricecode);
   echo table width=\240\ border=\0\ cellpadding=\2\
 cellspacing=\5\trtd valign=\top\ align=\right\
 width=\40\$pieces[0]/tdtd align=\left\ width=\60\/tdtd
 align=\left\ width=\200\$pieces[1]  $pieces[2] $pieces[3]
 $pieces[4]/tdtd valign=\top\ align=\left\
 width=\80\$formatted_price/td/tr/table;
 
 
 
 
 
}
}
 
 --
 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] Problem with array

2005-06-17 Thread Rick Emery

Quoting Ross [EMAIL PROTECTED]:


As with my previous post the problem is the pieces of the array can vary
from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
'undefined index' notice. All I really want to do is display the array
pieces if they EXIST. But as they are inside a echo statement so I can't
even to a for loop...can I?


Not sure about a for loop inside the echo.


Any ideas?


Yes. Something like this should work:

echo beginning html tags;
foreach ($pieces as $this_piece) {
  echo $this_piece .  ;
}
echo middle html tags;
echo $formatted_price;
echo closing html tags;

This should at least give you a starting point. I'm fairly new to php, 
so maybe one of the gurus will give a better idea (or explain why mine 
won't work, if it won't).


hth,
Rick

P.S. I would usually trim out the rest of the message, but am leaving 
the code below as reference. Sorry for the long post.



if ($quantity == 0){

   }
  else {

$pieces = explode( , $quantity);


  $formatted_price = sprintf('%0.2f', $pricecode);
 echo table width=\240\ border=\0\ cellpadding=\2\
cellspacing=\5\trtd valign=\top\ align=\right\
width=\40\$pieces[0]/tdtd align=\left\ width=\60\/tdtd
align=\left\ width=\200\$pieces[1]  $pieces[2] $pieces[3]
$pieces[4]/tdtd valign=\top\ align=\left\
width=\80\$formatted_price/td/tr/table;





  }
  }


--
Rick Emery

When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return
 -- Leonardo Da Vinci

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



RE: [PHP] Problem with array

2005-06-17 Thread Leila Lappin
Try this I think it will work.

$count = count($arry);

for ($i=0; $i$count; $i++) {
   // do something with $array[$i]
}

cout($array) brings back the number of elements in the array which limits
the lookup index.



-Original Message-
From: Rick Emery [mailto:[EMAIL PROTECTED]
Sent: Friday, June 17, 2005 2:30 PM
To: php-general@lists.php.net
Subject: Re: [PHP] Problem with array


Quoting Ross [EMAIL PROTECTED]:

 As with my previous post the problem is the pieces of the array can vary
 from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
 'undefined index' notice. All I really want to do is display the array
 pieces if they EXIST. But as they are inside a echo statement so I can't
 even to a for loop...can I?

Not sure about a for loop inside the echo.

 Any ideas?

Yes. Something like this should work:

echo beginning html tags;
foreach ($pieces as $this_piece) {
   echo $this_piece .  ;
}
echo middle html tags;
echo $formatted_price;
echo closing html tags;

This should at least give you a starting point. I'm fairly new to php,
so maybe one of the gurus will give a better idea (or explain why mine
won't work, if it won't).

hth,
Rick

P.S. I would usually trim out the rest of the message, but am leaving
the code below as reference. Sorry for the long post.

 if ($quantity == 0){

}
   else {

 $pieces = explode( , $quantity);


   $formatted_price = sprintf('%0.2f', $pricecode);
  echo table width=\240\ border=\0\ cellpadding=\2\
 cellspacing=\5\trtd valign=\top\ align=\right\
 width=\40\$pieces[0]/tdtd align=\left\ width=\60\/tdtd
 align=\left\ width=\200\$pieces[1]  $pieces[2] $pieces[3]
 $pieces[4]/tdtd valign=\top\ align=\left\
 width=\80\$formatted_price/td/tr/table;





   }
   }

--
Rick Emery

When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return
  -- Leonardo Da Vinci

--
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] Problem with array

2005-05-01 Thread Murray @ PlanetThoughtful
Hi All,

 

I have 2 function, 1 which calls another, that I am attempting to use in a
page with, currently, some problems.

 

In essence, I have a hierarchical recordset table called tbl_content (contid
and parid, where parid contains the contid of the record to which the
current record belongs). A record without a parid value indicates that the
record is a project level record. I have another table with messages that
have been attached to records in tbl_content, called tbl_content_messages.
Tbl_content_messages contains a contid field indicating the record from
tbl_content to which each message has been attached.

 

I'm trying to create a summary page at the project level (ie all records in
tbl_content that do not have a parid value) displaying the number of
messages in each project (ie, attached to any record in tbl_content that is
part of the hierarchy chain underneath the relevant project record).

 

To do this, for each project I'm trying to determine the list of child
contid values so that I can do a count(*) in tbl_content_messages using the
IN operator, so that only messages attached to records in that project's
hierarchy chain are counted.

 

To generate that child list in the summary page, I'm using:

 

?

$leaflist = listProjectChildren($d-contid); // $d-contid
contains the contid of the project being summarised

?

 

The two functions I'm calling are:

 

?

 

function listProjectChildren($contid, $list=''){

if ($contid''){

$arrtree = array();

$arrtree = buildProjectTree($contid, $level=1);

for ($i=0;$i  count($arrtree);$i++){

$list .= '{$arrtree[$i][2]}',;

 }

}

$list = substr($list, 0,-1);

unset($arrtree);

return $list;

}

 

function buildProjectTree($contid, $level=1){

if ($contid''){

global $arrtree;

$sql = SELECT contid, parid, title FROM tbl_content
WHERE parid='$contid';

$rs = mysql_query($sql);

while ($d= mysql_fetch_object($rs)){

$ind = count($arrtree);

 

$arrtree[$ind][0] = $d-title;

$arrtree[$ind][1] = $level;

$arrtree[$ind][2] = $d-contid;

$arrtree[$ind][3] = $d-parid;

buildProjectTree($d-contid, $level+1);

 

}

mysql_free_result($rs);

}

return $arrtree;

}

?

 

My problem is that when I'm iterating through all of the project level
records, it appears that the content of $arrtree is never reset. New entries
are simply placed on the end, causing the for. loop that builds the
returned $list variable in listProjectChildren() to progressively return
larger and larger lists of contid values. As you can see, I try to UNSET()
the array prior to returning the $list variable, but this doesn't seem to
help.

 

Can anyone help me figure out what I'm doing wrong?

 

Many thanks in advance!

 

Murray

 



Re: [PHP] Problem with array

2005-05-01 Thread Richard Lynch
On Sun, May 1, 2005 10:21 am, Murray @ PlanetThoughtful said:
 ?

 function listProjectChildren($contid, $list=''){

 if ($contid''){

 $arrtree = array();

 $arrtree = buildProjectTree($contid, $level=1);

 for ($i=0;$i  count($arrtree);$i++){

 $list .= '{$arrtree[$i][2]}',;

  }

 }

 $list = substr($list, 0,-1);

 unset($arrtree);

 return $list;

 }

The $arrtree in the function above has *NOTHING* to do with the $arrtree
in the function below.

Not connected at all, really.

 function buildProjectTree($contid, $level=1){

 if ($contid''){

 global $arrtree;

//Start with an empty tree every time this function is called:
$arrtree = array();

 $sql = SELECT contid, parid, title FROM
 tbl_content
 WHERE parid='$contid';

 $rs = mysql_query($sql);

 while ($d= mysql_fetch_object($rs)){

 $ind = count($arrtree);



 $arrtree[$ind][0] = $d-title;

 $arrtree[$ind][1] = $level;

 $arrtree[$ind][2] = $d-contid;

 $arrtree[$ind][3] = $d-parid;

 buildProjectTree($d-contid,
 $level+1);



 }

 mysql_free_result($rs);

 }

 return $arrtree;

 }

 ?

 My problem is that when I'm iterating through all of the project level
 records, it appears that the content of $arrtree is never reset. New
 entries
 are simply placed on the end, causing the for. loop that builds the
 returned $list variable in listProjectChildren() to progressively return
 larger and larger lists of contid values. As you can see, I try to UNSET()
 the array prior to returning the $list variable, but this doesn't seem to
 help.


 Can anyone help me figure out what I'm doing wrong?

There is *NOTHING* in the code given here that makes it right to have
$arrtree be a GLOBAL variable in your function.

That means you are probably doing that wrong too.

Try it with just the line I added, and no global $arrtree; line.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



RE: [PHP] Problem with array

2005-05-01 Thread Murray @ PlanetThoughtful
Hi Richard,

Color me confused. I removed global $arrtree; and added $arrtree =
array(); to the function buildProjectTree() and now the parent function
(listProjectChildren) returns no values at all.

I've checked the page from which listProjectChildren() is being called, and
$arrtree does not appear as a variable in it at all, so it seems global
$arrtree; was doing SOMETHING, but at this point I have no idea what.

Still trying to work this out, if anyone else has any suggestions?

Much warmth,

Murray

 -Original Message-
 From: Richard Lynch [mailto:[EMAIL PROTECTED]
 Sent: Monday, 2 May 2005 5:04 AM
 To: Murray @ PlanetThoughtful
 Cc: php-general@lists.php.net
 Subject: Re: [PHP] Problem with array
 
 On Sun, May 1, 2005 10:21 am, Murray @ PlanetThoughtful said:
  ?
 
[Here there be snippage: please see original post for outline of problem]

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



RE: [PHP] Problem with array

2005-05-01 Thread Richard Lynch
On Sun, May 1, 2005 1:08 pm, Murray @ PlanetThoughtful said:
 Color me confused. I removed global $arrtree; and added $arrtree =
 array(); to the function buildProjectTree() and now the parent function
 (listProjectChildren) returns no values at all.

 I've checked the page from which listProjectChildren() is being called,
 and
 $arrtree does not appear as a variable in it at all, so it seems global
 $arrtree; was doing SOMETHING, but at this point I have no idea what.

 Still trying to work this out, if anyone else has any suggestions?

I'm not real clear on what you are trying to do in the first place, but if
taking out the global messed up, put it back :-)

Maybe add another global $arrtree in the other function so *BOTH*
functions are using the same $arrtree?



-- 
Like Music?
http://l-i-e.com/artists.htm

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



RE: [PHP] Problem with array

2005-05-01 Thread Murray @ PlanetThoughtful
 -Original Message-
 From: Richard Lynch [mailto:[EMAIL PROTECTED]
 Sent: Monday, 2 May 2005 6:16 AM
 To: Murray @ PlanetThoughtful
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] Problem with array
 
 On Sun, May 1, 2005 1:08 pm, Murray @ PlanetThoughtful said:
  Color me confused. I removed global $arrtree; and added $arrtree =
  array(); to the function buildProjectTree() and now the parent function
  (listProjectChildren) returns no values at all.
 
  I've checked the page from which listProjectChildren() is being called,
  and
  $arrtree does not appear as a variable in it at all, so it seems global
  $arrtree; was doing SOMETHING, but at this point I have no idea what.
 
  Still trying to work this out, if anyone else has any suggestions?
 
 I'm not real clear on what you are trying to do in the first place, but if
 taking out the global messed up, put it back :-)
 
 Maybe add another global $arrtree in the other function so *BOTH*
 functions are using the same $arrtree?

(Laugh) It's probably because I'm not explaining myself well... Let me try
to outline pseudo recordsets for the 2 tables:

Tbl_content:

Contid, parid
1,
2,1
3,1
4,
5,4
6,1
7,5
8,2
9,7

Tbl_content_messages:

Msgid, contid
1,2
2,2
3,4
4,5
5,5
6,5
7,6
8,6
9,8
10,9
11,9


Okay, so what I'm trying to do is display a summary count of all of the
messages in tbl_content_messages for each project in tbl_content (in this
case the 2 records with contid of 1 and 4, as they have no parid value).

The only way I could think to do this was to create a query that did a
SELECT COUNT(*) from tbl_content_messages using the IN operator with a list
of all of the contid values associated with each project.

For the project associated with contid 1, the entire list of contids in the
project would be 1,2,3,6,8. So, my select query for that project should look
like:

SELECT COUNT(*) FROM tbl_content_messages WHERE contid IN (1,2,3,6,8)

Using the association of contid between tbl_content and
tbl_content_messages, that should return a total count of 5 messages for the
project hierarchy that begins with tbl_content record with contid of 1.

Similarly, the next project in tbl_content, with contid of 4, would be
summarized by:

SELECT COUNT(*) FROM tbl_content_messages WHERE contid IN (4,5,7,9)

Again, from the pseudo recordsets above, that should return a message count
of 6.

So, in the two functions from my original message I'm trying to build the IN
list of contid values for each of the projects.

In the page that calls the functions, I pull a recordset of all records in
tbl_content that have no parid (and thus, by definition, are projects).

Using a while loop, I move through the project recordset and for each record
in it I have $leaflist = listProjectChildren($contid);. In the example
above, for the project contid of 1, I am hoping to return from
listProjectChildren() a variable that contains the value '1,2,3,6,8', so
that this can be used in a SELECT COUNT(*) query using the IN operator to
count all messages that are attached at any level in the project hierarchy
underneath contid 1.

I know this is probably needlessly convoluted, but I inherited this table
structure from another developer and I'm trying to make sense of it in some
way.

Hope that explains a little better what I'm going on about.

Thanks again,

Murray

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



RE: [PHP] Problem with array

2005-05-01 Thread Richard Lynch
On Sun, May 1, 2005 1:46 pm, Murray @ PlanetThoughtful said:
 -Original Message-
 From: Richard Lynch [mailto:[EMAIL PROTECTED]
 Sent: Monday, 2 May 2005 6:16 AM
 To: Murray @ PlanetThoughtful
 Cc: php-general@lists.php.net
 Subject: RE: [PHP] Problem with array

 On Sun, May 1, 2005 1:08 pm, Murray @ PlanetThoughtful said:
  Color me confused. I removed global $arrtree; and added $arrtree =
  array(); to the function buildProjectTree() and now the parent
 function
  (listProjectChildren) returns no values at all.
 
  I've checked the page from which listProjectChildren() is being
 called,
  and
  $arrtree does not appear as a variable in it at all, so it seems
 global
  $arrtree; was doing SOMETHING, but at this point I have no idea what.
 
  Still trying to work this out, if anyone else has any suggestions?

 I'm not real clear on what you are trying to do in the first place, but
 if
 taking out the global messed up, put it back :-)

 Maybe add another global $arrtree in the other function so *BOTH*
 functions are using the same $arrtree?

 (Laugh) It's probably because I'm not explaining myself well... Let me try
 to outline pseudo recordsets for the 2 tables:

 Tbl_content:

 Contid, parid
 1,
 2,1
 3,1
 4,
 5,4
 6,1
 7,5
 8,2
 9,7

 Tbl_content_messages:

 Msgid, contid
 1,2
 2,2
 3,4
 4,5
 5,5
 6,5
 7,6
 8,6
 9,8
 10,9
 11,9


 Okay, so what I'm trying to do is display a summary count of all of the
 messages in tbl_content_messages for each project in tbl_content (in this
 case the 2 records with contid of 1 and 4, as they have no parid value).

Okay, I'm lost.

You're tossing around words like project, but you've got a field contid
and parid, and I read this three times and I don't know which is which.

What's a cont?
What's a par?

I assume Msg is short for message.

Type them out.  Your fingers may hurt today, but your brain will thank you
tomorrow. :-)

 The only way I could think to do this was to create a query that did a
 SELECT COUNT(*) from tbl_content_messages using the IN operator with a
 list
 of all of the contid values associated with each project.

I think you maybe want LEFT OUTER JOIN to keep the projects with 0 messages.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] problem with array diff, need to reindex array according to key

2005-04-26 Thread Angelo Zanetti
HI all,

I am using the array_diff function.
The problem im having is the array that gets returned. Well here's an
example:

this is where i assign the values to two different arrays

$a[]=0;
$a[]=1;
$a[]=2;
$a[]=3;


$b[]=1;
$b[]=4;
$b[]=0;


$diff = array_diff_assoc($a, $b);

then compare the arrays

print_r ($diff);

then print the difference between array $a and $b


Array ( [2] = 2 [3] = 3 )

now my problem is that  although the values are correct the array it
returns, they values have the same keys as the origional array.
Now my problem is that I need to get the return array to be reindexed
because I want to loop through it from element 0 till count($diff).

How do I reindex the returned array by key, to accomplish the above.

thanks in advance

-- 

Angelo Zanetti

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



Re: [PHP] Problem with array

2004-12-15 Thread Jason Wong
On Thursday 16 December 2004 13:33, Ahmed Abdel-Aliem wrote:

Put this at the beginning of all your code:

error_reporting(E_ALL);
ini_set('display_errors', TRUE);

Then run your code to see all the errors and warnings and notices that it 
generates. Then incorporate the changes below:

 i am retrieving records from database and putting each row in a array
 here is the code
 @ $db = mysql_connect ($server, $user, $pass);

Remove all '@'. Put in error checking and make use of mysql_error(), see 
examples in manual.

 while ($record=mysql_fetch_array($test_tr)){
  $record[Game_ID] = stripslashes($record[Game_ID]);

This whole stripslashes() business may not be needed. In general you should 
only use it if magic_quotes_runtime is enabled in php.ini.

Also the correct syntax is:

  $record['Game_ID'] = stripslashes($record['Game_ID']);

And if you find that you really do need to use stripslashes() because 
magic_quotes_runtime is enabled then use this instead:

  foreach ($record as $key = $val) {
$record[$key] = stripslashes($record[$val];
  }

  echo $record[Game_Esrb_Rating];
  if($Game_Esrb_Rating  1){
 $Esrb_Rate_Pic = bar_rating_star_0.gif;

If you can be certain that $Game_Esrb_Rating is within 0-5 (ie you have 
validated your data properly before inserting into the database) then you can 
simply do 

  $Esrb_Rate_Pic = bar_rating_star_{$Game_Esrb_Rating}.gif;

 my problem is with $Esrb_Rate_Pic, i can't put its value to the array
 , i used $row[Esrb_Rate_Pic] = $Esrb_Rate_Pic; but it didn't work

That's because it should be:

  $row['Esrb_Rate_Pic'] = $Esrb_Rate_Pic;

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
Robot, n.:
 University administrator.
*/

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



[PHP] Problem with array

2004-12-15 Thread Ahmed Abdel-Aliem
Hi
i am retrieving records from database and putting each row in a array
here is the code 
@ $db = mysql_connect ($server, $user, $pass);
mysql_select_db($database);
$query = SELECT Game_ID FROM games WHERE Game_Category='$Game_Category';
$result= mysql_query($query);
$total_numbers = mysql_num_rows($result);
$startingID=$_GET['startingID'];
$startingID = ($startingID) ? $startingID : 0; //if rec is passed in, use it,
$row = array();
$test_tr = mysql_query(select * from games WHERE
Game_Category='$Game_Category' order by Game_ID desc LIMIT
$startingID,
$items_numbers_list);
$num = mysql_num_rows($test_tr);
while ($record=mysql_fetch_array($test_tr)){
$record[Game_ID] = stripslashes($record[Game_ID]);
$record[Game_Picture_Small] = stripslashes($record[Game_Picture_Small]);
$record[Game_Name] = stripslashes($record[Game_Name]);
$record[Game_Title] = stripslashes($record[Game_Title]);
$record[Game_Description] = stripslashes($record[Game_Description]);
$record[Game_Full_Story] = stripslashes($record[Game_Full_Story]);
$record[Game_Screen_Shot_1] = stripslashes($record[Game_Screen_Shot_1]);
$record[Game_Screen_Shot_2] = stripslashes($record[Game_Screen_Shot_2]);
$record[Game_Screen_Shot_3] = stripslashes($record[Game_Screen_Shot_3]);
$record[Game_Status] = stripslashes($record[Game_Status]);
$record[Game_Play_Score] = stripslashes($record[Game_Play_Score]);
$record[Game_Category] = stripslashes($record[Game_Category]);
$Game_Esrb_Rating = intval($record[Game_Esrb_Rating]);
echo $record[Game_Esrb_Rating];
if($Game_Esrb_Rating  1){ 
$Esrb_Rate_Pic = bar_rating_star_0.gif;
}elseif ($Game_Esrb_Rating  2){
$Esrb_Rate_Pic = bar_rating_star_1.gif;
}elseif ($Game_Esrb_Rating  3){
$Esrb_Rate_Pic = bar_rating_star_2.gif;
}elseif ($Game_Esrb_Rating  4){
$Esrb_Rate_Pic = bar_rating_star_3.gif;
}elseif ($Game_Esrb_Rating  5){
$Esrb_Rate_Pic = bar_rating_star_4.gif;
}elseif ($Game_Esrb_Rating = 5){
$Esrb_Rate_Pic = bar_rating_star_5.gif;
}
$row[] = $record;
$row[Esrb_Rate_Pic] = $Esrb_Rate_Pic;
}

my problem is with $Esrb_Rate_Pic, i can't put its value to the array
, i used $row[Esrb_Rate_Pic] = $Esrb_Rate_Pic; but it didn't work
can anyone help?

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


Re: [PHP] problem with array

2004-10-19 Thread Minuk Choi
You say you have a database with many CHAR(60) fields?
Have you considered changing those to VARCHAR(60)?
This isn't PHP and is probably inappropriate solution(since it is not PHP 
related), but I believe a CHAR(60) defines the field as a fixed length 
character string, meaning no matter what you want to store, it is 60 
lengths.

VARCHAR(60) is a variable length(still fixed, since you have a maximum) 
length field type.

My SQL datatypes may be rusty, but try converting a small portion of your db 
to VARCHAR(60) and try pulling data off those fields.  Let me know how it 
turns out.

-Minuk
- Original Message - 
From: Dale Hersowitz [EMAIL PROTECTED]
To: 'Minuk Choi' [EMAIL PROTECTED]
Sent: Tuesday, October 19, 2004 12:38 AM
Subject: RE: [PHP] problem with array


Minuk,
After much searching and asking, I found the answer to my problem. It 
turns
out that after re-attaching my db and re-formatting the server, the db has
been slightly adjusted. Let me explain. Many of my fields are set to char
with a width of 60. As a result, when I extract data from the db, it has
extra chars or blank spaces attached to it. I am finding myself to have to
use the trim function everywhere. If you have a fix to this problem it 
would
be greatly appreciated.

Thx.
Dale
Hersh Corporation
2250 E. Imperial Hwy., 2nd Fl.
El Segundo, CA 90245 USA
Phone: (310) 563-2155 Fax: (310) 563-2101
E-mail: [EMAIL PROTECTED]
Web Site: www.hershonline.com
E-Mail Disclaimer
NOTE: This e-mail message and all attachments thereto (this message)
contain confidential information intended for a specific addressee and
purpose. If you are not the addressee (a) you may not disclose, copy,
distribute or take any action based on the contents hereof; (b) kindly
inform the sender immediately and destroy all copies thereof. Any copying,
publication or disclosure of this message, or part thereof, in any form
whatsoever, without the sender's express written consent,is prohibited. No
opinion expressed or implied by the sender necessarily constitutes the
opinion of Hersh Corporation. This message does not constitute a guarantee
or proof of the facts mentioned therein. Hersh Corporation accepts no
responsibility or liability in respect of (a) any opinion or guarantee of
fact, whether express or implied; or (b) any action or failure to act as a
result of any information contained in this message, unless such 
information
or opinion has been confirmed in writing by an authorized Hersh 
Corporation
partner or employee.
-Original Message-
From: Minuk Choi [mailto:[EMAIL PROTECTED]
Sent: Friday, October 15, 2004 5:16 PM
To: Dale Hersowitz
Subject: Re: [PHP] problem with array

Hmm... okay,
Now,  is the output you gave me the last row?  That is, that's the row you
have errors?
According to the output, it should work, since
$row['selectedCol'] exists
and $row['selectedCol'] = col0
and $row['col0'] exists.
How about this approach,  tell me what it is you are trying to accomplish
from the block of code.
In particular, explain to me what
$selectedCol=$row[selectedCol];
 echo $selectedCol;
$selectedColName=$row[$selectCol];   //--- PLEASE NOTE THIS 
SPECIFIC
is supposed to prove.
--your code--

  $query=SELECT * FROM customizeViewClients WHERE employeeNum =
$employeeNum;
  $results=mssql_query($query, $connection) or die(Couldn't execute
query);
  $numRows=mssql_num_rows($results);
   if($numRows0)
  {
$row=mssql_fetch_array($results);
   }
$selectedCol=$row[selectedCol];
 echo $selectedCol;
$selectedColName=$row[$selectCol];   //--- PLEASE NOTE THIS 
SPECIFIC

- Original Message - 
From: Dale Hersowitz [EMAIL PROTECTED]
To: 'Minuk Choi' [EMAIL PROTECTED]
Sent: Friday, October 15, 2004 1:29 PM
Subject: RE: [PHP] problem with array


Minuk,
I add that line of code and here is what came out:
selectedCol : col0  Array
(
   [0] = 1
   [employeeNum] = 1
   [1] = clientName
   [col0] = clientName
   [2] = city
   [col1] = city
   [3] = telephoneNum
   [col2] = telephoneNum
   [4] = telephoneNum2
   [col3] = telephoneNum2
   [5] = cp1FirstName
   [col4] = cp1FirstName
   [6] = 1
   [col0Active] = 1
   [7] = 1
   [col1Active] = 1
   [8] = 1
   [col2Active] = 1
   [9] = 1
   [col3Active] = 1
   [10] = 1
   [col4Active] = 1
   [11] = col0
   [selectedCol] = col0
   [12] = ASC
   [selectionType] = ASC
)
Thx.
Dale
-Original Message-
From: Minuk Choi [mailto:[EMAIL PROTECTED]
Sent: Thursday, October 14, 2004 9:04 PM
To: Dale Hersowitz
Subject: Re: [PHP] problem with array
$row['selectedCol'] returns 'clientName'???
let me guess, $row should have a column named 'clientName'?
try this and tell me the output.
  $query=SELECT * FROM customizeViewClients WHERE employeeNum =
$employeeNum;
  $results=mssql_query($query, $connection) or die(Couldn't execute
query);
  $numRows=mssql_num_rows($results);
   if($numRows0)
  {
$row=mssql_fetch_array($results);
   }
$selectedCol=$row[selectedCol

RE: [PHP] problem with array

2004-10-15 Thread Graham Cossey
 Hi guys,
 Recently, I had to reformat one of the web servers and now I have
 encountered an unusual problem. I am not sure whether this is an
 issue which
 can be fixed in the .ini file or whether its specific to the
 version of php
 I am using.

 Here is the problem:
$query=SELECT * FROM customizeViewClients WHERE employeeNum =
 $employeeNum;
$results=mssql_query($query, $connection) or die(Couldn't execute
 query);
$numRows=mssql_num_rows($results);

 if($numRows0)
{
  $row=mssql_fetch_array($results);
 }

  $selectedCol=$row[selectedCol];
   echo $selectedCol;
  $selectedColName=$row[$selectCol];   //--- PLEASE NOTE THIS SPECIFIC
ROW
[snip]

Note because you used $selectCol instead of $selectedCol?

I would also move the } to after this line so that you do not attempt to
access non-existent array elements when no rows are returned.

HTH

Graham

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



[PHP] problem with array

2004-10-14 Thread Dale Hersowitz
Hi guys,
Recently, I had to reformat one of the web servers and now I have
encountered an unusual problem. I am not sure whether this is an issue which
can be fixed in the .ini file or whether its specific to the version of php
I am using.

Here is the problem:
   $query=SELECT * FROM customizeViewClients WHERE employeeNum =
$employeeNum;
   $results=mssql_query($query, $connection) or die(Couldn't execute
query);
   $numRows=mssql_num_rows($results);

if($numRows0)
   {
 $row=mssql_fetch_array($results);
}

 $selectedCol=$row[selectedCol];
  echo $selectedCol;
 $selectedColName=$row[$selectCol];   //--- PLEASE NOTE THIS SPECIFIC
ROW


For some reason, on the last row, I am not unable to reference a particular
index in the array using a php variable. This has been working for almost 12
months and now the coding is breaking all over the place. I don't have an
answer. Any feedback would be greatly appreciated.

Thx.
Dale

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



Re: [PHP] problem with array

2004-10-14 Thread Jason Wong
On Friday 15 October 2004 09:58, Dale Hersowitz wrote:

 For some reason, on the last row, I am not unable to reference a particular
 index in the array using a php variable. This has been working for almost
 12 months and now the coding is breaking all over the place. I don't have
 an answer. Any feedback would be greatly appreciated.

echo()/print_r()/var_dump() every $variable that you use.

-- 
Jason Wong - Gremlins Associates - www.gremlins.biz
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
I love being married.  It's so great to find that one special person
you want to annoy for the rest of your life.
-- Rita Rudner
*/

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



Re: [PHP] problem with array

2004-10-14 Thread Minuk Choi
$selectedCol=$row[selectedCol];
 echo $selectedCol;
$selectedColName=$row[$selectCol];   //--- PLEASE NOTE THIS SPECIFIC
ROW
Please give me the output, what do you get from echo $selectedCol;?  If I 
had to guess, it looks like you're confusing key and value of an 
associatative array.

if
$row[selectedCol] = 12;
$row[12] does NOT equal SelectedCol.
In fact, even if you used mysql_fetch_array, you will not be able to do a 
reverse lookup like that.

Suppose you have the following :
$row['a'] = 1;
$row['b'] = 2;
$row['c'] = 1;
You can see that your approach is incorrect because what would $row[1] 
return?

If this is NOT your question, please post your output(errors and all).
- Original Message - 
From: Dale Hersowitz [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Thursday, October 14, 2004 9:58 PM
Subject: [PHP] problem with array


Hi guys,
Recently, I had to reformat one of the web servers and now I have
encountered an unusual problem. I am not sure whether this is an issue 
which
can be fixed in the .ini file or whether its specific to the version of 
php
I am using.

Here is the problem:
  $query=SELECT * FROM customizeViewClients WHERE employeeNum =
$employeeNum;
  $results=mssql_query($query, $connection) or die(Couldn't execute
query);
  $numRows=mssql_num_rows($results);
   if($numRows0)
  {
$row=mssql_fetch_array($results);
   }
$selectedCol=$row[selectedCol];
 echo $selectedCol;
$selectedColName=$row[$selectCol];   //--- PLEASE NOTE THIS SPECIFIC
ROW
For some reason, on the last row, I am not unable to reference a 
particular
index in the array using a php variable. This has been working for almost 
12
months and now the coding is breaking all over the place. I don't have an
answer. Any feedback would be greatly appreciated.

Thx.
Dale
--
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] Problem with array variables in forms

2003-02-18 Thread Chris Pudney
G'day,

Our web-host just upgraded to PHP v4.2.3 (from v4.1.2) and broke all of our 
forms that use array variables.

It appears that when the URL contains square brackets (i.e. %5B and %5D 
instead of [ and ]) then PHP doesn't parse the variables correctly.

For example,

http://www.offloadonline.com/test.php?personal[name]=johnpersonal[email]=john%40blah.com

works (you might need to paste the URL into your browser) but

http://www.offloadonline.com/test.php?personal%5Bname%5D=johnpersonal%5Bemail%5D=john%40blah.com

fails.

Can anyone suggest a workaround?

Thanks,
Chris.


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



Re: [PHP] Problem with array variables in forms

2003-02-18 Thread Chris Pudney
G'day,



It appears that when the URL contains square brackets (i.e. %5B and %5D 
instead of [ and ]) then PHP doesn't parse the variables correctly.

For example,

http://www.offloadonline.com/test.php?personal[name]=johnpersonal[email]=john%40blah.com

works (you might need to paste the URL into your browser) but

http://www.offloadonline.com/test.php?personal%5Bname%5D=johnpersonal%5Bemail%5D=john%40blah.com

fails.


Appears to be a known bug.

Rewrote my scripts to us $_REQUEST[]

Chris.




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




[PHP] Problem creating array from MySql query

2003-02-17 Thread Janyne Kizer
What we are trying to do is build an array from a query.  I don't
understand why but this is failing on the line $affiliations[] =
$affiliation_row[affiliation];  Basically there are two tables in the
database, since clubs can have multiple affiliations and the
affiliations are not set in stone, there is one table only for
affiliations.  We are trying to pull the data out of the table for
editing.  Any tips would be appreciated.  Thanks!

$affiliation_result = mysql_query(SELECT affiliation FROM
club_affiliations WHERE club_id=$id);

$affiliations = array();

 print Populating array...;
 //place affiliation data into an array that we can search later
 while($affiliation_row = mysql_fetch_array($affiliation_result)) {
  print $affiliation_row[affiliation];
  $affiliations[] = $affiliation_row[affiliation];
 }  //while


-- 
Janyne Kizer

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




Re: [PHP] Problem creating array from MySql query

2003-02-17 Thread Rick Emery
It helps if you show us all your code, not just what you think we might need.

For isntance, what does your mysql_query() statement look like?  Does it have an or
die(mysql_error())) clause?

- Original Message -
From: Janyne Kizer [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, February 17, 2003 9:04 AM
Subject: [PHP] Problem creating array from MySql query


What we are trying to do is build an array from a query.  I don't
understand why but this is failing on the line $affiliations[] =
$affiliation_row[affiliation];  Basically there are two tables in the
database, since clubs can have multiple affiliations and the
affiliations are not set in stone, there is one table only for
affiliations.  We are trying to pull the data out of the table for
editing.  Any tips would be appreciated.  Thanks!

$affiliation_result = mysql_query(SELECT affiliation FROM
club_affiliations WHERE club_id=$id);

$affiliations = array();

 print Populating array...;
 //place affiliation data into an array that we can search later
 while($affiliation_row = mysql_fetch_array($affiliation_result)) {
  print $affiliation_row[affiliation];
  $affiliations[] = $affiliation_row[affiliation];
 }  //while


--
Janyne Kizer

--
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] Problem creating array from MySql query

2003-02-17 Thread Janyne Kizer
Thanks for taking a look at this.  

?php

 mysql_connect (, , );
 mysql_select_db ();
 $result = mysql_query(SELECT * FROM clubs WHERE id=$id);
 $row = mysql_fetch_array($result);

 print Reading affiliations...;
 $affiliation_result = mysql_query(SELECT affiliation FROM
club_affiliations WHERE club_id=$id);

 print Building array...;
 $affiliations = array();

 print Populating array...;
 //place affiliation data into an array that we can search later
 while($affiliation_row = mysql_fetch_array($affiliation_result)) {
  print $affiliation_row[affiliation];
  $affiliations[] = $affiliation_row[affiliation];
 }  //while

 print Dumping array...;
 $count = count($affiliations);
 print Affiliations:;
 for ($i=0;i$count;$i++) {
  print $affiliations[$i];
 }
?

It does print the affiliations in print
$affiliation_row[affiliation]; and it works properly (except for
getting the affiliations field) if the line $affiliations[] =
$affiliation_row[affiliation]; is commented out.


Rick Emery wrote:
 
 It helps if you show us all your code, not just what you think we might need.
 
 For isntance, what does your mysql_query() statement look like?  Does it have an or
 die(mysql_error())) clause?
 
 - Original Message -
 From: Janyne Kizer [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, February 17, 2003 9:04 AM
 Subject: [PHP] Problem creating array from MySql query
 
 What we are trying to do is build an array from a query.  I don't
 understand why but this is failing on the line $affiliations[] =
 $affiliation_row[affiliation];  Basically there are two tables in the
 database, since clubs can have multiple affiliations and the
 affiliations are not set in stone, there is one table only for
 affiliations.  We are trying to pull the data out of the table for
 editing.  Any tips would be appreciated.  Thanks!
 
 $affiliation_result = mysql_query(SELECT affiliation FROM
 club_affiliations WHERE club_id=$id);
 
 $affiliations = array();
 
  print Populating array...;
  //place affiliation data into an array that we can search later
  while($affiliation_row = mysql_fetch_array($affiliation_result)) {
   print $affiliation_row[affiliation];
   $affiliations[] = $affiliation_row[affiliation];
  }  //while
 
 --
 Janyne Kizer


-- 
Janyne Kizer
CNE-3, CNE-4, CNE-5
Systems Programmer Administrator I
NC State University, College of Agriculture  Life Sciences
Extension and Administrative Technology Services

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




Re: [PHP] Problem creating array from MySql query

2003-02-17 Thread Rick Emery
where is $id set in (SELECT affiliation FROM club_affiliations WHERE club_id=$id)

Also, change to:
$query = (SELECT affiliation FROM club_affiliations WHERE club_id=$id;
$affiliation_result = mysql_query($query) or die(mysql_error());

The above will help identify bad queries.

rick
People will forget what you said. People will forget what you did.
But people will never forget how you made them feel.
- Original Message - 
From: Janyne Kizer [EMAIL PROTECTED]
To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 17, 2003 9:31 AM
Subject: Re: [PHP] Problem creating array from MySql query


Thanks for taking a look at this.  

?php

 mysql_connect (, , );
 mysql_select_db ();
 $result = mysql_query(SELECT * FROM clubs WHERE id=$id);
 $row = mysql_fetch_array($result);

 print Reading affiliations...;
 $affiliation_result = mysql_query(SELECT affiliation FROM
club_affiliations WHERE club_id=$id);

 print Building array...;
 $affiliations = array();

 print Populating array...;
 //place affiliation data into an array that we can search later
 while($affiliation_row = mysql_fetch_array($affiliation_result)) {
  print $affiliation_row[affiliation];
  $affiliations[] = $affiliation_row[affiliation];
 }  //while

 print Dumping array...;
 $count = count($affiliations);
 print Affiliations:;
 for ($i=0;i$count;$i++) {
  print $affiliations[$i];
 }
?

It does print the affiliations in print
$affiliation_row[affiliation]; and it works properly (except for
getting the affiliations field) if the line $affiliations[] =
$affiliation_row[affiliation]; is commented out.


Rick Emery wrote:
 
 It helps if you show us all your code, not just what you think we might need.
 
 For isntance, what does your mysql_query() statement look like?  Does it have an or
 die(mysql_error())) clause?
 
 - Original Message -
 From: Janyne Kizer [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, February 17, 2003 9:04 AM
 Subject: [PHP] Problem creating array from MySql query
 
 What we are trying to do is build an array from a query.  I don't
 understand why but this is failing on the line $affiliations[] =
 $affiliation_row[affiliation];  Basically there are two tables in the
 database, since clubs can have multiple affiliations and the
 affiliations are not set in stone, there is one table only for
 affiliations.  We are trying to pull the data out of the table for
 editing.  Any tips would be appreciated.  Thanks!
 
 $affiliation_result = mysql_query(SELECT affiliation FROM
 club_affiliations WHERE club_id=$id);
 
 $affiliations = array();
 
  print Populating array...;
  //place affiliation data into an array that we can search later
  while($affiliation_row = mysql_fetch_array($affiliation_result)) {
   print $affiliation_row[affiliation];
   $affiliations[] = $affiliation_row[affiliation];
  }  //while
 
 --
 Janyne Kizer


-- 
Janyne Kizer
CNE-3, CNE-4, CNE-5
Systems Programmer Administrator I
NC State University, College of Agriculture  Life Sciences
Extension and Administrative Technology Services

-- 
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] Problem creating array from MySql query

2003-02-17 Thread Janyne Kizer


Rick Emery wrote:
 
 where is $id set in (SELECT affiliation FROM club_affiliations WHERE club_id=$id)

The $id comes in from a link and it is the row ID.

 Also, change to:
 $query = (SELECT affiliation FROM club_affiliations WHERE club_id=$id;
 $affiliation_result = mysql_query($query) or die(mysql_error());

Thank you for the suggestion.  Since the line
print $affiliation_row[affiliation];

Does work, I do not think that it is a bad query in this case but you
are correct, I should clean up that section.  Thanks!

 
 The above will help identify bad queries.
 
 rick
 People will forget what you said. People will forget what you did.
 But people will never forget how you made them feel.
 - Original Message -
 From: Janyne Kizer [EMAIL PROTECTED]
 To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Monday, February 17, 2003 9:31 AM
 Subject: Re: [PHP] Problem creating array from MySql query
 
 Thanks for taking a look at this.
 
 ?php
 
  mysql_connect (, , );
  mysql_select_db ();
  $result = mysql_query(SELECT * FROM clubs WHERE id=$id);
  $row = mysql_fetch_array($result);
 
  print Reading affiliations...;
  $affiliation_result = mysql_query(SELECT affiliation FROM
 club_affiliations WHERE club_id=$id);
 
  print Building array...;
  $affiliations = array();
 
  print Populating array...;
  //place affiliation data into an array that we can search later
  while($affiliation_row = mysql_fetch_array($affiliation_result)) {
   print $affiliation_row[affiliation];
   $affiliations[] = $affiliation_row[affiliation];
  }  //while
 
  print Dumping array...;
  $count = count($affiliations);
  print Affiliations:;
  for ($i=0;i$count;$i++) {
   print $affiliations[$i];
  }
 ?
 
 It does print the affiliations in print
 $affiliation_row[affiliation]; and it works properly (except for
 getting the affiliations field) if the line $affiliations[] =
 $affiliation_row[affiliation]; is commented out.
 
 Rick Emery wrote:
 
  It helps if you show us all your code, not just what you think we might need.
 
  For isntance, what does your mysql_query() statement look like?  Does it have an 
or
  die(mysql_error())) clause?
 
  - Original Message -
  From: Janyne Kizer [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Monday, February 17, 2003 9:04 AM
  Subject: [PHP] Problem creating array from MySql query
 
  What we are trying to do is build an array from a query.  I don't
  understand why but this is failing on the line $affiliations[] =
  $affiliation_row[affiliation];  Basically there are two tables in the
  database, since clubs can have multiple affiliations and the
  affiliations are not set in stone, there is one table only for
  affiliations.  We are trying to pull the data out of the table for
  editing.  Any tips would be appreciated.  Thanks!
 
  $affiliation_result = mysql_query(SELECT affiliation FROM
  club_affiliations WHERE club_id=$id);
 
  $affiliations = array();
 
   print Populating array...;
   //place affiliation data into an array that we can search later
   while($affiliation_row = mysql_fetch_array($affiliation_result)) {
print $affiliation_row[affiliation];
$affiliations[] = $affiliation_row[affiliation];
   }  //while
 
  --
  Janyne Kizer
 
 --
 Janyne Kizer
 CNE-3, CNE-4, CNE-5
 Systems Programmer Administrator I
 NC State University, College of Agriculture  Life Sciences
 Extension and Administrative Technology Services
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Janyne Kizer
CNE-3, CNE-4, CNE-5
Systems Programmer Administrator I
NC State University, College of Agriculture  Life Sciences
Extension and Administrative Technology Services

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




Re: [PHP] Problem creating array from MySql query

2003-02-17 Thread Rick Emery
If you have to comment out $affiliations[] = $affiliation_row[affiliation];, tghen 
it's not
working, because this is the crux of your algorithm.

What error are you getting?

rick
People will forget what you said. People will forget what you did.
But people will never forget how you made them feel.
- Original Message -
From: Janyne Kizer [EMAIL PROTECTED]
To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 17, 2003 9:31 AM
Subject: Re: [PHP] Problem creating array from MySql query


Thanks for taking a look at this.

?php

 mysql_connect (, , );
 mysql_select_db ();
 $result = mysql_query(SELECT * FROM clubs WHERE id=$id);
 $row = mysql_fetch_array($result);

 print Reading affiliations...;
 $affiliation_result = mysql_query(SELECT affiliation FROM
club_affiliations WHERE club_id=$id);

 print Building array...;
 $affiliations = array();

 print Populating array...;
 //place affiliation data into an array that we can search later
 while($affiliation_row = mysql_fetch_array($affiliation_result)) {
  print $affiliation_row[affiliation];
  $affiliations[] = $affiliation_row[affiliation];
 }  //while

 print Dumping array...;
 $count = count($affiliations);
 print Affiliations:;
 for ($i=0;i$count;$i++) {
  print $affiliations[$i];
 }
?

It does print the affiliations in print
$affiliation_row[affiliation]; and it works properly (except for
getting the affiliations field) if the line $affiliations[] =
$affiliation_row[affiliation]; is commented out.


Rick Emery wrote:

 It helps if you show us all your code, not just what you think we might need.

 For isntance, what does your mysql_query() statement look like?  Does it have an or
 die(mysql_error())) clause?

 - Original Message -
 From: Janyne Kizer [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Monday, February 17, 2003 9:04 AM
 Subject: [PHP] Problem creating array from MySql query

 What we are trying to do is build an array from a query.  I don't
 understand why but this is failing on the line $affiliations[] =
 $affiliation_row[affiliation];  Basically there are two tables in the
 database, since clubs can have multiple affiliations and the
 affiliations are not set in stone, there is one table only for
 affiliations.  We are trying to pull the data out of the table for
 editing.  Any tips would be appreciated.  Thanks!

 $affiliation_result = mysql_query(SELECT affiliation FROM
 club_affiliations WHERE club_id=$id);

 $affiliations = array();

  print Populating array...;
  //place affiliation data into an array that we can search later
  while($affiliation_row = mysql_fetch_array($affiliation_result)) {
   print $affiliation_row[affiliation];
   $affiliations[] = $affiliation_row[affiliation];
  }  //while

 --
 Janyne Kizer


--
Janyne Kizer
CNE-3, CNE-4, CNE-5
Systems Programmer Administrator I
NC State University, College of Agriculture  Life Sciences
Extension and Administrative Technology Services

--
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] Problem creating array from MySql query

2003-02-17 Thread Janyne Kizer
No error.  It just times out.

Rick Emery wrote:
 
 If you have to comment out $affiliations[] = $affiliation_row[affiliation];, 
tghen it's not
 working, because this is the crux of your algorithm.
 
 What error are you getting?
 
 rick
 People will forget what you said. People will forget what you did.
 But people will never forget how you made them feel.
 - Original Message -
 From: Janyne Kizer [EMAIL PROTECTED]
 To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Monday, February 17, 2003 9:31 AM
 Subject: Re: [PHP] Problem creating array from MySql query
 
 Thanks for taking a look at this.
 
 ?php
 
  mysql_connect (, , );
  mysql_select_db ();
  $result = mysql_query(SELECT * FROM clubs WHERE id=$id);
  $row = mysql_fetch_array($result);
 
  print Reading affiliations...;
  $affiliation_result = mysql_query(SELECT affiliation FROM
 club_affiliations WHERE club_id=$id);
 
  print Building array...;
  $affiliations = array();
 
  print Populating array...;
  //place affiliation data into an array that we can search later
  while($affiliation_row = mysql_fetch_array($affiliation_result)) {
   print $affiliation_row[affiliation];
   $affiliations[] = $affiliation_row[affiliation];
  }  //while
 
  print Dumping array...;
  $count = count($affiliations);
  print Affiliations:;
  for ($i=0;i$count;$i++) {
   print $affiliations[$i];
  }
 ?
 
 It does print the affiliations in print
 $affiliation_row[affiliation]; and it works properly (except for
 getting the affiliations field) if the line $affiliations[] =
 $affiliation_row[affiliation]; is commented out.
 
 Rick Emery wrote:
 
  It helps if you show us all your code, not just what you think we might need.
 
  For isntance, what does your mysql_query() statement look like?  Does it have an 
or
  die(mysql_error())) clause?
 
  - Original Message -
  From: Janyne Kizer [EMAIL PROTECTED]
  To: [EMAIL PROTECTED]
  Sent: Monday, February 17, 2003 9:04 AM
  Subject: [PHP] Problem creating array from MySql query
 
  What we are trying to do is build an array from a query.  I don't
  understand why but this is failing on the line $affiliations[] =
  $affiliation_row[affiliation];  Basically there are two tables in the
  database, since clubs can have multiple affiliations and the
  affiliations are not set in stone, there is one table only for
  affiliations.  We are trying to pull the data out of the table for
  editing.  Any tips would be appreciated.  Thanks!
 
  $affiliation_result = mysql_query(SELECT affiliation FROM
  club_affiliations WHERE club_id=$id);
 
  $affiliations = array();
 
   print Populating array...;
   //place affiliation data into an array that we can search later
   while($affiliation_row = mysql_fetch_array($affiliation_result)) {
print $affiliation_row[affiliation];
$affiliations[] = $affiliation_row[affiliation];
   }  //while
 
  --
  Janyne Kizer
 
 --
 Janyne Kizer
 CNE-3, CNE-4, CNE-5
 Systems Programmer Administrator I
 NC State University, College of Agriculture  Life Sciences
 Extension and Administrative Technology Services
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php

-- 
Janyne Kizer
CNE-3, CNE-4, CNE-5
Systems Programmer Administrator I
NC State University, College of Agriculture  Life Sciences
Extension and Administrative Technology Services

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




Re: [PHP] Problem creating array from MySql query

2003-02-17 Thread Rick Emery
what times out?  The query? 

rick
People will forget what you said. People will forget what you did.
But people will never forget how you made them feel.
- Original Message - 
From: Janyne Kizer [EMAIL PROTECTED]
To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 17, 2003 9:51 AM
Subject: Re: [PHP] Problem creating array from MySql query


No error.  It just times out.




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




Re: [PHP] Problem creating array from MySql query

2003-02-17 Thread Janyne Kizer
I'm not sure.  It sits and spins.  If I go to view - source that
doesn't yield any additional information.  We are trying to build the
array and then use in_array to handle the data appropriately.

Rick Emery wrote:
 
 what times out?  The query?
 
 rick
 People will forget what you said. People will forget what you did.
 But people will never forget how you made them feel.
 - Original Message -
 From: Janyne Kizer [EMAIL PROTECTED]
 To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
 Sent: Monday, February 17, 2003 9:51 AM
 Subject: Re: [PHP] Problem creating array from MySql query
 
 No error.  It just times out.

-- 
Janyne Kizer
CNE-3, CNE-4, CNE-5
Systems Programmer Administrator I
NC State University, College of Agriculture  Life Sciences
Extension and Administrative Technology Services

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




Re: [PHP] Problem creating array from MySql query

2003-02-17 Thread Leif K-Brooks
I believe I've spotted your problem:

for ($i=0;   i $count;$i++) {

You left the $ out.  It's looking for a constant named i, which doesn't 
exist.

Janyne Kizer wrote:

I'm not sure.  It sits and spins.  If I go to view - source that
doesn't yield any additional information.  We are trying to build the
array and then use in_array to handle the data appropriately.

Rick Emery wrote:
 

what times out?  The query?

rick
People will forget what you said. People will forget what you did.
But people will never forget how you made them feel.
- Original Message -
From: Janyne Kizer [EMAIL PROTECTED]
To: Rick Emery [EMAIL PROTECTED]; [EMAIL PROTECTED]
Sent: Monday, February 17, 2003 9:51 AM
Subject: Re: [PHP] Problem creating array from MySql query

No error.  It just times out.
   


 


--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.





[PHP] problem with array and session

2002-08-12 Thread Ricky

Hello everybody I'd like to make a page in which the results shown can 
be bookmarked by clicking a button aside each of them.
Actually first it should check if the session is open already ... Then 
if that item(that comes from a query to a MySQL table) has been 
registered already, finally it registers all the variables in a 
multidimensional array.

this is the code:

session_start();
  
if(!session_is_registered(bkmks))
  
{session_register(bkmks)||die(WE GOT PROBLEMS MAN);
$bkmks = array(array(tab=$tab, id=$id, url=$url, nome=$nome, 
ind=$ind, com=$com, pv=$pv, tel=$tel, chi=$chi));

print htmlbody Your choice has been 
stored/body/html;   
  
  }
  
  else
  
  {

  
foreach($bkmks as $v)
  
  {
   
if(($v[tab]==$tab)($v[id]==$id)){
print htmlbody You have already chosen this item/body/html;exit;
  
  }
  
  }
  
$bkmks[][tab]=$tab;
  
$bkmks[][id]=$id;
  
$bkmks[][url]=$url;
  
$bkmks[][nome]=$nome;
  
$bkmks[][ind]=$ind;
  
$bkmks[][com]=$com;
  
$bkmks[][pv]=$pv;
  
$bkmks[][tel]=$tel;
  
$bkmks[][chi]=$chi;
 print htmlbodyYour choice has been 
stored/body/html;  
  
  }

It doesn't work! I can't figure out why.
It starts storing fine and then it seems messing up with values so it 
recognises as already stored only the variables of my first choice (the 
value stored at bkmks[0])... I tried to print values stored in the 
array: the output is a mess I don't know why!

Thanks a lot !
Bye.


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




[PHP] Problem with array

2002-04-30 Thread Carlos Fernando Scheidecker Antunes

Hello All,

I've got a form that creates checkboxes based on the number of rows on a table. The 
user has to check some of the boxes and then click submit. The boxes are named RG1, 
RG2, RG3, 

If there are 4 checkboxes and the user selects them all or selects the first, second 
and fourth, or the first third and fourth my code works. But if the user selects the 
second, third and fourth (He does not checks the first one) no information is recorded 
on my array.

Here's the code that I have to search the $HTTP_POST_VARS and then fill a array 
variable called $RG.


function SearchRGs() {
global $HTTP_POST_VARS;
global $RGs;

// fills the array variable RGs with the values of checked checkboxes that start 
with the name RG# (where # goes from 1,2,3,).
   // returns the qty of checked RGs and size of the $RGs array.

$index = count($HTTP_POST_VARS);
$count = 0;

for ($i=1; $i  $index; $i++) {
if (isset($HTTP_POST_VARS[RG$i])) {
$RGs[] = $HTTP_POST_VARS[RG$i];
$count++;
}
}

return $count;

}


Can anyone help me with this?

Why if I do not check the first checkbox on the form the array  is not filled.

Thank you,

Carlos Fernando.



Re: [PHP] Problem with array

2002-04-30 Thread Richard Emery

show the form.

- Original Message -
From: Carlos Fernando Scheidecker Antunes [EMAIL PROTECTED]
To: PHP-GENERAL [EMAIL PROTECTED]
Sent: Tuesday, April 30, 2002 10:11 AM
Subject: [PHP] Problem with array


Hello All,

I've got a form that creates checkboxes based on the number of rows on a
table. The user has to check some of the boxes and then click submit. The
boxes are named RG1, RG2, RG3, 

If there are 4 checkboxes and the user selects them all or selects the
first, second and fourth, or the first third and fourth my code works. But
if the user selects the second, third and fourth (He does not checks the
first one) no information is recorded on my array.

Here's the code that I have to search the $HTTP_POST_VARS and then fill a
array variable called $RG.


function SearchRGs() {
global $HTTP_POST_VARS;
global $RGs;

// fills the array variable RGs with the values of checked checkboxes
that start with the name RG# (where # goes from 1,2,3,).
   // returns the qty of checked RGs and size of the $RGs array.

$index = count($HTTP_POST_VARS);
$count = 0;

for ($i=1; $i  $index; $i++) {
if (isset($HTTP_POST_VARS[RG$i])) {
$RGs[] = $HTTP_POST_VARS[RG$i];
$count++;
}
}

return $count;

}


Can anyone help me with this?

Why if I do not check the first checkbox on the form the array  is not
filled.

Thank you,

Carlos Fernando.



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




[PHP] Problem Inserting Array of Rows from form

2001-07-15 Thread David

I am trying to insert an array of rows or values from a PHP form into a
MySQL database. There are six columns in the table songs: id, songname,
rating, video, album_id, movie.

Here is what I get when I submit the form
Add songs for Record Array
INSERT INTO songs VALUES (' 1, blah', ' ***', ' 45', ' 2', ' ')
id[0]=: 2 this is debug code
INSERT Failed, check the code.this is debug code

The problem seems to be with this part:

for ($i=0; $i= $songsinalbum; $i++) {
  $vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
'$album_id[$i]',
'$movie[$i]');
}

// $vals=preg_replace(^,, , $vals);
$vals=preg_replace('/^,/', '', $vals); // chop leading comma


Complete code:
When the user presses submit on the form this part executes:

  mysql_connect(192.168.0.1, mysqluser, mypassword);

$vals=' ';
for ($i=0; $i= $songsinalbum; $i++) {
  $vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
'$album_id[$i]',
'$movie[$i]');
}

// $vals=preg_replace(^,, , $vals);
$vals=preg_replace('/^,/', '', $vals); // chop leading comma

$qry=INSERT INTO songs VALUES $vals;

echo $qry;

$res=mysql_query($qry);


Here is part of the form:

?
$i = 1;
 while ($i = $songsinalbum) {
?

TD align=rightID:   /TDTDinput type=text name=id[]
size=3br/TD

TD align=rightSongname:  /TDTDinput type=text name=songname[]
size=30br/TD
?
$i++;
};




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




Re: [PHP] Problem Inserting Array of Rows from form

2001-07-15 Thread Hank Marquardt

For one, as you've written it you have a mismatch of columns vs. fields --

You're combining id and name into one field for the insert -- thus you have
five fields trying to be inserted into a table with six elemets.

You should have a print of the mysql_error() in your debug code ... I bet if
you did that's what it would tell you:)

On Sun, Jul 15, 2001 at 07:17:00AM -0600, David wrote:
 I am trying to insert an array of rows or values from a PHP form into a
 MySQL database. There are six columns in the table songs: id, songname,
 rating, video, album_id, movie.
 
 Here is what I get when I submit the form
 Add songs for Record Array
 INSERT INTO songs VALUES (' 1, blah', ' ***', ' 45', ' 2', ' ')
 id[0]=: 2 this is debug code
 INSERT Failed, check the code.this is debug code
 
 The problem seems to be with this part:
 
 for ($i=0; $i= $songsinalbum; $i++) {
   $vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
 '$album_id[$i]',
 '$movie[$i]');
 }
 
 // $vals=preg_replace(^,, , $vals);
 $vals=preg_replace('/^,/', '', $vals); // chop leading comma
 
 
 Complete code:
 When the user presses submit on the form this part executes:
 
   mysql_connect(192.168.0.1, mysqluser, mypassword);
 
 $vals=' ';
 for ($i=0; $i= $songsinalbum; $i++) {
   $vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
 '$album_id[$i]',
 '$movie[$i]');
 }
 
 // $vals=preg_replace(^,, , $vals);
 $vals=preg_replace('/^,/', '', $vals); // chop leading comma
 
 $qry=INSERT INTO songs VALUES $vals;
 
 echo $qry;
 
 $res=mysql_query($qry);
 
 
 Here is part of the form:
 
 ?
 $i = 1;
  while ($i = $songsinalbum) {
 ?
 
 TD align=rightID:   /TDTDinput type=text name=id[]
 size=3br/TD
 
 TD align=rightSongname:  /TDTDinput type=text name=songname[]
 size=30br/TD
 ?
 $i++;
 };
 
 
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
Hank Marquardt [EMAIL PROTECTED]
http://web.yerpso.net

Web  Database Development in PHP, MySQL/PostgreSQL
Small Office Networking Solutions - Debian GNU/Linux  FreeBSD
PHP Instructor - HTML Writers Guild http://www.hwg.org
*** PHP II The Cool Stuff starts July 16, 2001
*** http://www.hwg.org/services/classes/p181.1.html


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




Re: [PHP] Problem Inserting Array of Rows from form

2001-07-15 Thread David

I did add mysql_error which helped me solve part of the problem: I was missing a
single quote in the $val line after $id[$i] and before songname :  Here is the
corrected code but there is still a problem,

 $vals .=, ('$id[$i]', '$songname[$i]', '$rating[$i]', '$video[$i]',
'$album_id[$i]',
'$movie[$i]');

old code was:
$vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
 '$album_id[$i]',

Now the problem is it only inserts one row into the table, when there should be
more than one row inserted.

Here is the updated code and a sample entry:

?
if (isset($songname) isset($rating)){
   mysql_connect(24.1.15.33, webuser, );
  echo $id[0];

$vals='';
for ($i=0; $i= $songsinalbum; $i++) {
  $vals .=, ('$id[$i]', '$songname[$i]', '$rating[$i]', '$video[$i]',
'$album_id[$i]',
'$movie[$i]');
}

$vals=preg_replace('/^,/', '', $vals); // chop leading comma

$qry=INSERT INTO songs VALUES $vals;

echo $qry;

$result = mysql_db_query(movies, $qry);
// $res=mysql_query(movies, $qry);
$error_number = mysql_errno();
$error_msg = mysql_error();
echo MySQL error $error_number: $error_msg;

Here is part of the form:
TD align=rightSongname:  /TDTDinput type=text name=songname[]
size=30br/TD


Results:
Add songs for Record Array
2INSERT INTO songs VALUES (' 2', ' test', ' ***', ' ', ' 1', ' ')MySQL error 0:
id[0]=: 3
ID[1]: 3
Songname[1]: test
Rating[1]: ***
Video[1]:
Album ID[1]: 1

test was added to the database

Hank Marquardt wrote:

 For one, as you've written it you have a mismatch of columns vs. fields --

 You're combining id and name into one field for the insert -- thus you have
 five fields trying to be inserted into a table with six elemets.

 You should have a print of the mysql_error() in your debug code ... I bet if
 you did that's what it would tell you:)

 On Sun, Jul 15, 2001 at 07:17:00AM -0600, David wrote:
  I am trying to insert an array of rows or values from a PHP form into a
  MySQL database. There are six columns in the table songs: id, songname,
  rating, video, album_id, movie.
 
  Here is what I get when I submit the form
  Add songs for Record Array
  INSERT INTO songs VALUES (' 1, blah', ' ***', ' 45', ' 2', ' ')
  id[0]=: 2 this is debug code
  INSERT Failed, check the code.this is debug code
 
  The problem seems to be with this part:
 
  for ($i=0; $i= $songsinalbum; $i++) {
$vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
  '$album_id[$i]',
  '$movie[$i]');
  }
 
  // $vals=preg_replace(^,, , $vals);
  $vals=preg_replace('/^,/', '', $vals); // chop leading comma
 
 
  Complete code:
  When the user presses submit on the form this part executes:
 
mysql_connect(192.168.0.1, mysqluser, mypassword);
 
  $vals=' ';
  for ($i=0; $i= $songsinalbum; $i++) {
$vals .=, ('$id[$i], $songname[$i]', '$rating[$i]', '$video[$i]',
  '$album_id[$i]',
  '$movie[$i]');
  }
 
  // $vals=preg_replace(^,, , $vals);
  $vals=preg_replace('/^,/', '', $vals); // chop leading comma
 
  $qry=INSERT INTO songs VALUES $vals;
 
  echo $qry;
 
  $res=mysql_query($qry);
 
 
  Here is part of the form:
 
  ?
  $i = 1;
   while ($i = $songsinalbum) {
  ?
 
  TD align=rightID:   /TDTDinput type=text name=id[]
  size=3br/TD
 
  TD align=rightSongname:  /TDTDinput type=text name=songname[]
  size=30br/TD
  ?
  $i++;
  };
 
 
 
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]

 --
 Hank Marquardt [EMAIL PROTECTED]
 http://web.yerpso.net

 Web  Database Development in PHP, MySQL/PostgreSQL
 Small Office Networking Solutions - Debian GNU/Linux  FreeBSD
 PHP Instructor - HTML Writers Guild http://www.hwg.org
 *** PHP II The Cool Stuff starts July 16, 2001
 *** http://www.hwg.org/services/classes/p181.1.html

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


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