Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,028

HOME > PHP > PHP Forum > ต้องการเก็บข้อมูลลง Mysql โดยใช้ Select เป็นตัวเลือก Table DB ทำยังไงครับ



 

ต้องการเก็บข้อมูลลง Mysql โดยใช้ Select เป็นตัวเลือก Table DB ทำยังไงครับ

 



Topic : 107625

Guest




คือผมต้องการเก็บข้อมูล โดยใช้ Select เลือกฐานข้อมูลที่จะเก็บลงไปนะครับ ตามรูปเลยครับ ขอบคุณครับ
select1

select2



Tag : PHP, MySQL, HTML/CSS, JavaScript, Windows, Web Service







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2014-04-11 10:36:58 By : Harizadoz View : 2773 Reply : 6
 

 

No. 1



โพสกระทู้ ( 2,249 )
บทความ ( 5 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook Hi5 Blogger

รับค่าชื่อ table จาก select ก่อนครับสมมุติใช้ POST

$tb_name = $_POST['select_tb'];

insert into {$tb_name} (ฟิลด์) values (ค่า)






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-11 12:16:50 By : Manussawin
 


 

No. 2

Guest


<head>
<?
$objConnect = mysql_connect("localhost","root","1234") or die("Error Connect to Database");
$objDB = mysql_select_db("fprojectscience")
?>
</head>
<body
<select name="tablesel" >
<option><? $tb_name= $post['bachelor'];?>bachelor</option>
<option><? $tb_name = $post['vocation']; ?> vocation</option>
</select>
</body>

แบบนี้หรอครับหรือยังไง ช่วยอธิบายมากกว่านี้ทีครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-11 12:26:56 By : ็Harizadoz
 

 

No. 3



โพสกระทู้ ( 1,322 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


เอา code ทั้งหมดมาดูหน่อยสิครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-11 14:49:11 By : pokultra
 


 

No. 4

Guest


Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>

<script language="JavaScript" type="text/JavaScript">
	function CreateSelectOption(ele)
	{
		var objSelect = document.getElementById(ele);
		var Item = new Option("", ""); 
		objSelect.options[objSelect.length] = Item;
		<?
		while($objResult = mysql_fetch_array($objQuery))
		{
		?>
		var Item = new Option("<?=$objResult["subject$i"];?>", "<?=$objResult["txtCustomerID$i"];?>"); 
		objSelect.options[objSelect.length] = Item;
		<?
		}
		?>
	}

function CreateNewRow()
	{
		var intLine = parseInt(document.frmMain.hdnMaxLine.value);
		intLine++;
			
		var theTable = document.all.tbExp
		var newRow = theTable.insertRow(theTable.rows.length)
		newRow.id = newRow.uniqueID
		
		var item1 = 1
		var newCell
		
		//*** Column 1 ***//
		newCell = newRow.insertCell(0)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><td><INPUT TYPE=\"TEXT\"  NAME=\"txtCustomerID<?=$i;?>"+intLine+"\" VALUE=\"\"></td></center>"

		//*** Column 2 ***//
		newCell = newRow.insertCell(1)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><td><INPUT TYPE=\"TEXT\"  NAME=\"txtName<?=$i;?>"+intLine+"\" VALUE=\"\"></td></center>"		
		
		//*** Column 3 ***//
		newCell = newRow.insertCell(2)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><td><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtEmail<?=$i;?>"+intLine+"\" VALUE=\"\"></td></center>"				
		
		//*** Column 4 ***//
		newCell = newRow.insertCell(3)
		newCell.id = newCell.uniqueID
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><td><INPUT TYPE=\"TEXT\" SIZE=\"5\" NAME=\"txtCountryCode<?=$i;?>"+intLine+"\" VALUE=\"\"></td></center>"		
		
					newCell = newRow.insertCell(4);
		newCell.id = newCell.uniqueID;
		newCell.setAttribute("className", "css-name");
		newCell.innerHTML = "<center><SELECT NAME=\"Column5_"+intLine+"\" ID=\"Column5_"+intLine+"\"></SELECT></center>";

		//*** Create Option ***//
		CreateSelectOption("Column5_"+intLine)
		
		document.frmMain.hdnMaxLine.value = intLine;
	}
	
	function RemoveRow()
	{
		intLine = parseInt(document.frmMain.hdnMaxLine.value);
		if(parseInt(intLine) > 0)
		{
				theTable = (document.all) ? document.all.tbExp : 
				document.getElementById("tbExp")
				theTableBody = theTable.tBodies[0];
				theTableBody.deleteRow(intLine);
				intLine--;
				document.frmMain.hdnMaxLine.value = intLine;
		}	
	}	
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
</head>

<style>
#tbExp{font-family:"Lucida Sans Unicode", "Lucida Grande", Sans-Serif;font-size:12px;width:480px;
text-align:left;border-collapse:collapse;border:1px solid #69c;margin:20px;}
#tbExp th{ text-align:center; font-weight:bold;font-size:14px;color:#039;padding:15px 10px 10px;background:#d0dafd;}
#tbExp tbody{background:#e8edff;}
#tbExp td{color:#669;border-top:1px dashed #fff;padding:10px;}
#tbExp tbody tr:hover td{color:#339;background:#d0dafd;}
</style>
<?
mysql_connect("localhost","root","12345");
mysql_select_db("fprojectscience");


?>
<body>

  
<form action="phpMySQLAddSave.php
" name="frmMain" method="post" >
 
<select hidden="yes" name="menu1" onChange="MM_jumpMenu('parent',this,0)">
<?
for($i=5;$i<=5;$i++)
{
	if($_GET["Line"] == $i)
	{
		$sel = "selected";
	}
	else
	{
		$sel = "";
	}
?>
	<option value="<?=$_SERVER["PHP_SELF"];?>?Line=<?=$i;?>" <?=$sel;?>><?=$i;?></option>
<?
}
?>
</select>

<table width="600" border="1" id="tbExp">
  <tr>
    <th width="91"> <div align="center">ID </div></th>
    <th width="160"> <div align="center">Subject </div></th>
    <th width="198"> <div align="center">Credit </div></th>
    <th width="97"> <div align="center">Cound </div></th>
     <td><div align="center">Column 5 </div></td>

  </tr>
  
<?
$line = $_GET["Line"];
if($line == 0){$line=1;}
for($i=1;$i<=$line;$i++)
{
?>
    
    <tr>
    <td><input type="text" name="txtCustomerID<?=$i;?>" values=""></td>
    <td><input type="text" name="txtName<?=$i;?>" values=""></td>
    <td><div align="center"><input type="text" name="txtEmail<?=$i;?>" values="" size="5"></div></td>
    <td><div align="center"><input type="text" name="txtCountryCode<?=$i;?>" values="" size="5"></div></td>
    <td>

  </tr>
<?
}
?>
  </table>
  <select name="Liname">

    </select>


  <input name="btnAdd" type="button" id="btnAdd" value="+" onClick="CreateNewRow();">
<input name="btnDel" type="button" id="btnDel" value="-" onClick="RemoveRow();">
  <input type="submit" name="submit" value="submit">
  <input type="hidden" name="hdnMaxLine" value="<?=$i;?>">
  </form>
</body>
</html>


Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
	$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
	$objDB = mysql_select_db("fprojectscience");

	for($i=1;$i<=$_POST["hdnMaxLine"];$i++)
	{
		if($_POST["txtCustomerID$i"] != "")
		{
			$strSQL ="insert into bachelor";
			$strSQL .="(id_subject,subject,credit,cound) ";
			$strSQL .="VALUES ";
			$strSQL .="('".$_POST["txtCustomerID$i"]."','".$_POST["txtName$i"]."', ";
			$strSQL .="'".$_POST["txtEmail$i"]."' ";
			$strSQL .=",'".$_POST["txtCountryCode$i"]."')";
			$objQuery = mysql_query($strSQL);
		}
	}

	echo "Save Done.  Click <a href='phpMySQLListRecord.php'>here</a> to view.";
 echo $objQuery;
mysql_close($objConnect);
?>
</body>
</html>



ืที่ผมอยากทราบคือ ทำยังไง เราจะใช้ Select เลือก Insert ข้อมูลลง ตาราง เช่นผมมี ตาราง bachelor ถ้าเรา Select bachelor มันก้จะไป Insert ข้อมูลลงใน Record ของ Bachelor
หรือถ้าผมเลือก Select vocation มันก้ Insert ข้อมูลลงใน Record vocation อะครับ พอเข้าใจใช่ป่ะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-11 15:18:47 By : Harizadoz
 


 

No. 5



โพสกระทู้ ( 1,322 )
บทความ ( 0 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์


[/head]
<select name="tablesel" >
  <option value="bachelor">bachelor</option>
  <option value="vocation">vocation</option>
</select>



[head]Code (PHP)

<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
	$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
	$objDB = mysql_select_db("fprojectscience");

	for($i=1;$i<=$_POST["hdnMaxLine"];$i++)
	{
		if($_POST["txtCustomerID$i"] != "")
		{
			$tbName=$_POST['tablesel']; // รับชื่อตารางที่เลือก
			
			$strSQL ="insert into ".$tbName;  //เพิ่มข้อมูลลงในตารางที่เลือกมา
			$strSQL .="(id_subject,subject,credit,cound) ";
			$strSQL .="VALUES ";
			$strSQL .="('".$_POST["txtCustomerID$i"]."','".$_POST["txtName$i"]."', ";
			$strSQL .="'".$_POST["txtEmail$i"]."' ";
			$strSQL .=",'".$_POST["txtCountryCode$i"]."')";
			$objQuery = mysql_query($strSQL);
		}
	}

	echo "Save Done.  Click <a href='phpMySQLListRecord.php'>here</a> to view.";
 echo $objQuery;
mysql_close($objConnect);
?>

<select name="tablesel" >
  <option value="bachelor">bachelor</option>
  <option value="vocation">vocation</option>
</select>
</body>
</html>


ประมาณนี้มั้งครับ ...ลองปรับใช้ดูนะครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-11 15:35:35 By : pokultra
 


 

No. 6

Guest


ได้พอดีเลยครับ ขอบคุณมากครับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2014-04-11 19:49:49 By : Harizadoz
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ต้องการเก็บข้อมูลลง Mysql โดยใช้ Select เป็นตัวเลือก Table DB ทำยังไงครับ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่