OOP쪽으로 필사적으로 이동하려고하지만 사용하려고 할 때 주위를 감쌀 수 없습니다. 나는 기계공을 얻지 만 그들을 사용할 때는 클릭하지 않는 것입니다. 현재 시나리오가 OOP 접근 방식에 익숙하다면 궁금합니다.PHP OOP vs 인라인
3 페이지가 있습니다. Details.php는 두 개의 side div를 보여줍니다. 사용자가 메모를 추가 할 수있는 곳과 MySQL에 저장된 이전 메모를 볼 수있는 곳. 그들은 Details.php의 AJAX 기능을 통해 메모를 추가하고 메모를 가져올 수 있습니다. javascript 함수는 add_notes.php를 호출하여 메모를 데이터베이스에 추가하고 load_notes.php를 호출하여 Jquery .load()를 통해 페이지에 메모를로드하고 div를 새로 고치기 위해 새 메모를 제출할 때도 메모를로드합니다.
나는 초보자이지만이 코드를 구성하는 데 더 좋은 방법이 있다고 생각합니다. 나는 프레임 워크를 살펴볼 것이지만,이 프로젝트에서 이미 무릎 깊숙이 있으므로 OOP 아이디어를 더 잘 찾아내는 방법이나 유효성 검사를 가능한 한 능률적으로 수행 할 방법을 찾고있다. 모든 의견이 도움이됩니다!
DETAILS.PHP
<script type="text/javascript">
$(document).ready(function(){
//When loading page load notes/messages tables and then reload when ajax is done
$('#note_holder').load('load_notes.php?subcat=<? echo $subcat;?>');
//onclick handler send message btn
$("#notes_submit").click(function(){
$(this).closest('form').submit(function(){
return false;
});
var frm = $(this).closest('form');
var data = $(frm).serialize();
if($(frm).valid()){
$.post(
"../php/add_notes_ajax.php",
data,
function(data){
$('#note_holder').load('load_notes.php?subcat=<? echo $subcat;?>');
}
);
}
});
});
</script>
<div style="float:left; margin-left:15px;">
<form name="messages1" class="form" id="myforma" method="post" action="#" enctype="multipart/form-data">
<fieldset style="width:500px; height:400px; overflow:auto; font-size:11px;">
<legend>Click to View Previous Notes/Messages</legend>
<div style="height:350px; overflow:auto;" class="note_holder" id="note_holder">
<!--This div is being called from the ajax script to load add_notes_ajax.php-->
</div>
</fieldset>
<div style="margin-top:20px;"></div>
</form>
</div>
<div style=" float:right;">
<form name="notes" class="notes" id="notes" method="post" action="#" enctype="multipart/form-data">
<fieldset style="width:300px; height:400px;">
<legend>Enter a Note</legend>
<div style="margin-top:00px;"></div>
<div>
<textarea rows="20" cols="20" style="height:300px; width:290px;" name="notes"></textarea>
<input type="submit" name="notes_submit" id="notes_submit" value="Submit Note" class="button" />
<input type="hidden" name="subcat" value= "<?php echo $subcat; ?>" />
</div>
</fieldset>
<div style="margin-top:20px;"></div>
</form>
</div>
ADD는 AJAX.PHP
<?php
include_once('../bootstrap.php');
include_once('../site_globals/common_functions.php');
include_once('../site_globals/common_queries.php');
include_once('../php/gump.class.php');
page_protect();
error_reporting(0);
$firstname = filter($_SESSION['user_name']);
$myid = filter($_SESSION['user_id']);
// All the variables from the submission form
$notes = filter($_POST['notes']);
$subcat = filter($_POST['subcat']);
//Insert Notes into the database
$stmt = $dbh->prepare('
INSERT INTO `notes`
(date , sub_cat_id , notes)
VALUES
(:date , :subcat , :notes)
');
$stmt->bindValue('subcat', $subcat);
$stmt->bindValue('date', date('Y-m-d H:i:s'));
$stmt->bindValue('notes', $notes);
$stmt->execute();
echo "This note was added successfully";
exit;
?>
을 말한다. LOAD NOTES.PHP 그것은 절대적으로
<table width="100%">
<thead style="text-align:left; ">
<tr style="font-size:14px; font-weight:bold;">
<!-- <th><input class="check-all" type="checkbox" /></th>-->
<th>Date</th>
<th >Contents</th>
<th>Preview/Print</th>
</tr>
</thead>
<?php while ($messages_row = mysql_fetch_object($messages_res)):?>
<tr>
<td><a target="_blank" href="../site_hospital_files/thread.php?question_id=<?php echo $messages_row->question_id;?>"><?php echo substr($messages_row->reply, 0, 20) . '...';?></a></td>
<td><?php echo date('Y-m-d', strtotime($messages_row->date_added));?></td>
<td><a href="../site_hospital_files/pdf_messages_notes.php?msg_id=<?php echo $messages_row->question_id;?>&var1=<?php echo $subcat;?>">Create PDF</a></td>
</tr>
<?php endwhile;?>
<?php while($notes_row = $notes_res->fetch(PDO::FETCH_ASSOC)):?>
<tr>
<td><?php echo $notes_row[date]; ?></td>
<td><?php echo substr($notes_row[notes], 0, 50).'...';?></td>
<td><a href="pdf_messages_notes.php?note_id=<?php echo $notes_row->sub_cat_id; ?>&var1=<?php echo $subcat;?>">View</a></td>
</tr>
<?php endwhile;?>
</table>
이 시점에서 나는 그것에 대해 너무 걱정하지 않을 것입니다. 항상 개선 할 수있는 방법이 있지만, 현재하고있는 일은 나쁘지 않습니다. PDO를 사용하고 있습니다. –
...하지만 왜 'mysql_fetch_object'가 무작위입니까? – deceze
그리고이 질문은 http://codereview.stackexchange.com에 더 적합합니다. 여기서는 그렇지 않습니다. – deceze