2011-12-13 46 views
-3

下面的代碼旨在刪除記錄的id是從查詢select中在頁面上呈現的記錄。我遇到問題,如何刪除該行。 ?因此,而不是身份證=「233」」獲得表ID,並刪除你能親切地看着這個代碼,並提出解決方案感謝如何刪除此PHP代碼中的mysql表中的行?

<form name="form1" method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>"> 

<?php 


/* New Code */ 
//if($_POST['formSubmit'] == "Submit") 
if (isset($_POST['formSubmit'])) 

{ 
$courseid=$_POST['rowid']; 
$db8=& JFactory::getDBO(); 
$db8->setQuery("DELETE FROM jos_jquarks_persontraining WHERE 
    id = '233'"); 
$db8->query(); 
echo $courseid; 

} 

$database =& JFactory::getDBO(); 
// Display enrollments 
echo "<h1>"; 
echo "<span style='text-decoration: underline;'>"; 
echo "Courses : " ; 
echo "</h1>"; 
echo "</b>"; 

echo "</br>"; 
echo "</br>"; 

$database->setQuery("SELECT jos_jquarks_persontraining.id as trainingid,training.training, 
DATE_FORMAT(training.trainingDate, '%W, %M %e, %Y'), 
training.trainingHour, training.course_location, 
date_format(jos_jquarks_persontraining.timeStamp,'%m/%d/%Y') 
FROM jos_jquarks_persontraining 
INNER JOIN training ON jos_jquarks_persontraining.training_id = training.training_id 
WHERE 
    jos_jquarks_persontraining.user_id = " .$id ) ; 

if (!$database->query()) 
{ 
    echo "<script> alert('".$database->getErrorMsg()."'); </script>"; 
} 

$tableStyle = "padding: 5px;border:1px solid black"; 
$tdStyle = "padding:5px"; 
$thStyle = "padding:7px"; 

$row = $database->loadRowList(); 
if (0<count($row)) { 
    echo '<table style="', $tableStyle, '" cellpadding="7" cellspacing="7">'; 
    echo '<tr><th style="', $thStyle, '" align=center>Id</th><th style="', $thStyle, '" align=center>Course</th><th style="', $thStyle, '" align=center>Date</th> 
    <th style="', $thStyle, '" align=center>Time</th> 
<th style="', $thStyle, '" align=center>Location</th> 

<th style="', $thStyle, '" align=center>Enrollment Date</th> 
<th style="', $thStyle, '" align=center>Action</th>'; 


    $row = $database->loadRowList(); 
    foreach($row as $valuearray) { 
     echo '<tr align="center">'; 

     foreach($valuearray as $field){ 
      echo '<td style="', $tdStyle, '" align=center>', $field, '</td>'; 

     } // field 
     echo '</tr>'; 

echo '<tr align="center">'; 
echo'<td>'; 
//echo '<input type="submit" name="formSubmit" value="Unenroll" />'; 
echo '<input type="hidden" name="rowid" value="'.$row['ID'].'" ]" />'; 
echo '<input type="submit" name="formSubmit" value="Unenroll" />'; 

echo '</td>'; 
echo '</tr>'; 


    } // $valuearray 
    echo '</table>'; 
} 
// if count 
?> 
</form> 
+0

我我不知道你在問什麼,你想刪除一個表或一行嗎?這是什麼阻止你這樣做? – 2011-12-13 01:07:16

+0

是一排抱歉,我有像表:id,employeeid,name等, – user1091438

+0

然後刪除你想刪除的行。再次,什麼阻止你? – 2011-12-13 01:18:17

回答

0

我相信你想這樣的:

$db8->setQuery("DELETE FROM jos_jquarks_persontraining WHERE 
    id = '".mysql_real_escape_string($courseid)."'"); 
+0

可以用數據庫 - > setquery來代替嗎? – user1091438

+0

是否會在每行中獲取用於刪除該行的mysql id? – user1091438