【问题标题】:How to create a Dynamic Phonebook with Groups functionality如何创建具有群组功能的动态电话簿
【发布时间】:2010-04-22 13:22:05
【问题描述】:

我想创建一个在线电话簿,用户可以在其中添加任意数量的联系人,并且他必须能够创建这些联系人并将其分组。例如。朋友、家人等。所有组必须由用户创建或删除。谁能帮帮我..

任何好的教程或参考书都可以。我将使用 PHP、MySQL 以及一点 AJAX 和 jQuery。

谢谢

【问题讨论】:

    标签: php mysql codeigniter


    【解决方案1】:

    http://learning-computer-programming.blogspot.com/2008/05/creating-simple-phone-book-in-php.html 会给你创建电话簿的大致思路。

    为了对你的书进行分类,你需要另一个表来存储组(group_table)的性质和 id,你可以通过主 phone_table 中的一个字段来存储它

    【讨论】:

      【解决方案2】:

      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>"; 
      ?>
      

      【讨论】:

      • 请仅提供与问题相关的邮政编码。您在答案中粘贴了整个 html 文档。请格式化您的代码以使其可读。
      猜你喜欢
      • 2010-12-28
      • 1970-01-01
      • 2012-08-31
      • 2023-01-11
      • 1970-01-01
      • 1970-01-01
      • 2021-05-28
      • 2021-06-11
      • 1970-01-01
      相关资源
      最近更新 更多