Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > PHP

Reply
 
LinkBack Thread Tools Display Modes
Old 06-11-2002, 07:14 PM   #1 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
Question about a php prediction script(Great Site!)

Hello everyone! I just signed up and I have a questions to ask. I am hoping that someone here can answer it because everyone else just ignored me. The question is about making a php script that does prediction. I am doing a site that does races and I want to make a php script that is like a form. So that I can enter in the names and there overall points right after there name. Then when I press the submit button it calculates and puts the name in a table in the order of first, second, third, etc. I don't want it to be where it just puts them in order of there overall points. I would like it to be where it takes the overall points in consideration of there place. If the point thing is too much don't worry about it. I don't the whole script I just need to know how to basically get started in doing this because this is my first time attempting to make my own script. I would greatly appreciate the help! Thanks!
Geetazz is offline   Reply With Quote
Old 06-11-2002, 07:29 PM   #2 (permalink)
revolution
Legend in my own mind
 
revolution's Avatar
 
Join Date: May 2002
Location: florida
Posts: 618
revolution is on a distinguished road
Send a message via AIM to revolution
we can sure try

im a little confused on the overall points thing...
Quote:
Then when I press the submit button it calculates and puts the name in a table in the order of first, second, third, etc. I don't want it to be where it just puts them in order of there overall points. I would like it to be where it takes the overall points in consideration of there place.
it would seem that it needed to be a running total script with a place to put in thier "places" right?
__________________
Is it me or does the word abbreviation seem a little long?


registered user #193524 with the Linux Counter,
http://counter.li.org
revolution is offline   Reply With Quote
Old 06-11-2002, 07:39 PM   #3 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
Well, on the racing SIM like game that I am making they will have a stats page with like there speed, accelleration, and more. Then below all of that it will have overall like stat. I would like to be able to put either just the overall stat points or all of the other stats with ther name so that when it caluclates the places it will take that in concideration. And you right a total script so that there is a place to put the places.
Geetazz is offline   Reply With Quote
Old 06-11-2002, 08:01 PM   #4 (permalink)
revolution
Legend in my own mind
 
revolution's Avatar
 
Join Date: May 2002
Location: florida
Posts: 618
revolution is on a distinguished road
Send a message via AIM to revolution
hmm, i tried but failed miserably


lemme think
__________________
Is it me or does the word abbreviation seem a little long?


registered user #193524 with the Linux Counter,
http://counter.li.org
revolution is offline   Reply With Quote
Old 06-11-2002, 08:05 PM   #5 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
I appreciate you trying. This other person did something similar but would not tell me how she did it. But she did tell me what it did. She said, "The remote script is just a script I wrote that sits on my server. I run it, and it takes all of the entries in the races, calculates their results, then sorts them into the proper placings in a seperate table in the database." I hope this helps. Again thanks!
Geetazz is offline   Reply With Quote
Old 06-11-2002, 08:55 PM   #6 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i can help. i just need a little bit more information:

1. is it like horse racing? car racing? what kind of race is it?
2. how many racers are in a race? *and* are there always the same amount of racers in each race?
3. are there multiple races per day? or once per day? how often are the races?
4. do you want to keep other information about the racers?
5. what type of point system is it? ie. 1st place is 10 points, 2nd place is 8 points .. etc..

answer these questions and i'll come up with an idea =)

-mike
sde is offline   Reply With Quote
Old 06-11-2002, 09:21 PM   #7 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
Well, I have not completly decided on what type of racing but you can just do it has horse racing and I will change it if I change my mind.
1) Can just use horse racing as the type
2) If possible can you make it where there are two different types. One being One on One and the other being where they are 12 racers. There multiple races per day.
3) Most likely there will be multiple races per day
4) I think that is it. But if I need to add more I will look at how you have it and just add more
5) Winner gets two points on One on One. The winner in the 12 racers goes like this: 1st - 10pts, 2nd - 6pts, 3rd - 4pts, 4th - 1pt.

Hope this helps! Thanks
Geetazz is offline   Reply With Quote
Old 06-11-2002, 09:52 PM   #8 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i was going to make this all complex.. but if this is a beginner project, then just do it like this.. all you need is one table:

tablename: racers
fields:

name ( varchar(30) )
score ( int )

ok, now you php scripts are going to be what calculate and add to the scores . . . you will need a form for the 12 racer race, and the 2 racer race.

<html>
<body>

<form method=post action=php_self>
1st place <input type=text name=racer_1><br>
2nd place <input type=text name=racer_2><br>
3rd place <input type=text name=racer_3><br>
4th place <input type=text name=racer_4> <input type=submit name=submit value=Submit>
</form>

<!--ok .. now the php script would look something like this: -->
<?
// i would place this php script before any html on the page

// if the form was submitted, execute this code
if($submit){

// hoepfully you already have a connect script
include("connect.php");

for($i=0;$i<4;$i++){

// define scores for each place

if($i==0){
$add=10;
} elseif ($i==1){
$finished=6;
} elsif ($i==2){
$finished==4;
} elseif ($i==3) {
$finished=1;
}

// check to see if the racer exists in the table racers
$result=mysql_query("select * from racers where name='racer_$place'");

// if the racer exists, get current score and add to it
if($result){
$current_score=mysql_result($result,0,"score");
$score=$current_score + $finished;

// then update the table with the new score
$result=mysql_query("update racers set score='$score' where name='$racer_$place'");

// else, if the racer doesn't exist.. insert a new record with the score
} else {
$result=mysql_query("insert into racers set name='racer_$place',score='$finished'");
}
}

}
?>
</body>
</html>

ok, now this should add the correct info to your table.. now to display it .. i'll write this in the next post.

Last edited by sde; 06-11-2002 at 10:00 PM.
sde is offline   Reply With Quote
Old 06-11-2002, 09:56 PM   #9 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
THANKS!!
Geetazz is offline   Reply With Quote
Old 06-11-2002, 10:01 PM   #10 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
i added a few changes to that .. some of it was wrong after i took a look at it again.. there's probably a 100 different ways to do this, but this is just an example off the top of my head..

ok, stay tuned .. i'm going to give you an idea on how to display this information on a web page now that it is entered in the database.
sde is offline   Reply With Quote
Old 06-11-2002, 10:10 PM   #11 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
<?
// display_racers.php

// connect to your db
include("connect.php");

// get select information from db and order by score in descending order.
//This example will show the top 10 racers
// If you want to see all racers.. leave out "Limit 10" in the query
$result=mysql_query("select * from racers order by score desc limit 10");
$num=mysql_result($result);

// start a table
echo "<table border=1 cellspacing=5 cellpadding=0>";

// define loop ..
for($i=0;$i<$num;$i++){

// get data from each row of the result
$name=mysql_result($result,$i,"name");
$score=mysql_result($result,$i,"score");

// echo your newy defined variables to the screen
echo "<tr><td align=right><font size=2> $name: </td>
<td><font size=2> $score</td></tr>";
}

// above the loop just ended .. and below we close the table and page
echo "</table>
</body>
</html>";
?>

-- i didn't test this code, .. but if you have questions about it , let me know .. have fun =)
sde is offline   Reply With Quote
Old 06-12-2002, 03:28 PM   #12 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
OK, I have everything up but it don't work. This is the script I have:

<?
// display_racers.php

// connect to your db
include("vSignup/auth.php");
// get select information from db and order by score in descending order.
//This example will show the top 10 racers
// If you want to see all racers.. leave out "Limit 10" in the query
$result=mysql_query("select * from racers order by score desc limit 10");
$num=mysql_result($result);

// start a table
echo "<table border=1 cellspacing=5 cellpadding=0>";

// define loop ..
for($i=0;$i<$num;$i++){

// get data from each row of the result
$name=mysql_result($result,$i,"name");
$score=mysql_result($result,$i,"score");

// echo your newy defined variables to the screen
echo "<tr><td align=right><font size=2> $name: </td>
<td><font size=2> $score</td></tr>";
}

// above the loop just ended .. and below we close the table and page
echo "</table>
</body>
</html>";
?>
<form method=post action=php_self>
1st place <input type=text name=racer_1><br>
2nd place <input type=text name=racer_2><br>
3rd place <input type=text name=racer_3><br>
4th place <input type=text name=racer_4> <input type=submit name=submit value=Submit>
</form>

Please tell me what I did wrong. The auth page connects me to the server and stuff. All that comes up is the form then when I enter something in and press submit the code says 502 connection failed. Can you please tell me what is wrong. Thanks
Geetazz is offline   Reply With Quote
Old 06-12-2002, 03:34 PM   #13 (permalink)
abc123
bloomberg
 
abc123's Avatar
 
Join Date: Jun 2002
Location: bloomberg
Posts: 263
abc123 is on a distinguished road
Send a message via AIM to abc123 Send a message via Yahoo to abc123
Did you creare the table? in your database?

are you using the right passwords?, username?
__________________
-- bloomberg.
abc123 is offline   Reply With Quote
Old 06-12-2002, 03:36 PM   #14 (permalink)
Geetazz
Registered User
 
Join Date: Jun 2002
Posts: 12
Geetazz is on a distinguished road
Send a message via AIM to Geetazz
yup I created the database and stuff but it is still not working. That stuff works with my other scripts.
Geetazz is offline   Reply With Quote
Old 06-12-2002, 03:57 PM   #15 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,446
sde is on a distinguished road
That sounds like there is a problem with your connection script..

try making a seperate page just to test your connection script:

test.php
<?

include("vSignup/auth.php");

$result=mysql_query("insert into racers set name='test',score='0'");

if($result){
echo "connection successful";
} else {
echo "something is wrong with my connection script";
}

?>
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
PHP question I believe Ilya020 PHP 3 07-08-2003 08:08 PM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM


All times are GMT -8. The time now is 11:16 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting