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,027

HOME > PHP > PHP Forum > ช่วยดูโค้ดให้ด้วยครับ เกี่ยวกับการเรียกข้อมูลขึ้นมาดู



 

ช่วยดูโค้ดให้ด้วยครับ เกี่ยวกับการเรียกข้อมูลขึ้นมาดู

 



Topic : 058640



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



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




คือมันเป็นหน้าตรงข้อสอบครับ ผมจะเรียกข้อมูลจากฐานข้อมูลขึ้นมาแสดงครับแต่มันวนเกินไปหน่อยไม่รู้ว่าต้องแก้ตรงไหน
อันนี้รูปที่มันรันออกมาครับ
x1

แต่ผมอยากให้มันรันออกมาแบบนี้
x2

โค้ดครับ

หน้าเลือกข้อสอบไปแสดงครับ
Code (PHP)
<?
include('config.php');

?>
<form id="form1" name="form1" method="post" action="">
  <table width="70%" border="1">
    <tr>
      <th scope="col">1</th>
      <th scope="col">2รหัสนักศึกษา</th>
      <th scope="col">3รหัสข้อสอบ</th>
      <th scope="col">4รายวิชา</th>
      <th scope="col">5</th>
      <th scope="col">6</th>
      <th scope="col">7</th>      
    </tr>
    <?
	$answer="";
    $sql="select * from exam_results where answers!='$answer' group by s_id";
$sql_result = mysql_query($sql) or die (mysql_error());
while ($sql_show = mysql_fetch_array($sql_result))
			
{
   ?>
    <tr>
      <td><?=$sql_show[er_id];?>ไม่ต้องแสดง&nbsp;</td>
      <td><?=$sql_show[s_id];?>&nbsp;</td>
      <td><?=$sql_show[ex_id];?>&nbsp;</td>
      <td><?=$sql_show[c_id];?>เปลี่ยนเป็นชื่อวิชา&nbsp;</td>
      <td><?=$sql_show[answer];?>ไม่ต้องแสดง&nbsp;</td>
      <td><?=$sql_show[score];?>ไม่ต้องแสดง&nbsp;</td>
      <td><a href="exam-check-select.php?check=<?=$sql_show['er_id']?>num=&amp; lt;?=$sql_show['s_id']&amp;xxx1=<?=$sql_show['s_id']?>&amp;xxx2=<?=$sql_show['ex_id']?>">ตรวจข้อสอบ</a>&nbsp;</td>      
    </tr>
    <?
	}
	?>
  </table>
</form>



หน้าแสดงข้อมูล
Code (PHP)
<?
include('config.php');
$erid=$_GET[check];
$s=$_GET[xxx1];
$ex=$_GET[xxx2];
echo "$s $ex</br>";
$sql = "select * from exam_results as er , exam_news as en where er.s_id='$s' and er.ex_id='$ex' and en.id='$ex'";
$objQuery = mysql_query($sql); 
//$objResult = mysql_fetch_array($objQuery); 
//$objResult = mysql_fetch_array($objQuery);
echo "$objQuery";
?>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>
        		<form id="form1" name="form1" method="post" action="">
<table width="70%" cellpadding="0" cellspacing="0">
		  <tr>
            <td width="9%" align="right" valign="top" scope="col">คำถาม </td>
		    <td width="38%" align="left" valign="top" scope="col"><textarea id="question" rows="3" cols="30" name="question"><?=$objResult["question"];?></textarea></td>
		    <td width="20%" scope="col">คำตอบของนักศึกษา</td>
		    <td width="33%" scope="col"><?=$objResult["answers"];?></td>
		  </tr>
          <tr>
             <td valign="top" scope="col" align="right">เฉลย </td>
		    <td valign="top" scope="col" align="left"><textarea id="answer" rows="3" cols="30" name="answer"><?=$objResult["answer"];?></textarea></td>
            <td colspan="2" align="center" valign="middle" scope="col">คะแนนที่ได้ 
              <label>
              <input type="text" name="scores" id="scores" />
            คะแนน</label></td>
          </tr>
          <tr>
            <td colspan="3"  scope="col">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;คะแนน <?=$objResult["score"];?> คะแนน
            </LABEL></td>
            <td scope="col">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="4" align="right" valign="top" scope="col">——————————————————————————————————————————   </td>
            <input name="numid" type="hidden" id="numid" value="<?=$objResult["num"];?>" />
              <input name="edit_id" type="hidden" id="edit_id" value="<?=$_REQUEST['xxx1']?>" />
              <input name="num" type="hidden" id="num" value="<?=$_REQUEST['xxx2']?>" />
          </tr>
		  </table>
          <?
		  }
		  ?>
          <input id="submit" value="บันทึก" type="submit" name="submit2" />
          </form>


ฐานข้อมูลครับ
ฐานข้อมูลข้อสอบครับ
x3

ฐานข้อมูลคำตอบนักศึกษาครับ
x4



Tag : PHP







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2011-04-12 22:46:22 By : thecarbon View : 18110 Reply : 6
 

 

No. 1

Guest


หน้าแสดงข้อมูล ลองเปิด while ไว้ภายใน table ดูนะครับที่เห็นมันคร่อม table อยู่

ลองทำประมานนี้ดูนะครับ ผิดพลาดประการใดขออภัยด้วย
<table>
<? while()
{
?>
//[color=black]output.....[/color]
<?
}
?>
</table>






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-14 00:37:02 By : Fail
 


 

No. 2



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



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


ไม่ได้ครับผม ไงก็ขอบคุณนะคับ
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-14 14:39:28 By : thecarbon
 

 

No. 3



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



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


ผมให้มันแสดงอย่างที่ต้องการได้แล้วครับติดที่ว่า จะส่งค่าคะแนนที่ได้ ไปอีกหน้ายังไง ผมสงไปแล้วมันได้แค่ค่าสุดท้ายอะครับ


ประวัติการแก้ไข
2011-04-16 17:34:01
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-16 17:33:21 By : thecarbon
 


 

No. 4



โพสกระทู้ ( 11,835 )
บทความ ( 10 )

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

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


ส่งแบบอาร์เรครับ ตัวอย่าง
https://www.thaicreate.com/php/php-mysql-add-insert-multiple-record.html
https://www.thaicreate.com/php/php-mysql-multiple-rows-update-edit-record.html
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-16 17:50:51 By : PlaKriM
 


 

No. 5



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



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


ผมแก้โค้ดเป็นแบบนี้
หน้าเรียกดูครับ
Code (PHP)
		<?
include('config.php');
$erid=$_GET[check];
$s=$_GET[xxx1];
$ex=$_GET[xxx2];
$c='';
//echo "$s $ex</br>";
$sql = "select * from exam_results as er , exam_news as en where er.s_id='$s' and er.ex_id='$ex' and en.id='$ex' and er.questionnum=en.questionnum and c1='$c'";
$objQuery = mysql_query($sql); 
//$objResult = mysql_fetch_array($objQuery); 
$num=mysql_num_rows($objQuery);
echo $num;
?>
<form id="form1" name="form1" method="post" action="exam-check-select-save.php">
<?
for($i=1;$i<=$num;$i++)
{while($objResult = mysql_fetch_array($objQuery))
{
?>        		
<table width="70%" cellpadding="0" cellspacing="0">
<tr>
            <td width="9%" align="right" valign="top" scope="col">คำถาม </td>
		    <td width="38%" align="left" valign="top" scope="col">&nbsp;&nbsp;&nbsp;<?=$objResult["question"];?></td>
		    <td width="25%" scope="col">คำตอบของนักศึกษา</td>
		    <td width="33%" scope="col"><?=$objResult["answers"];?></td>
		  </tr>
          <tr>
             <td valign="top" scope="col" align="right">เฉลย </td>
		    <td valign="top" scope="col" align="left">&nbsp;&nbsp;&nbsp;<?=$objResult["answer"];?></td>
            <td colspan="2" align="center" valign="middle" scope="col">คะแนนที่ได้ 
              <label>
              <input type="text" name="scores<?=$i;?>" id="scores" />
            คะแนน</label></td>
          </tr>
          <tr>
            <td colspan="3"  scope="col">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;คะแนน <?=$objResult["score"];?> คะแนน
            </LABEL></td>
            <td scope="col">&nbsp;</td>
          </tr>
          <tr>
            <td colspan="4" align="right" valign="top" scope="col">——————————————————————————————————————————   </td>
              <input name="edit_id" type="hidden" id="edit_id" value="<?=$_REQUEST['xxx1']?>" />
              <input name="num1" type="hidden" id="num1" value="<?=$_REQUEST['xxx2']?>" />
              <input name="num" type="hidden" id="num" value="<?=$num;?>" />

              <input type="hidden" name="hdnLine" value="<?=$i;?>">
          </tr>
		  <?
		  }}
		  ?>
          </table>
          <center><input id="submit" value="บันทึก" type="submit" name="submit2" /></center>
          </form>



หน้าที่ส่งค่าไปครับ
Code (PHP)
<?
$n=$_POST[num];
echo "n = $n";
for($i=0; $i<=$n;$i++)
{
echo "".$_POST["scores$i"]."</br>";
}
?>


มันมาแค่ค่าสุดท้ายที่กรอกไปครับ ผิดตรงไหนช่วยดูให้ด้วยครับ


ประวัติการแก้ไข
2011-04-17 11:55:33
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-04-17 11:54:35 By : thecarbon
 


 

No. 6

Guest


ส่งเป็น array คับ แล้วตั้ง id ของ form คับ

$i=0;
while()
{
<form id=$i name=$i>
$data
</form>
$i++;
}
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2011-07-11 23:57:59 By : jane
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยดูโค้ดให้ด้วยครับ เกี่ยวกับการเรียกข้อมูลขึ้นมาดู
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ 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 อัตราราคา คลิกที่นี่