Creating a table where you decide the amount of rows and cells

First a .html page with a form where you have 2 textboxes and a submit button. In the first textbox you’ll write the number of rows and in the second the number of cells in every row.

 

testwithtablehtml

Afterwards, the code where you take the numbers from the textboxes and stock the into variables, which then decides the amount of rows and cells. This is how the code looks like:

testwithtablephp

The .html file is here for download: http://www.filehosting.org/file/details/563618/testwithtable.html

And the .php file where the table will be “drawn” is here to be found:
http://www.filehosting.org/file/details/563619/testtd.php

 

Writing To Arrays, Displaying From Beginning To The End And From The End To The Beginning + Writing To File And Display In Order And In Reverse – PHP

<html>
<head>
</head>

<body>
<?php

$minaKompisar = array(
“Batman”,
“Superman”,
“Red Hood”,
“Iron Man”
);

if(isset($_POST[‘inorder’])){
if(isset($_POST[‘namn’])){
if(isset($_POST[‘antal’])){
$antal = $_POST[‘antal’];
$names = $_POST[‘namn’];

//writing $names to a textfile
$fp = fopen(“test.txt”, “a”);
fwrite($fp,”\n”);
fwrite($fp,$names);
fclose($fp);

foreach($minaKompisar as $kompis)
{
echo $kompis;
echo ‘<br>’;
}

//listing the content in the textfile
$file=fopen(“test.txt”, “r”);
while(!feof($file)) {
echo fgets($file) . “<br>”;
}
fclose($file);

array_push($minaKompisar, $names);
$antal2;
$antal2 = $antal;
for($antal=1; $antal <= $antal2; $antal++)
{
echo $names;
//checks that $names is added to the array by as many times as written by the user in textbox “antal” on the preindex page.
array_push($minaKompisar, $names);
}
}
}
}

print_r($minaKompisar);

if(isset($_POST[‘reverse’])){
if(isset($_POST[‘namn’])){
if(isset($_POST[‘antal’])){
$antal = $_POST[‘antal’];
$names = $_POST[‘namn’];
$antal2=$antal;

//puts the $antal times of $names in the beginning of the array
//use only if you need it to
//
//for($antal=1;$antal<=$antal2;$antal++)
//{
//array_push($minaKompisar, $names);
//}
$fp = fopen(“test.txt”, “a”);
fwrite($fp,”\n”);
fwrite($fp,$names);
fclose($fp);

$reverseKompisar = array_reverse($minaKompisar, false);

//print_r($reverseKompisar);
foreach($reverseKompisar as $kompis)
{
echo $kompis;
echo ‘<br>’;
}
$antal2 = $antal;
for($antal=1;$antal <=$antal2; $antal++) {
echo $names;
array_push($reverseKompisar, $names);
}
print_r ($reverseKompisar);
}

$file = file(“test.txt”);
$file = array_reverse($file);
foreach($file as $f){
echo $f.”<br />”;
}
}}

?>
</body>

</html>

The above code might not work properly when copied and pasted, so I uploaded the files to a filesharing website.

1.You’ll need this one: ‘preindex.php’
http://www.filehosting.org/file/details/563152/preindex.php

2. You’ll need ‘index3.php’, which gets info from the previous file:
http://www.filehosting.org/file/details/563158/index3.php

A PHP Script That Adds Text To Arrays

The following code should go in a page that you have to name to “index.php”:

<html>
<head>
</head>

<body>
<?php

$minaKompisar = array(
“Batman”,
“Superman”,
“Red Hood”,
“Iron Man”
);

if(isset($_POST[‘inorder’])){
if(isset($_POST[‘namn’])){
if(isset($_POST[‘antal’])){
$antal = $_POST[‘antal’];
$names = $_POST[‘namn’];
foreach($minaKompisar as $kompis)
{
echo $kompis;
echo ‘<br>’;
}
array_push($minaKompisar, $names);
$antal2;
$antal2 = $antal;
for($antal=1; $antal <= $antal2; $antal++)
{
echo $names;
//checks that $names is added to the array by as many times as written by the user in textbox “antal” on the preindex page.
array_push($minaKompisar, $names);
}
}
}
}

print_r($minaKompisar);

if(isset($_POST[‘reverse’])){
if(isset($_POST[‘namn’])){
if(isset($_POST[‘antal’])){
$antal = $_POST[‘antal’];
$names = $_POST[‘namn’];
$antal2=$antal;
//puts the $antal times in the beginning of the array
//use only if you need it to
//
//for($antal=1;$antal<=$antal2;$antal++)
//{
//array_push($minaKompisar, $names);
//}

$reverseKompisar = array_reverse($minaKompisar, false);

//print_r($reverseKompisar);
foreach($reverseKompisar as $kompis)
{
echo $kompis;
echo ‘<br>’;
}
$antal2 = $antal;
for($antal=1;$antal <=$antal2; $antal++) {
echo $names;
array_push($reverseKompisar, $names);
}
print_r ($reverseKompisar);
}}}

?>
</body>

</html>

And you’ll need a frontpage that you will take the values of the textboxes from. THis is my “preindex.php”:

<html>
<head>

<body>

<?php

echo ‘<form action=”index.php” method=”post”>’;
echo ‘<input type=”submit” value=”In order” name=”inorder”>’;
echo'<input type=”submit” value=”reverse” name=”reverse”>’;

//this textbox won’t do anything.
echo ‘<input type=”text” value=”write something” name=”namn”>’;
echo ‘<input type=”text” value=”antal gånger” name=”antal”>’;
echo ‘<br>’;
echo ‘<input type=”submit” value=”namn” name=”name”>’;
echo ‘</form>’;

?>
</body>
</html>

 

Writing CSS to An Autogenerated PHP Document

skrivastylesheettillphpsida- index video

The marked line shows how the code for an external stylesheet that is to be atached to auto generated documents look like. Notice the extension – .php.

 

And here you can see how the code should look like in the file ‘style.php’

skrivastylesheettillenphpsida - style

Notice the <?php ?> paragrafs. The “header” line is reuired in order for the stylesheet to work..