i have a admin page for add or remove jobs in a table. think we have 10 job in table:
1 ... 10
yeah it is simple but what will be done if admin want remove second job of table? table will have:
1,3 ... 10
and new jobs will add as:
11 to N
i need a right way to sort values after deleting.
this is fetching values of database table to choose and then remove:
<form name="form2" method="post" action="delete.php" >
<?php
$db_host = 'localhost';
$db_name= 'site';
$db_table= 'job_list';
$db_user = 'root';
$db_pass = '';
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
mysql_query("SET CHARACTER SET utf8");
$dbresult=mysql_query("SELECT * FROM $db_table",$con);
echo "شغلی که می خواهید حذف کنید انتخاب نمایید: ";
echo '<br/>';
echo '<select name="delete">';
while($amch=mysql_fetch_assoc($dbresult))
{
echo '<option value="'.$amch['job_id'].'">'.$amch['job_name'].'</option>';
}
echo '</select>'; ?> <br/>
<input name="submit2" type="submit" value="submit2" />
</form>
and this is my delete.php:
<?php
$db_host = 'localhost';
$db_name= 'site';
$db_table= 'job_list';
$db_user = 'root';
$db_pass = '';
$con = mysql_connect($db_host,$db_user,$db_pass) or die("خطا در اتصال به پايگاه داده");
mysql_query("SET NAMES 'utf8'", $con);
mysql_query("SET CHARACTER SET 'utf8'", $con);
mysql_query("SET character_set_connection = 'utf8'", $con);
$selected=mysql_select_db($db_name, $con) or die("خطا در انتخاب پايگاه داده");
$ins = "DELETE FROM job_list
where job_id='" . mysql_escape_string($_POST['delete']) . "'";
$dbresult=mysql_query($ins,$con);
echo "('" . mysql_escape_string($_POST['delete']) . "')";
?>