php script help!!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wazza91
Forum Newbie
Posts: 1
Joined: Tue Feb 22, 2011 5:11 pm

php script help!!!

Post by wazza91 »

hi could someone help me with this task im a novice at php so help would be great thaks.
task:
b. Create a php script to [See Week 3 worksheet]

- receive the chosen option from the select box & textbox in the html file & check it is within range and is a number (using the is_numeric( ) function)
- Assign 7 employee records (Employee Number, Employee Name, Age, Department Name) into a 2 dimensional sequential array (using employee numbers 1 to 7) and your own made up values for the other record details – remember that text values are enclosed within inverted commas whereas numeric values are not:
- See PHP worksheet 3 for how a 2D array is created in a program
- If the chosen select option is to print the whole table
o – then print all 7 records in an html table with a header row
• You will need a for loop to print a record
• You will need to manipulate array values
(You should use a variable for the row number to
generalise row printing a row using the for loop)
- If the chosen option is to print a selected record, use the record number from the textbox to
o Print that particular record including the header details row
• E.g. for employee number 1 by transposing it to the array row index number
• This row number should be generalised using a variable for the row index number
• Sample record
Employee Number Employee Name Age Department Name
1 J Smith 55 Sales

this what i have so far:

Code: Select all

<?php
$output = "";
$total = 0;

for($i = 1; $i <= 7; $i++) {


$people = array(array(21, "John"), array(25, "Bill"), array(23, "Anna"), 
                 array(29, "Aine"),  array(19, "Pat"), array(30 , "Leanne") );



print "<table border=1>";
print "<tr><th>Age</th><th>Name</th></tr>";

for($x=0;$x<6;$x=$x+1) {     

print "<tr><td>" . $people[$x][0]  . "</td>";
print "<td>" . $people[$x][1]  . "</td></tr>";

}

?>
not to sure what im doing to be honest!!!
Last edited by califdon on Tue Feb 22, 2011 7:21 pm, edited 1 time in total.
Reason: Moderator added syntax=php tags to make code readable. Note to poster, please always do this.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: php script help!!!

Post by califdon »

As I'm sure you will appreciate, we won't do your assignment for you, but perhaps I can get you started on the right foot.

You need to start by outlining what your script must do. It won't get you anywhere to just write some lines of code. A good way to start is with some "pseudo code", meaning that you write in plain english what things have to be performed. Then, one by one, you replace each operation with the actual code that will do that.

So what's the first thing that your assignment stated? "Receive the selected option from the select box & textbox in the html file", right? If you have been reading about html forms, you should recognize that it will have to create 2 variables from the POST data sent by the html file. This should be at the top of your PHP script. As pseudo code, you could write it something like:

Code: Select all

// get the data sent by the form:
Then what's the next thing? Your assignment says "check it is within range and is a number (using the is_numeric( ) function)". So, your next pseudo code could be:

Code: Select all

// check that if the user entered anything in the textbox
// (to specify a record number to print), it is really a number
// (not an "X" or something) and that it is an allowable number
// (if you have just 7 records, any number larger than 7
// would not be acceptable).
Then go on to the next part of the assignment. That's where you need to start. When you've written pseudo code for everything, go back and start trying to write code to do each part. For the first one, replace that comment with something like:

Code: Select all

$action = $_POST['whatever the name of the html select box is'];
$recordnum = $_POST['whatever the name of the html textbox is'];
And so on.
Post Reply