2011-11-11 3 views
0

나는이 특별한 일을하는 방법에 약간 혼란 스럽다. 내가 갖고있는 것은 데이터베이스 데이터를 나열하는 메인 디스플레이 페이지입니다. 그런 다음 삽입 양식, 삭제 양식 편집 단추 및 주석을위한 링크가 있습니다. 코멘트 버튼의 경우 빈 폼으로 가서 코멘트로 추가하여 클릭 한 레코드의 자식이 될 수 있도록해야합니다. 그러면 하위 버튼으로 새 레코드를 추가 할 수있는 설명 버튼이 있어야합니다.php 계층 적 포럼 스타일의 메뉴 보드

문제가 발생하여 도움이 될 것입니다.

<!--PHP Update--> 
<?php 

$con = mysql_connect("localhost","root",""); 

if (!$con) 
{ 
die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db("project1", $con); 

if ($_GET['action']=='delete_ok'){ 

}elseif ($_GET['action']=='edit_ok'){ 

}elseif ($_GET['action']=='comment_ok'){ 

} 


switch($_GET['action']){ 
case 'write_ok': 

$error=false; 

$msg=''; 

if($_POST['dateofbirth']=='' || !preg_match("/^(19|20)\d\d[- \\.](0[1-9]|1[012])[-  \\.](0[1-9]|[12][0-9]|3[01])$/",$_POST['dateofbirth'])){ 
    $error=true; 
    $msg.='Date of birth is required and in the correct format 0000.00.00\n'; 

} 


    if($_POST['gender']==''){ 
    $error=true; 
    $msg.='Gender is a required field\n'; 

} 


if($_POST['title']==''){ 
    $error=true; 
    $msg.='Please select your title\n'; 
} 


if($_POST['firstname']==''){ 
    $error=true; 
    $msg.='Please Enter your First Name\n'; 
} 


if($_POST['lastname']==''){ 
    $error=true; 
    $msg.='Please Enter your Last Name\n'; 
} 


if($_POST['address1']==''){ 
    $error=true; 
    $msg.='Please Enter the first line of your address\n'; 
} 


if($_POST['city']==''){ 
    $error=true; 
    $msg.='Please Enter your city of residence\n'; 
} 


    if($_POST['postcode']==''|| !preg_match("/^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$/",$_POST['postcode'])){ 
    $error=true; 
    $msg.='Please Enter a Valid Postcode\n'; 
} 


if($_POST['contactno']==''|| !preg_match("/^((\+44\s?\d{4}|\(?\d{5}\)?)\s?\d{6})|((\+44\s?|0)7\d{3}\s?\d{6})$/",$_POST['contactno'])){ 
    $error=true; 
    $msg.='Please Enter your Contact No\n'; 
} 


if($_POST['email']==''|| !preg_match("/^([a-z0-9])(([-.]|[]+)?([a-z0-9]+))(@)([a-z0-9])((([-]+)?([a-z0-9]+))?)*((.[a-z]{2,3})?(.[a-z]{2,6}))$/",$_POST['email'])){ 
    $error=true; 
    $msg.='Please Enter a Valid Email Address\n'; 
} 



if($error){ 

    echo '<script>alert("'.$msg.'");history.back()</script>'; 

}else{ 

$sql = "INSERT INTO project_data (Date_Of_Birth, Gender, Title, First_Name, Last_Name, Address_Line_1, Address_Line_2, City, Postcode, Contact_No, Email, Additional_Comment) VALUES ('".$_POST[dateofbirth]."','".$_POST[gender]."','".$_POST[title]."','".$_POST[firstname]."','".$_POST[lastname]."','".$_POST[address1]."','".$_POST[address2]."','".$_POST[city]."','".$_POST[postcode]."','".$_POST[contactno]."','".$_POST[email]."','".$_POST[note]."')"; 
    if(!mysql_query($sql,$con)) { 
     die('Error: ' . mysql_error()); 
    } 
    else{ 
     echo '<script>alert("Data Has Been Successfully Updated");</script>'; 
     echo '<meta http-equiv="Refresh" content="0;URL=pv.php">'; 
    } 
} 

break; 
case 'edit_ok': 
    $id = $_GET['id']; 

    mysql_query("UPDATE project_data SET Date_Of_Birth='".$_POST[dateofbirth]."',Gender='".$_POST[gender]."',Title='".$_POST[title]."',First_Name='".$_POST[firstname]."',Last_Name='".$_POST[lastname]."',Address_Line_1='".$_POST[address1]."',Address_Line_2='".$_POST[address2]."',City='".$_POST[city]."',Postcode='".$_POST[postcode]."',Contact_No='".$_POST[contactno]."',Email='".$_POST[email]."',Additional_Comment='".$_POST[note]."' WHERE ID='".$_GET['id']. "'") or die ("Error in query: $query. " . mysql_error()); 

    echo '<script>alert("Data Has Been Successfully Updated");</script>'; 
    echo '<meta http-equiv="Refresh" content="0;URL=pv.php">'; 
break; 
case 'delete_ok': 
    #########Delete OK Start################# 
    $id= $_GET['id']; 
    $result = mysql_query("DELETE FROM project_data WHERE ID = '$id'") or die ("Error in query: $query. " . mysql_error()); 
    echo '<script>alert("Data Has Been Successfully Updated");</script>'; 
    echo '<meta http-equiv="Refresh" content="0;URL=pv.php">'; 
    #########Delete OK End ################# 
break; 
case 'add_ok'; 

break; 
    } 
    ?> 
    <?php 
    $id=$_GET['id']; 
    $result = mysql_query("SELECT * FROM project_data WHERE id='$id'"); 
    $row = mysql_fetch_array($result); 
    ?> 

    <form method="post" action="pv.php?id=<?php echo $row['ID']?>&action=<?php echo $form_action ?>"> 
<fieldset> 
    <legend></legend> 
    <p> 
     <label for="cname">Date Of Birth</label> * 
     <input id="cname" name="dateofbirth" class="required date" value=" <?php echo $row['Date_Of_Birth']?>" /> (eg 1978.11.11) 
    </p> 
    <p> 
     <label for="cgender">Gender</label> * 
     <input type="radio" name="gender" value="Male" <?php if($row['Gender']=='male'){echo 'checked';}?>/> Male <input type="radio" name="gender" value="Female" <?php if($row['Gender']=='female'){echo 'checked';}?>/> Female </td> 
    </p> 
    <p> 
     <label for="curl">Title</label> * 
     <select name="title" id="title" class="required"> 
      <option value="">Please Select</option> 
      <option value="Mr" <?php if($row['Title']=='Mr'){echo 'selected';}?>>Mr</option> 
      <option value="Ms" <?php if($row['Title']=='Ms'){echo 'selected';}?>>Ms</option> 
      <option value="Mrs" <?php if($row['Title']=='Mrs'){echo 'selected';}?>>Mrs</option> 
      <option value="Miss" <?php if($row['Title']=='Miss'){echo 'selected';}?>>Miss</option> 
      <option value="Other" <?php if($row['Title']=='Other'){echo 'selected';}?>>Other</option> 
      </select> 
    </p> 
    <p> 
     <label for="ccomment">First Name</label>  * 
     <input type="text" name="firstname" value="<?php echo $row['First_Name']?>" maxlength="50" /> 
    </p> 


    <p> 
    <label for="cemail">Last Name</label> * 
     <input id="cemail" type="text" name="lastname" value="<?php echo $row['Last_Name']?>" maxlength="75" /> 
    </p> 
    <p> 
     <label for="ccomment">Address 1</label>* 
     <input type="text" name="address1" value="<?php echo $row['Address_Line_1']?>" maxlength="50" /> 
    </p> 
    <p> 
     <label for="ccomment">Address 2</label> 
     <input type="text" name="address2" value="<?php echo $row['Address_Line_2']?>" maxlength="50" /> 
    </p> 
    <p> 
     <label for="ccomment">City</label>* 
     <input type="text" name="city" value="<?php echo $row['City']?>" maxlength="50" /> 
    </p> 
    <p> 
     <label for="ccomment">Postcode</label>* 
     <input type="text" name="postcode" value="<?php echo $row['Postcode']?>" maxlength= "10" /> (eg LE5 5QE) 
    </p> 
    <p> 
     <label for="ccomment">Contact No</label>* 
     <input type="text" name="contactno" value="<?php echo $row['Contact_No']?>" maxlength= "12" /> (eg 077448825723) 
    </p> 
    <p> 
     <label for="ccomment">Email</label>* 
     <input type="text" name="email" value="<?php echo $row['Email']?>" maxlength= "40"/> (eg [email protected]) 
    </p> 
    <p> 
     <label for="ccomment">Comment</label> 
     <textarea rows="10" cols="30" name="note" maxlength= "500"><?php echo $row['Additional_Comment']?></textarea> 
    </p> 
    <p> 
     <input class="submit" type="submit" value="Submit"/> 
    </p> 
    <p> 
    <a href='pv.php'>Main Page</a> 
    </p> 

</fieldset> 


<?php 

//break; 
default: 


?> 


<style type="text/css"> 

</style> 


<?php 

    echo "<table border='1'> 
    <tr bgcolor ='#FFFACD'> 
    <th>ID</th> 
    <th>Date Of Birth</th> 
    <th>Gender</th> 
    <th>Title</th> 
    <th>First Name</th> 
    <th>Last Name</th> 
    <th>Address Line 1</th> 
    <th>Address Line 2</th> 
    <th>City</th> 
    <th>Postcode</th> 
    <th>Contact No</th> 
    <th>Email</th> 
    <th>Additional Info</th> 
    <th>Action</th> 
    </tr>"; 


$tbl_name="project_data";  //your table name 
// How many adjacent pages should be shown on each side? 
$adjacents = 1; 

/* 
    First get total number of rows in data table. 
    If you have a WHERE clause in your query, make sure you mirror it here. 
*/ 
$query = "SELECT COUNT(*) as num FROM $tbl_name"; 
$total_pages = mysql_fetch_array(mysql_query($query)); 
$total_pages = $total_pages[num]; 

/* Setup vars for query. */ 
$targetpage = "pv.php";  //your file name (the name of this file) 
$limit = 3;         //how many items to show per page 
$page = $_GET['page']; 
if($page) 
    $start = ($page - 1) * $limit;   //first item to display on this page 
else 
    $start = 0;        //if no page var is given, set start to 0 

/* Get data. 

order by ? 

group 
parent 
level 



*/ 
$sql = "SELECT * FROM project_data LIMIT $start, $limit"; 
$result = mysql_query($sql); 

/* Setup page vars for display. */ 
if ($page == 0) $page = 1;     //if no page var is given, default to 1. 
$prev = $page - 1;       //previous page is page - 1 
$next = $page + 1;       //next page is page + 1 
$lastpage = ceil($total_pages/$limit);  //lastpage is = total pages/items per page, rounded up. 
$lpm1 = $lastpage - 1;      //last page minus 1 

/* 
    Now we apply our rules and draw the pagination object. 
    We're actually saving the code to a variable in case we want to draw it more than once. 
*/ 
$pagination = ""; 
if($lastpage > 1) 
{ 
    $pagination .= "<div class=\"pagination\">"; 
    //previous button 
    if ($page > 1) 
     $pagination.= " <a href=\"$targetpage?page=$prev\">« previous</a> "; 
    else 
     $pagination.= " <span class=\"disabled\">« previous</span> "; 

    //pages 
    if ($lastpage < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up 
    { 
     for ($counter = 1; $counter <= $lastpage; $counter++) 
     { 
      if ($counter == $page) 
       $pagination.= " <span class=\"current\">$counter</span >"; 
      else 
       $pagination.= " <a href=\"$targetpage?page=$counter\">$counter</a> ";     
     } 
    } 
    elseif($lastpage > 5 + ($adjacents * 2)) //enough pages to hide some 
    { 
     //close to beginning; only hide later pages 
     if($page < 1 + ($adjacents * 2))   
     { 
      for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) 
      { 
       if ($counter == $page) 
        $pagination.= " <span class=\"current\">$counter</span> "; 
       else 
        $pagination.= " <a href=\"$targetpage?page=$counter\">$counter</a> ";     
      } 
      $pagination.= "..."; 
      $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; 
      $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";  
     } 
     //in middle; hide some front and some back 
     elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) 
     { 
      $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; 
      $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; 
      $pagination.= "..."; 
      for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) 
      { 
       if ($counter == $page) 
        $pagination.= "<span class=\"current\">$counter</span>"; 
       else 
        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";     
      } 
      $pagination.= "..."; 
      $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; 
      $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>";  
     } 
     //close to end; only hide early pages 
     else 
     { 
      $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; 
      $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; 
      $pagination.= "..."; 
      for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) 
      { 
       if ($counter == $page) 
        $pagination.= "<span class=\"current\">$counter</span>"; 
       else 
        $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>";     
      } 
     } 
    } 

    //next button 
    if ($page < $counter - 1) 
     $pagination.= "<a href=\"$targetpage?page=$next\">next »</a>"; 
    else 
     $pagination.= "<span class=\"disabled\">next »</span>"; 
    $pagination.= "</div>\n";  
} 


//$result = mysql_query("SELECT * FROM $tbl_name"); 
    while($row = mysql_fetch_array($result)){ 
     echo "<tr>"; 
     echo "<td>" . $row['ID'] . "</td>"; 
     echo "<td>" . $row['Date_Of_Birth'] . "</td>"; 
     echo "<td>" . $row['Gender'] . "</td>"; 
     echo "<td>" . $row['Title'] . "</td>"; 
     echo "<td>" . $row['First_Name'] . "</td>"; 
     echo "<td>" . $row['Last_Name'] . "</td>"; 
     echo "<td>" . $row['Address_Line_1'] . "</td>"; 
     echo "<td>" . $row['Address_Line_2'] . "</td>"; 
     echo "<td>" . $row['City'] . "</td>"; 
     echo "<td>" . $row['Postcode'] . "</td>"; 
     echo "<td>" . $row['Contact_No'] . "</td>"; 
     echo "<td>" . $row['Email'] . "</td>"; 
     echo "<td>" . $row['Additional_Comment'] . "</td>"; 
     echo "<td><a href='pv.php?action=edit&id=" . $row['ID']."'>Edit</a>&nbsp&nbsp<a href='pv.php?action=delete_ok&id=" . $row['ID']."'>Delete</a>&nbsp&nbsp<a href='pv.php?action=add&id=" . $row['ID']."'>Comment</a></td>"; 
     echo "</tr>"; 
     } 
    echo "</table>"; 

    echo $pagination; 

    echo "<a href='pv.php?action=write'>Insert</a>"; 



} 

mysql_close($con); 

?> 

</body> 
</html> 
+0

처럼 [이] (http://ux.stackexchange.com/questions/3864/hierarchica l-comments-usability-issues/13309 # 13309)? –

+0

그런 식으로 정렬하지만 이름, 성, dob 등 데이터 항목 목록에 대한. – mayman212

답변

0
어쩌면

완벽하지,하지만 난 그런 일을 주문할 것 :

데이터 모델링 :

|pages ([idPage], ...)| 0..n 
    1,1 |mainComments ([idPage, idMainComment], ...)| 0..n 
     1,1 |secondaryComments ([idPage, idMainComment, idSecondaryComment], ...)| 

PHP :

$query = mysql_query('SELECT * FROM mainComments WHERE idPage = 12'); 

while ($data = mysql_fetch_assoc($query)) { 
    //echo mainComments 
    //echo forms for each 

    $query2 = mysql_query('SELECT * FROM secondaryComments 
           WHERE idPage = 12 
           AND idMainComment = '.$data['idMainComment']); 

    while ($data2 = mysql_fetch_assoc($query2)) { 
     //echo secondaryComments 
     //echo forms for each 
    } 
} 
+0

내 현재 프로젝트에 대한 내 코드는 도움이된다면 위에 나와 있습니다. – mayman212