开发者

How to create a Dynamic Phonebook with Groups functionality

I want to create an online phone book where user can add as many contact as he want and he must be able to create and divide those contact into groups. For eg. Friends, Family etc. All the groups must be created 开发者_StackOverflow社区or deleted by the user. Can anyone help me..

Any good tutorial or a book reference will do. I will be using PHP, MySQL and a little bit of AJAX and jQuery.

Thanks


http://learning-computer-programming.blogspot.com/2008/05/creating-simple-phone-book-in-php.html will give u general idea for creating phone book.

For categorizing ur book u would be needing another table storing the nature and id of the group(group_table) which u can thru a field in main phone_table


config.php

<?php

$dbname = "phonebook"; // name of database

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("phonebook") or die(mysql_error());

?> 

add.php

<!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Phone book form</title>
<style type="text/css">
body {
    margin: 0 12%;
    width: 990px;   

}
form {
      width: 30em;
} 
fieldset {
    margin: 1em 0; 
    padding: 1em;
    border-width : .1em ;
    border-style: solid;
} 
form div {
    padding: 0.4em 0;
} 

label {
    display:block;
} 
input {
  width: 20em;
}

input.submit {
  width: auto;
}

</style>
</head>

<body>
<p>Phone Book - Enter your contact's details</p>
<form method="post" action="index.php">
<p><label for="name">Name:</label><input type="text" name="username" maxlength="20" title="Enter Name"></p>
<p><label for="phonenumber">Phone Number</label><input type="text" maxlength="12" name="phone" title="Enter phone number"></p>
<p><label for="town">Town</label><input type="text" maxlength="25" title="Enter name of town" name="town"></p>
<input type="submit" name="save" value="Save Data">
</form>
</body>

</html><!DOCTYPE html>
<html>

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Phone book form</title>
<style type="text/css">
body {
    margin: 0 12%;
    width: 990px;   

}
form {
      width: 30em;
} 
fieldset {
    margin: 1em 0; 
    padding: 1em;
    border-width : .1em ;
    border-style: solid;
} 
form div {
    padding: 0.4em 0;
} 

label {
    display:block;
} 
input {
  width: 20em;
}

input.submit {
  width: auto;
}

</style>
</head>

<body>
<p>Phone Book - Enter your contact's details</p>
<form method="post" action="index.php">
<p><label for="name">Name:</label><input type="text" name="username" maxlength="20" title="Enter Name"></p>
<p><label for="phonenumber">Phone Number</label><input type="text" maxlength="12" name="phone" title="Enter phone number"></p>
<p><label for="town">Town</label><input type="text" maxlength="25" title="Enter name of town" name="town"></p>
<input type="submit" name="save" value="Save Data">
</form>
</body>

</html>

index.php

<?php
include_once('config.php'); // call database login details page

if(isset($_POST['save'])) {

    $name = strip_tags($_POST['username']);
    $phone = strip_tags($_POST['phone']);
    $town = strip_tags($_POST['town']);

    $query = "INSERT INTO my_contacts(name,phonenumber,town) VALUES('$name', '$phone', '$town')";
    $result = mysql_query($query);

    if($result) {
       echo "Data successfully stored!";
    }
    else {
       echo "Data was NOT saved!";
       echo "<p> Query: ' $query  ' </p>";
    }
}

$query = "SELECT * from my_contacts";
$result = mysql_query($query);
echo "<h3>My Contact's Data</h3>";
echo '<table border = "1">';
echo "<tr><td>Id</td><td>Name</td><td>Phone Number</td><td>Town</td></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>".$row['id']."</td><td><a href='index.php?ID=$row[id]'>".$row['name']."</a></td><td>".$row['phonenumber'].
"</td><td>".$row['town']."</td></tr>";

}
echo "</table>"; 
?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜