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
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 6:58 pm
This is the code that I have already done.
Code: Select all
<?php
$value1=$_GETї'value1'];
$value2=$_GETї'value2'];
$value3=$_GETї'value3'];
$value4=$_GETї'value4'];
$username=$_GETї'username'];
$total1=(($value1 + $value2 + $value3) / $value4);
$total2=$total1 * 10;
echo "<font face=verdana size=2 color=red>{$_GETї'username']}</font><br>";
echo "<font face=verdana size=2>Games Won </font><br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value1']}</font><br>";
echo "<font face=verdana size=2>Games lost by someone reaching 100 mojo</font> <br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value2']}</font><br>";
echo "<font face=verdana size=2>Games lost by zero </font> <br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value3']}</font><br>";
echo "<font face=verdana size=2>Games Played</font> <br>";
echo "<font face=verdana size=2 color=red>{$_GETї'value4']}</font><br>";
echo "<font face=verdana size=2>Percent of the time you/someone quit </font><br>";
echo "<font face=verdana size=2 color=red>{$total2}%</font>";
?>
What I want to do with it is to take the
and store it on a .txt file so it has a record of what the % is for people.
I tried using the fopen,fwrite,fclose functions but I just can't seem to get them to work. Also how would I be able to have a top 10 list of the highest %'s. Hopefully this makes sense.
-Peyce
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 7:14 pm
well you have the right idea with fopen n fwrite functions.
try this
Code: Select all
<?php
$log = "whatever.txt";
if(file_exists("$log")) {
$write = fopen($log, "r+");
fwrite($write, $username);
fclose($write);
} else {
echo "$log could not be found";
}
?>
this should write the username...
do you have access to a MySQL database? what you want would be easier if you went thru that
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 7:28 pm
where would i put that code? in the same file as the other php code?
and yea i have MySQL but i have no idea how to work it and php seems easier
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 7:32 pm
i'd suggest you try to learn that... seems your new with php too?
Heres a good tutorial to get you started with both.
A MySQL DB is alot better than a text file when storing info. plus you can arrange, edit, add, delete, etc with stuff in a sql table alot easier then a text file.
http://hotwired.lycos.com/webmonkey/99/ ... rogramming
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 7:34 pm
u can place the code anywhere after you defined the variables
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 7:36 pm
thanks alot man, im gonna get one that tutorial right away
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 7:39 pm
anytime, and always come back here for help with things you dont understand. Alot of very nice and intelligent people here willing to help.
and your choosing the right path by changing your method to MySQL. you'll thank me in the end.
good luck and godspeed
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 8:06 pm
hmm, i stumbled into a little problem, in the tutorial is says to put stuff into the comand line, but i dont know where that is, for MySQL i have phpmyadmin but it doesnt say anthing about that in the tutorial
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 8:08 pm
by "stuff" i take it u mean the create table?
In phpmyadmin, after u named the table, click the table and you'll see a "sql" link
paste your create table code there
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 8:16 pm
wut about the comand line?
it says to put
mysql -u root mydb < mydb.dump
in there
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 8:20 pm
Oh.. i'm sorry for not explaining...
in the first lessons of that tutorial, it tells u how to set-up php and mySQL on your own server, its thinking your an actual web hoster with the server.
ignore that part, just mimic the table in that tutorial
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 8:23 pm
its ok, you've explained way more then you needed too and i thank you for that, you reply to my posts before i even submit them lol
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 8:31 pm
i get this error when i try to view the php file that connects to the mysql
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 25
First Name:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 29
Last Name:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 33
Address:
Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/krunk/public_html/php/mysqlexample.php on line 37
Position:
tim
DevNet Resident
Posts: 1165 Joined: Thu Feb 12, 2004 7:19 pm
Location: ohio
Post
by tim » Fri Mar 19, 2004 8:33 pm
read your private message.
and people usually post code so people can see the errors, but it seems like you dont ahve your table set-up correctly.
you connect to your DB before? lets see the code
bawla
Forum Contributor
Posts: 116 Joined: Fri Mar 19, 2004 9:15 am
Post
by bawla » Fri Mar 19, 2004 8:41 pm
Code: Select all
<?php
$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);
$result = mysql_query("SELECT * FROM employees",$db);
printf("First Name: %s<br>\n", mysql_result($result,0,"first"));
printf("Last Name: %s<br>\n", mysql_result($result,0,"last"));
printf("Address: %s<br>\n", mysql_result($result,0,"address"));
printf("Position: %s<br>\n", mysql_result($result,0,"position"));
?>
thats the code i got form the tutorial,
check your private msg