Page 1 of 1

how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 5:56 am
by mr.white
Dear forum users,

I would like to make an address book application where user adds people and then edits their info or remove them from the database. This is something that I can already do, which is very simple. But what I really need is, I would like to let user choose the amount of info he would like to add for a certain entry. I.E 4 telephone numbers, 2 addresses, 5 emails etc. How can I achieve this? It's just like what today's mobile phones have.

Thank you for your ideas and suggestions.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 9:02 am
by php_east
interesting.

how about a 'central' user table, with ID references to email, address, phone number tables etc. that way any number and any combination of data can be used. the central table will only carry references, not the data itself. a lookup table if you will.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 9:26 am
by mr.white
Oh yes! That's a great idea. And I can get it done w/o any trouble. However, how do I handle the "editing" process? Because, I need to create input fields on the go, and then get the data from them and edit the table where I store all the main data? Like, if user adds 3 phone number fields, and I get the number of them, create 3 input fields on the go with names and then when posted update them?

Any ideas?

Thanks again!
php_east wrote:interesting.

how about a 'central' user table, with ID references to email, address, phone number tables etc. that way any number and any combination of data can be used. the central table will only carry references, not the data itself. a lookup table if you will.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 10:03 am
by greyhoundcode
Could you compose each entry in XML? So maybe each row of the database is an index, your XML and a timestamp (last amended) or whatever. So your XML could be along the lines of:

Code: Select all

<name>Billy Pinecone</name>
<phone>01234 567890</phone>
<phone>98765 123678</phone>
<email>terri@hatcher.ranch.net</email>
That would be quite easy to parse when you're extracting each item to display and very easy to insert, for example, a new phone number.

Might be some weaknesses in the idea, just thought I'd throw another thought into the pan though.

Re: how shall I design an address book app.? simple.

Posted: Thu Apr 09, 2009 10:09 am
by mr.white
This is also definitely a great idea. I might as well try this one. And yes, parsing this or inserting this way should be super simple and easy. However, how am I going to handle editing process? I can create input boxes dynamically but, what do I do when it comes to editing the XML?

thank you!
greyhoundcode wrote:Could you compose each entry in XML? So maybe each row of the database is an index, your XML and a timestamp (last amended) or whatever. So your XML could be along the lines of:

Code: Select all

<name>Billy Pinecone</name>
<phone>01234 567890</phone>
<phone>98765 123678</phone>
<email>terri@hatcher.ranch.net</email>
That would be quite easy to parse when you're extracting each item to display and very easy to insert, for example, a new phone number.

Might be some weaknesses in the idea, just thought I'd throw another thought into the pan though.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 10:55 am
by greyhoundcode
Iterate through I guess.

Code: Select all

$entryData = '<data><phone>1234567</phone><phone>890123</phone></data>';
      $xml = simplexml_load_string($entryData);
  $counter = 0;
 
echo '<form action="bananas.php" method="post">';
  
foreach ($xml->phone as $phone)
{
    echo "<input type='text' name='phone-$counter' value='$phone' /> <br/> \n";
    
    $counter++;
}
 
echo '<input type="submit" value="Update" /></form>';
Though you might want to make it a bit more generic, you know, so you don't have multiple foreach loops.

Re: how shall I design an address book app.? simple.

Posted: Thu Apr 09, 2009 11:11 am
by greyhoundcode
mr.white wrote: but, what do I do when it comes to editing the XML?
Perhaps I misunderstood you first time round ... :? ... something like this would turn it back into XML (following on from my previous post) that you can shove back into the database:

Code: Select all

// Lets assume this is "bananas.php" or wherever
// the last post's form action leads ...
 
$string = '';
 
reset ($_POST);
 
// Oh oh, we're not validating our Post Data :-O
 
while (list($property, $value) = each($_POST))
{
    // Get rid of the counter value
    $property = substr($property, 0, strpos($property, '-'));
    
    // Concatenate into a new string
    $string .= "<$property>$value</$property>";
}
 
// Wrap it in <data> tags
$string = "<data>$string</data>";
 
// I'm echoing $string, but really we would update
// our database row
 
echo $string;
I'm no purist so it could be that there is a better way to rebuild the XML, but the basic process is probably similar :)

Re: how shall I design an address book app.? simple.

Posted: Thu Apr 09, 2009 11:28 am
by mr.white
greyhoundcode, thank you, very very much! you simply have given everything that I needed. you rock! lol seriously, thank you! now I'll get to work!
greyhoundcode wrote:
mr.white wrote: but, what do I do when it comes to editing the XML?
Perhaps I misunderstood you first time round ... :? ... something like this would turn it back into XML (following on from my previous post) that you can shove back into the database:

Code: Select all

// Lets assume this is "bananas.php" or wherever
// the last post's form action leads ...
 
$string = '';
 
reset ($_POST);
 
// Oh oh, we're not validating our Post Data :-O
 
while (list($property, $value) = each($_POST))
{
    // Get rid of the counter value
    $property = substr($property, 0, strpos($property, '-'));
    
    // Concatenate into a new string
    $string .= "<$property>$value</$property>";
}
 
// Wrap it in <data> tags
$string = "<data>$string</data>";
 
// I'm echoing $string, but really we would update
// our database row
 
echo $string;
I'm no purist so it could be that there is a better way to rebuild the XML, but the basic process is probably similar :)

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 11:30 am
by php_east
basically with a central user table with references as contents, and with the xml idea thrown in by grehoundcode ( many thanks ), it makes for a simple beautiful system. a little laying tinkering around may be needed, maybe the central table should also indicate type of data as well as reference, as the data could also be images,files etc so maybe a slightly different treatment of it required.

editing wise i dont see any issue. all we have to do is retrieve the values from the db, and present it in a form and shuttle back and forth from it. and certainly xml makes that a breeze. adding new data is a matter of using the next available id into the respective table.

i think the recipe is right and ripe. the only thing missing is a name to it. i don't want to get into codes yet, the architecture of the whole thing is more important. the codes are easy.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 11:33 am
by php_east
mr.white wrote:Because, I need to create input fields on the go, and then get the data from them and edit the table where I store all the main data? Like, if user adds 3 phone number fields, and I get the number of them, create 3 input fields on the go with names and then when posted update them?
not that way i think, you get the data first, based on the current user. and then you create the input fields. and of course for additional input, you would make an input field on the fly, with javascript. at the receiving end those new fields will carry an id of zero, so you know they are new and hence you insert them accordingly, and for the rest you update. least that's how i got it figured out in my head.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 11:38 am
by mr.white
yes, you are completely right. i'll do it the way grehoundcode and you suggested. It'll work perfectly. thank you as well!
php_east wrote:basically with a central user table with references as contents, and with the xml idea thrown in by grehoundcode ( many thanks ), it makes for a simple beautiful system. a little laying tinkering around may be needed, maybe the central table should also indicate type of data as well as reference, as the data could also be images,files etc so maybe a slightly different treatment of it required.

editing wise i dont see any issue. all we have to do is retrieve the values from the db, and present it in a form and shuttle back and forth from it. and certainly xml makes that a breeze. adding new data is a matter of using the next available id into the respective table.

i think the recipe is right and ripe. the only thing missing is a name to it. i don't want to get into codes yet, the architecture of the whole thing is more important. the codes are easy.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 11:47 am
by php_east
i think i might want to do this too, thanks for a marvelous idea. just thinking a few steps ahead we might want to create a simple protocol to exchange data amongst users.

remember mobiles of a certain brand can easily send each other mobile details. having this would make for a very convenient db communication. you could 'send' me the contact details from your app and it goes straight into my address book and vice versa.

xml plays a key role in simpicity and standardisation here. we just need to agree to some sort of standard for the minimum database itself. all extra info would be deemed optional and the address book application programmed to handle that in its own way.

this is already done for things like email (SMTP) and FTP so on, but unfortunately not address books. csv's are fine but they are always a two step process and prone to errors.

Re: how shall a design an address book app.? simple.

Posted: Thu Apr 09, 2009 12:32 pm
by greyhoundcode
php_east wrote:i think the recipe is right and ripe. the only thing missing is a name to it.
FRIE-UP

(F)ully (R)osterable (I)nformation (E)xchange - (U)pdatable (P)rotocol

Just kidding 8O