[PHP-DB] RE: [PHP] Re: ARRAY, IF & INSERT

2002-06-24 Thread César Aracena

> the name <> 0 was a sql-query - it will return a ressource which will
> enable you to make something like
> 
> $i=0;
> while($row = mysql_fetch_assoc($nameless_result){
> 
> #psuedo-code#
> # mysql_query=("insert into table set relativenumber = 'jr$i' where
> ID=$row["ID"]");
> }

[César L. Aracena] I think you just showed me the smartest way of doing
it. After I deal with a deadline here, I will change my hard coded
script in order to try it... will let you know.

Thanks a lot.


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




[PHP-DB] Re: [PHP] Re: ARRAY, IF & INSERT

2002-06-23 Thread Jesper Brunholm

César aracena wrote:
> The catch would be to make PHP to auto assign the relatives "level" by
> knowing it has to start from $i=1 and loop $i++ until no other kid is
> inserted. Now that I write it, it seems I could use a for loop, but what
> should be the structure of it using the $name <> 0 you told me?

the name <> 0 was a sql-query - it will return a ressource which will 
enable you to make something like

$i=0;
while($row = mysql_fetch_assoc($nameless_result){

#psuedo-code#
# mysql_query=("insert into table set relativenumber = 'jr$i' where 
ID=$row["ID"]");
}

regards

Jesper Brunholm

btw: please do not write to my private email

-- 
Phønix - Danish folk music from young musicians - http://www.phonixfolk.dk



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




[PHP-DB] RE: [PHP] Re: ARRAY, IF & INSERT

2002-06-21 Thread César Aracena

Thanks for the input. I wasn't considering the possibility of making a
new table for kids until now which seems pretty logic when trying to
save space. The only thing missing now is how to assign a unique
relation number for each kid/relative. That's 1 for the first born, 2
for the second one, etc... and it can't be done by auto_incrementing,
for it will start over when a new member is inserted... i.e. the
relatives table should show:

Member  level   nameaddress 
00251   Jr.1same as 0025/0
00252   Jr.2same as 0025/0
00261   Jr.1same as 0026/0
00262   Jr.2same as 0026/0
00263   Jr.3same as 0026/0

The catch would be to make PHP to auto assign the relatives "level" by
knowing it has to start from $i=1 and loop $i++ until no other kid is
inserted. Now that I write it, it seems I could use a for loop, but what
should be the structure of it using the $name <> 0 you told me?

Thanks

> -Original Message-
> From: Jesper Brunholm [mailto:[EMAIL PROTECTED]]
> Sent: Friday, June 21, 2002 6:56 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: [PHP] Re: ARRAY, IF & INSERT
> 
> (i am new to these groups, but shouldn't there be a follow-up-to on a
> X-post?)
> 
> César aracena wrote:
> > I have this form in which one Administrator can insert new members
and
> > after that, in another page, a form where he/she can insert the new
> > member’s sons & daughters. I want to display a table with “text
inserts”
> > into the admin can type let’s say a maximum of 5 kids in the second
> > page.
> 
> The number doesn't matter if you design you db well (I suppose we are
> talking database).
> 
> I suppose that you have a table with members with unique ID's?
> 
> Make a new table with relatives, where you connect to their parents
> through a ParentID-field
> 
> This way you'll avoid empty fields for the folks with eg. only 2 sons
:-)
> 
> The query for father + sons and daughters would then be like
> 
> mysql_query("
> select members.Name, members.ID, relatives.Name as RelativeName,
> relatives.ID
> from parents, relatives
> where parents.ID = relatives.ParentID
> ")
> 
> The “members” table will have one memberID field (which will be
> > shared between parents and kids) and a levelID which will grant 0
for
> > the parent and 1, 2, 3, 4, 5 for the kids.
> 
> You _can_ put them all in the same table, but I suppose that you have
a
> lot of data stored on the parents/members, that is non-existing and
> irellevant for the children - this will give a lot of empty fields,
> which is why i propose the solution above...
> 
> > Now, how do I tell PHP to make an array from the kids input, but
only
> > from the fields in which let’s say the “name” field was filled out
in
> > order to spend the necessary table’s rows. Another thing… the Array
> > should also specify new levelID’s for each kid from 1 to 5. It would
be
> > great if you also show me how to deal with it after it’s created.
> 
> It's easy to select only rows with contents for at certain field:
> 
> select * from relatives
> where Name <> 0
> 
> I hope this was of some help?
> 
> regards
> 
> Jesper Brunholm
> 
> --
> Phønix - Danish folkmusic from young musicians -
http://www.phonixfolk.dk
> 
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php


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