Jump to content

Recommended Posts

I have all my pages set up but i would like it so that it would only show a certain game scores.

What i have at the minute is a web-page that handles all scores but does not say which game sent it. So the hi scores are kind of pointless.

What i thought i could do was add a gameid.

So my script could look at the gameid and store it, and when i would like to look at highscores i could type something.php?gameid=1 and it will show me everything for that game.

 

Below are my current scripts. Please can you help me change them.

uploadscore.php

<?php require('connect.php'); ?>
<?php
mysql_query("INSERT INTO myscorev1 
(name, score) VALUES('" . mysql_real_escape_string($_GET['name']) . "', '" . mysql_real_escape_string($_GET['score']) . "')") or die('Theres an error. Please try again.#');  

mysql_query("SELECT count(name) as position FROM myscorev1 WHERE score > ".mysql_real_escape_string($_GET['score'])) or die('Theres an error. Please try again.#');

$row = mysql_fetch_assoc($result);
$position = $row['position']+1;
echo "Score Uploaded# Your Position was ".$row['position']."#";
?>

 

viewalldata.php

<?php require('connect.php'); ?>
<?php
mysql_query("INSERT INTO myscorev1 
(name, score) VALUES('" . mysql_real_escape_string($_GET['name']) . "', '" . mysql_real_escape_string($_GET['score']) . "')") or die('Theres an error. Please try again.#');  

mysql_query("SELECT count(name) as position FROM myscorev1 WHERE score > ".mysql_real_escape_string($_GET['score'])) or die('Theres an error. Please try again.#');

$row = mysql_fetch_assoc($result);
$position = $row['position']+1;
echo "Score Uploaded# Your Position was ".$row['position']."#";
?>

 

viewscores.php

<?php require('connect.php'); ?>
<?php
// Get all the data from the "myscorev1" table
$result = mysql_query("SELECT * FROM myscorev1 ORDER BY score DESC LIMIT 0, 10")
or die('O no. Theres an error#');  

echo "";
echo "";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo ""; 
echo $row['score'];
echo "#"; 

} echo "#Completed";
?>

 

viewnames.php

<?php require('connect.php'); ?>
<?php
// Get all the data from the "myscorev1" table
$result = mysql_query("SELECT * FROM myscorev1 ORDER BY score DESC LIMIT 0, 10")
or die('O no. Theres an error#');  

echo "";
echo "";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo ""; 
echo $row['name'];
echo "#"; 

} echo "#Completed";
?>

 

viewall.php

<?php require('connect.php'); ?>
<?php
// Get all the data from the "myscorev1" table
$result = mysql_query("SELECT * FROM myscorev1 ORDER BY score DESC") 
or die('O no. Theres an error');  

echo "<table border='1' width='20%'>";
echo "<tr> <th>Name</th> <th>Score</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
// Print out the contents of each row into a table
echo "<tr><td>"; 
echo $row['name'];
echo "</td><td>"; 
echo $row['score'];
echo "</td></tr>"; 
} echo "</table>";
?>

 

Thank-you all very much.

Link to comment
https://forums.phpfreaks.com/topic/108014-solved-help-with-id/
Share on other sites

what your asking for is pretty basic MySQL,

your need to add a field called GameID then update the statements to suite

 

$gid = (int)$_GET['id'];
mysql_query("INSERT INTO myscorev1 
(name, score, GameID) VALUES('" . mysql_real_escape_string($_GET['name']) . "', '" . mysql_real_escape_string($_GET['score']) . "', $gid)") or die('Theres an error. Please try again.#');  

 

$gid = (int)$_GET['id'];
$result = mysql_query("SELECT * FROM myscorev1 WHERE GameID = $gid ORDER BY score DESC LIMIT 0, 10")
or die('O no. Theres an error#');  

 

etc

Link to comment
https://forums.phpfreaks.com/topic/108014-solved-help-with-id/#findComment-553613
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.