Jump to content
php.lv forumi

DELETE query, MySQL.


Eob

Recommended Posts

Tātad, ar php kodu (pirmais koda klucis) tiek no datubāzes dinamiski vilkta ārā informācija. Turpat blakus dinamiski tiek izveidota Delete poga.

<?php
include 'library/config.php';
include 'library/opendb.php';

$query  = "SELECT Pardevejs_ID, Pardevejs_vards, Pardevejs_uzvards, Pardevejs_pers_kods, Pardevejs_adrese, Pardevejs_tel_nr FROM pardevejs ORDER BY Pardevejs_ID DESC";
$result = mysql_query($query);


while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $id = $row['Pardevejs_ID'];
   $vards = $row['Pardevejs_vards'];
   $uzvards = $row['Pardevejs_uzvards'];
   $pkods = $row['Pardevejs_pers_kods'];
   $adrese = $row['Pardevejs_adrese'];
   $telnr = $row['Pardevejs_tel_nr'];
   echo "$id $vards $uzvards $pkods $adrese $telnr ";
   echo "<input name='delete' type='submit' value='Dzēst'>";
   echo "<br>";
}

include 'library/closedb.php';
?>

 

Šis ir kods, ar kuru mēģinu atdzīvināt šo Delete pogu:

<?php
if(isset($_POST['delete']))
{
  include 'library/config.php';
  include 'library/opendb.php';
  $id = $_POST['Pardevejs_ID'];
  $query2 = " DELETE FROM pardevejs WHERE Pardevejs_ID = $id";
  mysql_query($query2) or die('MySQL operācija neizdevās. Pārdevēja dati nav izdzēsti.');

  include 'library/closedb.php';

  echo "<br>Pārdevējs $vards $uzvards vaiksmīgi izdzēsts no saraksta.<br>";
}
?>

 

Problēma tāda, ka nezinu, kas īsti būtu jāliek

$id = $_POST['Pardevejs_ID'];
  $query2 = " DELETE FROM pardevejs WHERE Pardevejs_ID = $id";

vietā, lai Delete poga izdzēstu tajā pat rindiņā esošo informāciju.

 

Jebkāda veida palīdzība būtu ļoti noderīga.

Link to comment
Share on other sites

Kā izveidot maizīti: http://www.wikihow.com/Make-a-Sandwich

while($row = mysql_fetch_array($result, MYSQL_ASSOC)){
   $id = $row['Pardevejs_ID'];
   $vards = $row['Pardevejs_vards'];
   $uzvards = $row['Pardevejs_uzvards'];
   $pkods = $row['Pardevejs_pers_kods'];
   $adrese = $row['Pardevejs_adrese'];
   $telnr = $row['Pardevejs_tel_nr'];
   echo "$id $vards $uzvards $pkods $adrese $telnr ";
echo '<form method="post" action="">';
echo '<input type="hidden" name="Pardevejs_ID" value="'.$id.'>"';
   echo "<input name='delete' type='submit' value='Dzēst'>";
echo '</form>';
   echo "<br>";
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...