Nieuw lid |
|
<?php
$mysql_connect = mysql_connect("localhost", "login", "password");
mysql_connect("localhost", "login", "password")
or die("Could not connect mySQL.");
mysql_select_db("ekitorc_mySQLtest")
or die("Could not select the database.");
if ($_POST['sumbit'] != "" )
{
$name = $_POST['name'];
$surname = $_POST['surname'];
$adress = $_POST['adress'];
$xfire_username = $_POST['xfire_username'];
$query = "INSERT INTO `ekitorc_mySQLtest`.`mytest` (
`ID` ,
`name` ,
`surname` ,
`adress` ,
`xfire_username`
)
VALUES (
NULL , '$name', '$surname', '$adress', '$xfire_username'
); ";
mysql_query($query)
or die("Could not make an account.");
if(mysql_affected_rows() == 1)
{
print("New member added.");
}
} else {
?>
<html>
<head>
<title>member registration/showing</title>
</head>
<body>
<form action="members.php" method="post" enctype="text/plain">
name: <INPUT NAME="name" TYPE="text" SIZE=30 MAXLENGTH=30><BR>
surname: <INPUT NAME="surname" TYPE="text" SIZE=30 MAXLENGTH=30><BR>
adress: <INPUT NAME="adress" TYPE="text" SIZE=50 MAXLENGTH=50><BR>
xfire_username: <INPUT NAME="xfire_username" TYPE="text" SIZE=30 MAXLENGTH=30><BR>
Sumbit: <INPUT NAME="Sumbit" TYPE="submit" VALUE="Sumbit"><BR>
<INPUT TYPE="submit" VALUE="submit">
</form>
<br>
<br>
<br>
<?php
}
function member_display ($tablename, $connection)
{
$query_string = "SELECT* FROM $tablename";
$result_id = mysql_query($query_string, $connection);
$column_count = mysql_num_fields($result_id);
print("<table border=1> \n");
while($row = mysql_fetch_row($result_id))
{
print("<tr align=left valign=top>");
for($column_num = 0;
$column_num < $column_count;
$column_num++)
print("<td>$row[$column_num]</td>\n");
print("</tr>\n");
}
print("</table>");
}
?>
<?php member_display("mytest" , $mysql_connect); ?>
</body>
</html>
<?php $mysql_connect = mysql_connect("localhost", "login", "password"); or die("Could not connect mySQL."); or die("Could not select the database."); if ($_POST['sumbit'] != "" ) { $name = $_POST['name']; $surname = $_POST['surname']; $adress = $_POST['adress']; $xfire_username = $_POST['xfire_username']; $query = "INSERT INTO `ekitorc_mySQLtest`.`mytest` ( `ID` , `name` , `surname` , `adress` , `xfire_username` ) VALUES ( NULL , '$name', '$surname', '$adress', '$xfire_username' ); "; or die("Could not make an account."); { print("New member added."); } } else { ?> <html> <head> <title>member registration/showing</title> </head> <body> <form action="members.php" method="post" enctype="text/plain"> name: <INPUT NAME="name" TYPE="text" SIZE=30 MAXLENGTH=30><BR> surname: <INPUT NAME="surname" TYPE="text" SIZE=30 MAXLENGTH=30><BR> adress: <INPUT NAME="adress" TYPE="text" SIZE=50 MAXLENGTH=50><BR> xfire_username: <INPUT NAME="xfire_username" TYPE="text" SIZE=30 MAXLENGTH=30><BR> Sumbit: <INPUT NAME="Sumbit" TYPE="submit" VALUE="Sumbit"><BR> <INPUT TYPE="submit" VALUE="submit"> </form> <br> <br> <br> <?php } function member_display ($tablename, $connection) { $query_string = "SELECT* FROM $tablename"; print("<table border=1> \n"); { print("<tr align=left valign=top>"); for($column_num = 0; $column_num < $column_count; $column_num++) print("<td>$row[$column_num]</td>\n"); } } ?> <?php member_display("mytest" , $mysql_connect); ?> </body> </html>
Dat laatste gedeelte, wat de leden in een tabel laat zien, dat gedeelte heb ik uit een boek.
Nou is mijn vraag, om uitleg te geven over de functie.
De rest snap ik.
Hij maakt eerst een tabel aan, met border 1.
Dan zet hij de query om (die alles selecteerd, van de ID, name, surname, adress, en de xfire_username) in Fetch Row die in een while staat.
Daarna maakt hij een TR, gebruikt een for loop zonder {}.
Wat ik niet snap omdat dat denk ik ook best kan in de while ().
Daarna maakt hij een TD aan, en met de forloop nummers weet hij op een of andere manier alles in een tabel te krijgen.
Ik snap niet hoe hij dat doet!
|