Jump to content
Sign in to follow this  
cyberfly

Dynamic Row/column Dan Dynamic Textfield

Recommended Posts

<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("bowling2") or die(mysql_error());
?>


<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php

  $game[0] = "game1";
  $game[1] = "game2";
  $game[2] = "game3";
  $game[3] = "game4";
  $game[4] = "game5";
  $game[5] = "game6";
  
  $query="select * from pertandingan where status=1";
  $doquery=mysql_query($query) or die(mysql_error());
  $array = mysql_fetch_array($doquery);
  echo $array['idPertandingan'];
  $limit = $array['bilGame'];
  for ( $x=0; $x<$limit; $x++ ){ ?>
<table width="100%" border="2" cellpadding="2" cellspacing="2" bordercolor="#000000">
  
  <tr>
    <td></td>
    <td><form id="form1" name="form1" method="post" action="">
      <label>
        <input type="text" name="$game[$x]" />
        </label>
    </form>
    </td>
  </tr>
</table><?php } ?>
</body>
</html>

Ni percubaan aku nak buat textfield dlm array.

betul ke idea aku tu?nama textfield tu aku buat $game[$x] sbb aku nak masukkan markah dlm table markah.

Ni gmbar table pertandingan dlm DB aku..

pertandingansy1.jpg

Ni table markah

markahlagicv9.jpg

Share this post


Link to post
Share on other sites

Aku rasa aku dah jumpa solution.

Ni aku pastekan skali untuk rujukan forumers lain ^_^

<?php
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("bowling2") or die(mysql_error());
?>
<?php
if(isset($_POST['submit']))
{


$games1 = $_POST['game1'];
$games2 = $_POST['game2'];
$games3 = $_POST['game3'];
$games4 = $_POST['game4'];
$games5 = $_POST['game5'];
$games6 = $_POST['game6'];


$query = "INSERT INTO markah (idPeserta, idPertandingan, game1, game2, game3, game4, game5, game6) VALUES ('14', '2', '$games1', '$games2', '$games3', '$games4', '$games5', '$games6')";

mysql_query($query) or die(mysql_error());
}
?>

<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<?php

  $game[0] = "game1";
  $game[1] = "game2";
  $game[2] = "game3";
  $game[3] = "game4";
  $game[4] = "game5";
  $game[5] = "game6";
  
  $query="select * from pertandingan where status=1";
  $doquery=mysql_query($query) or die(mysql_error());
  $array = mysql_fetch_array($doquery);
  echo $array['idPertandingan'];
  $limit = $array['bilGame'];
  
  for ( $x=0; $x<$limit; $x++ ){ ?>
<table width="100%" border="2" cellpadding="2" cellspacing="2" bordercolor="#000000">
  <form id="form1" name="form1" method="post" action="">
  <tr>
    <td></td>
    <td>
      <label>
        <input type="text" name="<?php echo $game[$x]; ?>" />
        </label>
    
    </td>
  </tr>
</table><?php } ?>
<input type="submit" name="submit" value="Submit" /></form>
</body>
<label>

</label>
</body>
</html>

Share this post


Link to post
Share on other sites

Soalan:

Kau nak buat banyak column kan? Tapi kena dalam loop kau, ada table? Kalau macam tu bukan ke nanti table yang jadi banyak?

Share this post


Link to post
Share on other sites

Soalan:

Kau nak buat banyak column kan? Tapi kena dalam loop kau, ada table? Kalau macam tu bukan ke nanti table yang jadi banyak?

ni experimen je.

table tu kan ada satu row je.so loop byk2 pn jadi mcm satu table ada byk row je la :P

kesimpulan,experimen aku berjaya..hehe..

Share this post


Link to post
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...
Sign in to follow this  

×
×
  • Create New...