ไม่อยากให้มันเป็น AUto_id ครับ

ถาม-ตอบ แนะนำไอเดียว โค้ดตัวอย่าง แนวทาง วิธีแก้ปัญหา ไม่อยากให้มันเป็น AUto_id ครับ

ไม่อยากให้มันเป็น AUto_id ครับ
<?php if (!isset($_SESSION)) {  session_start(); } // อย่าลืม ต้องประการทุกครั้ง 
		require_once('../Connections/MyConnect.php'); // นำเข้าชุดเชื่อมต่อกับฐานข้อมูล
 ?>
<?php
mysql_select_db($database_MyConnect, $MyConnect);

if($_SESSION['rule']==1){  // เช็คว่า สิทธิ์การเข้าถึงข้อมูลเป็น admin หรือไม่ โดย ค่า rule 1 = admin 2 = user 0 = blockuser
	
    $query_select = "SELECT * FROM `user`";  // ถ้าเป็น admin ดึงข้อมูลออกมาทั้งหมด 
}
else{	
	$query_select = "SELECT * FROM `user` WHERE us_username='".$_SESSION['us_username']."'"; // ถ้าไม่ใช่ก็พ่วงเงื่อนไข ด้วย username เข้าไป 
  } 
$select = mysql_query($query_select,$MyConnect) or die(mysql_error());



?>
<? include_once "../Connections/MyConnect.php"; ?>
<?
if($submit=="OK"){
if($id1==""){
$sql="INSERT INTO gpa  set st_id='".$st_id."',st_gpa='".$st_gpa."',opened_term='".$opened_term."',ac_year='".$ac_year."'";
}else{
$sql="UPDATE alumni set st_gpa='".$st_gpa."',opened_term='".$opened_term."',ac_year='".$ac_year."'  WHERE st_id='".$id1."'" ;
}
mysql_query($sql);
}
if ($submit=="DEL"){
$sql="delete from alumni where st_id ='".$id1."'";
mysql_query($sql);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>โรงเรียนชาวไทยภูเขา นพค.32</title>
<meta name="keywords" content="free css templates, blog design, 2-column, web design, CSS, HTML" />
<meta name="description" content="Design Blog - free css template, 2-column blog layout" />
<link href="css/templatemo_style.css" rel="stylesheet" type="text/css" />
<link href="A/style/style.css" rel="stylesheet" type="text/css" />
<link  href='A/date_time/datepicker.css' rel='stylesheet'>
<script type='text/javascript' language='javascript' src='A/date_time/prototype-1.js'></script>
<script type='text/javascript' language='javascript' src='A/date_time/prototype-date-extensions.js'></script>
<script type='text/javascript' language='javascript' src='A/date_time/behaviour.js'></script>
<script type='text/javascript' language='javascript' src='A/date_time/datepicker.js'></script>
<script type='text/javascript' language='javascript' src='A/date_time/behaviors.js'></script>
<script language="javascript" type="text/javascript">
function clearText(field)
{
    if (field.defaultValue == field.value) field.value = '';
    else if (field.value == '') field.value = field.defaultValue;
}
</script>
<script language="JavaScript">
function chkdel(){
if(confirm('  กรุณายืนยันการลบอีกครั้ง !!!  ')){
return true;
}else{
return false;
}
}
function Check_txt(){
if(document.getElementById('st_id').value==""){
alert("กรุณาระบุรหัสนักเรียนด้วยครับ");
document.getElementById('st_id').focus();
return false;
}
if(document.getElementById('st_gpa').value==""){
alert("กรุณาระบุเกรดเฉลี่ยด้วยครับ");
document.getElementById('st_gpa').focus();
return false;
}
if(document.getElementById('opened_term').value==""){
alert("กรุณาระบุเทอมด้วยครับ");
document.getElementById('opened_term').focus();
return false;
}
if(document.getElementById('ac_year').value==""){
alert("กรุณาระบุปีการศึกษาด้วยครับ");
document.getElementById('ac_year').focus();
return false;
}
}
</script>
</head>
<body>

<div id="templatemo_body_wrapper">
<div id="templatemo_wrapper">
    
    <div id="templatemo_header">
            
        <div id="site_title">
            <a href="http://www.templatemo.com/page/1" target="_parent">MDU.32 
            	<span>School</span><span class="tagline"><br>
            	โรงเรียนขาวไทยภูเขา</span>
            </a>
        </div> <!-- end of site_title -->
        
        <div id="s">
            <form action="#" method="get">
                <input type="text" value="Enter keyword here..." name="q" size="10" id="searchfield" title="searchfield" onfocus="clearText(this)" onblur="clearText(this)" />
              <input type="submit" name="Search" value="Search" id="searchbutton" title="Search" />
            </form>
        </div>
    
   
        <div class="cleaner"></div>
        
    </div> <!-- end of header -->
    
    <div id="templatemo_menu">
         <ul>
            <li><a href="indexadminstudent.php" class=""><span></span>จัดการข้อมูลนักเรียน</a></li>
            <li><a href="indexuseralumni.php"><span></span>จัดการข้อมูลศิษย์เก่า</a></li>
            <li><a href="#"><span></span>จัดการข้อมูลเกรดเฉลี่ย</a></li>
            <li><a href="indexuser.php"><span></span>ข้อมูลส่วนตัวอาจารย์</a></li>
              </ul>   	
           </div>
     
  <!-- end of templatemo_menu -->
    
    <div id="templatemo_main">
    	
        <div id="templatemo_content">
        
        	<div class="post_box">
            
                <h2><a href="#"></a></h2>		
                <div class="news_meta"><a href="#"></a> <a href="#"></a> <a href="#"></a> <a href="#"></a> <a href="#"></a></div>
              <div class=""><p><center>
<div id="container">
<div id="header">
<div id="header_left"></div>
<div id="header_main">ระบบจัดการข้อมูลศิษย์เก่า</div>
<div id="header_right"></div>
</div>
<div id="content"><br><br>

<?  if($submit=="" or $show=="OK"){?>
<center><form name="form1" method="post" action="indexusergpa.php?show=OK&strSearch=Y">
<table width="98%" >
<tr>
<td width="50%"><div align="right">ค้นหา :<select name="Search2">
<option value="st_id" <? if($Search2=="st_id"){ ?>selected<? }?>>รหัสนักเรียน</option>
<option value="st_gpa" <? if($Search2=="st_gpa"){ ?>selected<? }?>>เกรดเฉลี่ย</option>
<option value="opened_term" <? if($Search2=="opened_term"){ ?>selected<? }?>>ภาคการศึกษา</option>
<option value="ac_year" <? if($Search2=="ac_year"){ ?>selected<? }?>>ปี</option>
</select></div>
</td>
<td width="64%"><input name="Search" type="text" size="20" value="<? echo $Search?>"onFocus="this.value = '';">
<input type="submit" name="submit" value="Search">
</td>
</tr>
</table>
</form></center>

<?
if(!isset($start)){
$start = 0;
$page=1;
}
$limit = '20';

if($strSearch=="Y"){
$Qtotal = mysql_query("select * from gpa Where ".$Search2." like '%".$Search."%'  ");
}else{
$Qtotal = mysql_query("select * from gpa");
}

$total = mysql_num_rows($Qtotal); 
if($strSearch=="Y"){
$Query = mysql_query("select * from gpa Where ".$Search2." like '%".$Search."%'   order  by  st_id DESC LIMIT $start,$limit");
}else{
$Query= mysql_query("select * from  gpa order  by  st_id DESC LIMIT $start,$limit");
}

$totalp = mysql_num_rows($Query);
$xx=$totalp+$start;
$yy=$start+1;
echo "ข้อมูลที่ ".$yy." ถึงข้อมูลที่ ".$xx;
printf(" | จากทั้งหมด %d รายการ  ",$total);
printf(" | หน้าที่ %d <br />",$page);
?><br><br>

<table width="100%">
<tr bgcolor="#999999" height='40' >
<td width="19%" align='center'><strong>รหัสนักเรียน</strong></td>
<td width="6%" align='center'><strong>เกรดเฉลี่ย</strong></td>
<td width="14%" align='center'><strong>ภาคการศึกษา</strong></td>
<td width="7%" align='center'><strong>ปี</strong></td>
<td width="14%" align='center'><strong>ข้อมูลทั้งหมด</strong></td>
<td width="19%"><a href="indexusergpa.php?submit=Add&show="><center><img src="A/style/images/add.png" border="0"></center></a></td>
</tr>
<?
while($arr = mysql_fetch_array($Query)){
$autoid = $arr['st_id'];
$i++;
if($i%2==0){
$bg = "#CCCCCC";
}else{
$bg = "#FFFFFF";
}
?>
<tr bgcolor="<? echo $bg?>" onMouseOver="this.style.backgroundColor='#CCFFCC'" onMouseOut="this.style.backgroundColor=''" valign="top">
<td align='center'><? echo $arr['st_id'] ?></td>
<td align='center'><? echo $arr['st_gpa'] ?></td>
<td align='center'><? echo $arr['opened_term'] ?></td>
<td align='center'><? echo $arr['ac_year'] ?></td>
<td align='center'></td>
<td align="center">
<a href="indexusergpa.php?submit=DEL&show=OK&id1=<? echo $autoid;?>" OnClick="return chkdel();"><img src="A/style/images/-.png" border="0"></a>&nbsp;
<a href="indexusergpa.php?submit=Edit&id1=<? echo $autoid;?>"><img src="A/style/images/Tools.png" border="0"></a></td>
</tr>
<? }?>
</table>

<? }?>

<?  if($submit=="Add"){?>
<form action="indexusergpa.php?submit=OK&show=OK&id1=" method="post"onSubmit="return Check_txt()" enctype='multipart/form-data'>
<table width="98%">
<tr>
<td width='30%'  align='right'>รหัสนักเรียน:</td>
<td width='70%'><input name='st_id' id='st_id' type='text' size='30'></td>
</tr>
<tr>
<td width='30%'  align='right'>เกรดเฉลี่ย:</td>
<td width='70%'><input name='st_gpa' id='st_gpa' type='text' size='30'></td>
</tr>
<tr>
<td width='30%'  align='right'>ภาคการศึกษา:</td>
<td width='70%'><input name='opened_term' id='opened_term' type='text' size='30'></td> 
</tr>
<tr>
<td width='30%'  align='right'>ปี:</td>
<td width='70%'><input name='ac_year' id='ac_year' type='text' size='30'></td>
</tr>
<tr height='50'>
<td></td>
<td align='left' valign='middle'><input type='submit' name='Submit' value='   บันทึก   '> <input type='reset' name='Submit2' value='ล้างข้อมูล'> <input type='button' name='Submit222' value='   ยกเลิก   ' onClick="document.location.href='indexusergpa.php?show=OK'"></td>
</tr>
</table>
</form>
<? }?>


<?  if($submit=="Edit"){
$sql="select * from  gpa  where st_id ='".$id1."'  ";
$tem = mysql_query($sql);
$row3=mysql_fetch_array($tem);
?>

<form action="indexusergpa.php?submit=OK&show=OK&id1=<? echo $id1?>" method="post"onSubmit="return Check_txt();" enctype='multipart/form-data'>
<input type='hidden' name='st_id' value="<?=$row3['st_id']?>">
<table width="98%">
<tr>
<td width='30%'  align='right'>รหัสนักเรียน:</td>
<td width='70%'><input name='st_id' id='st_id' type='text' size='30' value="<?=$row3['st_id']?>"></td>
</tr>
<tr>
<td width='30%'  align='right'>เกรดเฉลี่ย:</td>
<td width='70%'><input name='st_gpa' id='st_gpa' type='text' size='30' value="<?=$row3['st_gpa']?>"></td>
</tr>
<tr>
<td width='30%'  align='right'>ภาคการศึกษา:</td>
<td width='70%'><input name='opened_term' id='opened_term' type='text' size='30' value="<?=$row3['opened_term']?>"></td> 
</tr>
<tr>
<td width='30%'  align='right'>ปี:</td>
<td width='70%'><input name='ac_year' id='ac_year' type='text' size='30' value="<?=$row3['ac_year']?>"></td>
</tr>

<tr>
<tr height="50">
<td></td>
<td><input type="submit" name="Submit" value="   บันทึก   "> <input type="button" name="Submit222" value="   ยกเลิก   " onClick="document.location.href='indexusergpa.php?show=OK'"></td>
</tr>
</table>
</form>
<? }?>

</div>
<div id="footer">
<? if($submit=="" or $show=="OK"){
$page = ceil($total/$limit);
for($i=1;$i<=$page;$i++){
if($_GET['page']==$i){
echo "[<a href='?start=".$limit*($i-1)."&page=$i&strSearch=$strSearch&Search=$Search&Search2=$Search2'><B>$i</B></A>]";
}else{
echo "[<a href='?start=".$limit*($i-1)."&page=$i&strSearch=$strSearch&Search=$Search&Search2=$Search2'>$i</A>]";
}}} ?>
</div>
</div>
</center></p>
              </div>
              <p align="justify"> <a href="http://www.templatemo.com" target="_parent"></a> <a href="http://www.templatemo.com" target="_parent"></a>  <a href="#" class="continue">Continue ...</a></p>
              <div class="cleaner"></div>
            </div>
            
            <div class="post_box">
            
                <h2><a href="#"></a></h2>		
                
              <p align="">&nbsp;</p>
        <div class=""></div>
            </div>
            
          <div class="">
            
                <h2>&nbsp;</h2>		
                <div class=""> <a href="#"></a></div>
             <div class=""></a></p>
             <div class=""></div></div>
             <p align=""></div>
        
        </div>
        
        <div id="templatemo_sidebar">
        
        	<div id="aboutus">
            	<h3>
            	  <label for="uname"></label>
            	  <label for="pword">ชื่อผู้ใช้ : <?php echo $_SESSION['us_username']; ?>

<p>&nbsp;</p>
  <p><a href="logout.php">ออกจากระบบ</a></p><br />
            	    <br />
                  </label>
            	</h3>
            	<p>&nbsp;</p>
           	  <p>&nbsp;</p>
           	  <p>&nbsp;</p>
           	  <p>&nbsp;</p>
            	<p>&nbsp;</p>
          </div>
            
            <div class="cleaner_h20"></div>
            
            <div class="sidebar_box">
            
            	<h3>Our Sponsors</h3>
                
                <div class="ads_125"><a href="http://www.templatemo.com/page/1" target="_parent"><img src="images/ads_125.jpg" alt="ad 1" /></a></div>
                <div class="ads_125 odd"><a href="http://www.templatemo.com/page/2" target="_parent"><img src="images/ads_125.jpg" alt="ad 2" /></a></div>
                
                <div class="ads_125"><a href="http://www.templatemo.com/page/3" target="_parent"><img src="images/ads_125.jpg" alt="ad 3" /></a></div>
                <div class="ads_125 odd"><a href="http://www.templatemo.com/page/4" target="_parent"><img src="images/ads_125.jpg" alt="ad 4" /></a></div>
                
              	<div class="cleaner"></div>
                
            </div>
            
            <div class="sidebar_box">
            	<h3>Categories</h3>
                
                <ul class="sidebar_menu">
                    <li><a href="#">&raquo; Web Design Tips <span>(260)</span></a></li>
                    <li><a href="#">&raquo; Beautiful Wallpapers <span>(380)</span></a></li>
                    <li><a href="#">&raquo; Free Fonts <span>(125)</span></a></li>
                  	<li><a href="#">&raquo; Digital Illustrations <span>(215)</span></a></li>
       		  </ul>
                
          </div>
            
            
            <div class="sidebar_box">
            	<h3>Archives</h3>
                <ul class="sm_two_col">
                    <li><a href="#">&raquo; February 2048</a></li>
                    <li><a href="#">&raquo; </a></li>
                    <li class="cleaner"><a href="#">&raquo; </a></li>
                    <li><a href="#">&raquo; </a></li>
                    <li><a href="#">&raquo; </a></li>
                    <li><a href="#">&raquo; </a></li>
                </ul>
                
                <div class="cleaner"></div>
            </div>
  
            
          	<div class="sidebar_box">
            
            	<h3>Newsletter</h3>
                
                <form method="get" action="#">
                  	<input type="text" id="user" name="user" class="newsletter_email" value="Enter your email address"  onfocus="clearText(this)" onblur="clearText(this)" />
                    <input style="font-weight: bold;" type="submit" name="submit" id="submit" value="Subscribe" />
                </form>
                
            	<div class="cleaner_h20"></div>
              <a href="#" class="icon_link"><img src="images/templatemo_rss.jpg" alt="rss" /></a><a href="#" class="icon_link"><img src="images/templatemo_twitter.jpg" alt="twitter" /></a>
            </div>
        
        </div>
    
    	<div class="cleaner"></div>
    </div>
    
</div>
<div class="cleaner"></div>
</div>


<div id="templatemo_footer_wrapper">
	<div id="templatemo_footer">
    
    	<div class="footer_box col_w300">
        	<h4>------</h4>
            <ul class="footer_menu">
            	<li><a href="#">หน้าแรก</a></li>
                <li><a href="#">แผนผังบุคลากร</a></li>
            </ul>     
        </div>
        
        <div class="footer_box col_w160">
        	<h4>------</h4>
            <ul class="footer_menu">
            	<li><a href="#">ข่าวประชาสัมพันธ์</a></li>
                <li><a href="#">ข่าวกิจกรรม</a></li>
                </ul>     
        </div>
        
        <div class="footer_box col_w160">
       	  <h4>------</h4>
            <ul class="footer_menu">
            	<li><a href="#">รูปภากิจกรรม</a></li>
                
            </ul>     
        </div>

        <div class="footer_box col_w260 fb_last">
        	<h4>------</h4>
            	<a href="#" style="font-size:12px">ติดต่อทางโรงเรียน</a> <a href="#" style="font-size:11px"></a> <a href="#" style="font-size:16px"></a> <a href="#" style="font-size:11px"></a> <a href="#" style="font-size:20px"></a> <a href="#" style="font-size:16px"></a> <a href="#" style="font-size:12px"></a>
        </div>
    
    	<div class="cleaner"></div>
    </div>
</div>

<div id="templatemo_copyright">
    Copyright © 2015 <a href="#">MDU 32 School</a> 
     <a href="http://www.templatemo.com" target="_parent"></a>  
  <a href="http://validator.w3.org/check?uri=referer"></a>  
    		 <a href="http://jigsaw.w3.org/css-validator/check/referer"></a>
</div>

</body>
</html>


Soomsam77 171.99.99.xxx 14-04-2015 11:04:35

คำแนะนำ และการใช้งาน

สมาชิก กรุณา ล็อกอินเข้าระบบ เพื่อตั้งคำถามใหม่ หรือ ตอบคำถาม สมาชิกใหม่ สมัครสมาชิกได้ที่ สมัครสมาชิก


  • ถาม-ตอบ กรุณา ล็อกอินเข้าระบบ
  • เปลี่ยน


    ( หรือ เข้าใช้งานผ่าน Social Login )

 ความคิดเห็นที่ 1
คือตอนนี้มันเป็น Auto_id ครับบ ในฐานข้อมูลผมมันเป็น char แต่เมื่อเราทำการแก้ไข มันก็เป็น Auto_id อยู่ดีครับบ


soomsam77 171.99.99.xxx 14-04-2015 11:06
 ความคิดเห็นที่ 2
  ในโครงสร้างฐานข้อมูล เราสามารถยกเลิก  กำหนดไม่ให้ฟิลด์ เป็น auto_increment ได้ไม่ใช่หรอ


ninenik 1.47.105.xxx 14-04-2015
 ความคิดเห็นที่ 3
ใช่ครับผมยกเลิกผมกำหนด เป็น char โค๊ดมันก็ยังเป็น Auto_id อยู่ครับบ ไม่รู้จะทำไงครับบ
<?  
while($arr = mysql_fetch_array($Query)){  
$autoid = $arr['st_id'];  
$i++;  
if($i%2==0){  
$bg = "#CCCCCC";  
}else{  
$bg = "#FFFFFF";  
}  
?>  

ไม่รู้ว่าเป็นตรงไหนครับบ

?>  
<? include_once "../Connections/MyConnect.php"; ?>  
<?  
if($submit=="OK"){  
if($id1==""){  
$sql="INSERT INTO gpa  set st_id='".$st_id."',st_gpa='".$st_gpa."',opened_term='".$opened_term."',ac_year='".$ac_year."'";  
}else{  
$sql="UPDATE alumni set st_gpa='".$st_gpa."',opened_term='".$opened_term."',ac_year='".$ac_year."'  WHERE st_id='".$id1."'" ;  
}  
mysql_query($sql);  
}  
if ($submit=="DEL"){  
$sql="delete from alumni where st_id ='".$id1."'";  
mysql_query($sql);  
}  
?>  
แล้วอีกอย่างแก้ไขมันก็ยังเป็น Auto อยู่ครับ
<tr bgcolor="<? echo $bg?>" onMouseOver="this.style.backgroundColor='#CCFFCC'" onMouseOut="this.style.backgroundColor=''" valign="top">  
<td align='center'><? echo $arr['st_id'] ?></td>  
<td align='center'><? echo $arr['st_gpa'] ?></td>  
<td align='center'><? echo $arr['opened_term'] ?></td>  
<td align='center'><? echo $arr['ac_year'] ?></td>  
<td align='center'></td>  
<td align="center">  
<a href="indexusergpa.php?submit=DEL&show=OK&id1=<? echo $autoid;?>" OnClick="return chkdel();"><img src="A/style/images/-.png" border="0"></a>&nbsp;  
<a href="indexusergpa.php?submit=Edit&id1=<? echo $autoid;?>"><img src="A/style/images/Tools.png" border="0"></a></td>  
</tr>  
<? }?>  
ช่วยหน่อยนะครับบบขอบคุณครับบ


soomsam77 171.99.97.xxx 14-04-2015 13:07
1






เว็บไซต์ของเราให้บริการเนื้อหาบทความสำหรับนักพัฒนา โดยพึ่งพารายได้เล็กน้อยจากการแสดงโฆษณา โปรดสนับสนุนเว็บไซต์ของเราด้วยการปิดการใช้งานตัวปิดกั้นโฆษณา (Disable Ads Blocker) ขอบคุณครับ