Now time for VS help!

Relax, kick those feet up. Enjoy a few laughs and take it easy.

Now time for VS help!

Unread postby Jnr » 14 Sep 12, 8:17 pm

ITS OK
Last edited by Jnr on 26 Oct 12, 3:13 pm, edited 2 times in total.
Jnr

User avatar
1337 p0st3r
 
Offline
Posts: 1086
Joined: 7 Jan 06, 2:03 am
Location: Perth

Re: PHP Help

Unread postby Makena » 14 Sep 12, 8:35 pm

What PHP I know was only what I had to learn for uni, so anyone who actually knows it can probably expand/correct me on this, but ..

Depending what you need to do to the data, will change what you want to do, If you just need to fill in the form, hit submit, and then display something done with that data on the next page, you can use POST/GET to do so, or if you need to hold the data for longer/storing records or whatever, you'd want to do so with a database of some kind.
ImageImage
Makena

User avatar
Has 1 million gon bucks
 
Online
Posts: 1696
Joined: 22 May 04, 4:00 pm
Location: Melbourne

Re: PHP Help

Unread postby Jnr » 14 Sep 12, 8:43 pm

Well, the way I've understood it as when I hit submit it needs to be linked to a php script that will then save that data to a .txt file, so then I can just import that txt file into the main script with all the data and process it that way.

The only problem is, I'm not sure how to link it :/
Jnr

User avatar
1337 p0st3r
 
Offline
Posts: 1086
Joined: 7 Jan 06, 2:03 am
Location: Perth

Re: PHP Help

Unread postby Otto-matic » 16 Sep 12, 3:38 pm

Been a while for me too.

Wouldn't it be easier to post or get the data when they hit submit and have the page that does the processing save it to a text file, then process it on the same page?
Otto-matic

User avatar
1337 p0st3r
 
Offline
Posts: 1399
Joined: 24 Dec 04, 12:34 am
Location: Space

Re: PHP Help

Unread postby Fireslide » 16 Sep 12, 3:51 pm

Never write to a text file if you don't have to.

Either some parts of the form go into a database of some kind, or you're using it to output some result which then is displayed afterwards.

That's not to say you can't test your code is working fine by writing to a text file in the interim, but really a bunch of well placed print statements achieves the same effect.
Image
Fireslide

User avatar
Moderator
 
Offline
Posts: 3934
Joined: 3 Feb 03, 9:52 pm
Location: Adelaide, SA

Re: PHP Help

Unread postby diamondd » 16 Sep 12, 3:57 pm

Fireslide wrote:Never write to a text file if you don't have to.

Either some parts of the form go into a database of some kind, or you're using it to output some result which then is displayed afterwards.

That's not to say you can't test your code is working fine by writing to a text file in the interim, but really a bunch of well placed print statements achieves the same effect.

he's not trying to deploy this thing, sounds like a basic early assignment in high school or uni with specific requirements to write to a txt file. Certainly beyond the scope of also having a database to worry about anyway.

as far as "linking" goes you can basically just have the submit button call your php script and there you go, its linked. Then in the script you just pull out the info using the usual POST methods and write it to a file.
diamondd

User avatar
Forgotten What The Sky Looks Like
 
Online
Posts: 2566
Joined: 23 Sep 08, 7:12 pm

Re: PHP Help

Unread postby Jnr » 16 Sep 12, 11:46 pm

Okay so the assignment is based on us filling out a form related to the olympics, things like Event Participant, Country, Event Won, Medal Won and whether a World Record was achieved.

The main goal is for us to order the information and tally the countries according to total medals won, there's also a bunch of other restrictions/restraints we have to follow.

The only problem is, I'm not sure how to go about getting the data from the form.

Any thoughts?
Jnr

User avatar
1337 p0st3r
 
Offline
Posts: 1086
Joined: 7 Jan 06, 2:03 am
Location: Perth

Re: PHP Help

Unread postby diamondd » 17 Sep 12, 12:10 am

diamondd

User avatar
Forgotten What The Sky Looks Like
 
Online
Posts: 2566
Joined: 23 Sep 08, 7:12 pm

Re: PHP Help

Unread postby Jnr » 17 Sep 12, 12:28 am

diamondd wrote:http://www.w3schools.com/html/html_forms.asp
http://www.w3schools.com/php/php_post.asp


thanks :)
Jnr

User avatar
1337 p0st3r
 
Offline
Posts: 1086
Joined: 7 Jan 06, 2:03 am
Location: Perth

Re: PHP Help

Unread postby Jnr » 17 Sep 12, 10:32 pm

I have another question now.

The HTML form code is as follows (little snippet)
Hidden: show
Code: Select all
<td align="center"><input name="CompName_R_1" type="text" id="CompName_R_1" size="40" maxlength="80"></td>
    <td align="center"><select id="CountryList_R_1" name="CountryList_R_1">
[list of countries]
<td align="center"><select id="Event_R_1" name="Event_R_1">
[list of events]
<td align="center"><input name="MedalWon_R_1" type="text" id="MedalWon_R_1" size="1" maxlength="1"></td>
    <td align="center"><input name="WorldRecord_R_1" type="text" id="WorldRecord_R_1" size="1" maxlength="1"></td>
This repeats 25 times in the code as there are 25 entry fields.


I was thinking a for loop would be best to count the amount of medals x country has won, because that's the main part of the information.

This whole unit was pretty confusing, during the lectures the lecture slides had no information on PHP in particular, it was just based on basic coding information common throughout all languages (structure, modularisation, etc) a lot of it I already knew and such.
Jnr

User avatar
1337 p0st3r
 
Offline
Posts: 1086
Joined: 7 Jan 06, 2:03 am
Location: Perth

Re: PHP Help

Unread postby Fireslide » 18 Sep 12, 9:42 am

So if I understand correctly. The data already exists in some HTML document and you have to use something in php to scrape it? or do you have to make a form that adds to some kind of data structure and then order it?

A problem like this is perfectly suited to using a database in the real world. You'd have a table for countries, a table for events and a table for records. The form(s) would either add a country, add a new event, or add a countries performance in a given event.

The rest of the info could be drawn out from queries on those tables.

Now assuming you can't use databases, just create an array where first entry is country, second entry is medals won, then order that array by second entry and then display it as is.

If you don't have the data for medals won directly and you need to sum it up, use a for loop to go through every event and add to the array above.

There's a million ways to do things when it comes to programming. It all comes down to what your data looks like and what you want to do with it.
Image
Fireslide

User avatar
Moderator
 
Offline
Posts: 3934
Joined: 3 Feb 03, 9:52 pm
Location: Adelaide, SA

Re: PHP Help

Unread postby Brad » 21 Sep 12, 9:19 am

Assuming form method is POST

Code: Select all
<?php
$country = $_REQUEST['CountryList_R_1'];

echo "Selected country is $country";

$f = fopen("YOURTEXTFILEHERE.txt", "a");
fwrite($f, "$country $medal $company \n "); // build string of text to write to file.
fclose($f);

?>


either repeat that for every field 25 times or build an array. As Fireslide said, an array would be the best way if you cant use a DB.
More info
http://php.net/manual/en/function.fopen.php
http://www.tizag.com/phpT/files.php
To POV for a sig, but HEY it is GREEN!
Brad

User avatar
Padawan
 
Online
Posts: 264
Joined: 4 Feb 03, 9:13 pm
Location: P4C-970

Re: Now time for VS help!

Unread postby Jnr » 26 Oct 12, 1:06 pm

bump cause of new problem
Jnr

User avatar
1337 p0st3r
 
Offline
Posts: 1086
Joined: 7 Jan 06, 2:03 am
Location: Perth


Return to The Water Cooler

Who is online

Users browsing this forum: Ashigaru, Bek, Disco LT, Makena and 5 guests