• 0

[PHP] Some sort of scoreboard.


Question

Hi there!

In two weeks we have some big fun activity day at school, in groups, and people are supposed to get points for it. Now, I'm charged with making a scoreboard and I thought it must be easy to just run a quick XAMPP server on a laptop, and on the external screen having a webpage in fullscreen with autorefresh, while I am on the laptop itself to enter scores.

I was thinking something about a page for all groups (about 40) with, next to each group, 25 input boxes. For the scoreboard it should just add up all of the 25 boxes for each group (to get a total score) and then display them in the right order. (highest points first).

Now, I know HTML, so formatting is no issue, and I know some PHP, but I don't know anything of integrating MySQL in PHP...

Anyone can give me a jumpstart?

Ty

Ambroos

Link to comment
https://www.neowin.net/forum/topic/749726-php-some-sort-of-scoreboard/
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hi,

This tutorial is just about the best on the internet...

http://www.tizag.com/mysqlTutorial/

Basically, you do the following:

1) Create a database and a table to store the scores (use phpmyadmin provided in xampp)

2) Connect to the database with a username and password

mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("DBNAME") or die(mysql_error());

2) Insert the scores into the database

mysql_query("INSERT INTO TABLENAME (column1, column2etc) VALUES ('.$_POST['textbox1'].', '.$_POST['textbox2'].' ) ") or die(mysql_error());

3) Query, and output the scores from the database and format using HTML to display it on a page

$query = "SELECT * FROM TABLENAME ORDER BY COLUMN ASC"; 	 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
	echo $row['column1']. " - ". $row['column2'];
	echo "<br />";
}

4) You can order the scores by using ORDER BY as per above, and just tell it which column you want to order by...

5) You'll need to add your scores together which you can do using either the SQL Count function, or by putting the scores into an array and counting them using PHP.

As long as you set the table, database and column names correctly, that would give the following functioning script. You just need an input page with a form setup for the scores to be typed into.

<?php

mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error());
mysql_select_db("DBNAME") or die(mysql_error());

mysql_query("INSERT INTO TABLENAME (column1, column2etc) VALUES ('.$_POST['textbox1'].', '.$_POST['textbox2'].' ) ") or die(mysql_error());

$query = "SELECT * FROM TABLENAME ORDER BY COLUMN ASC"; 	 
$result = mysql_query($query) or die(mysql_error());

// the while loop will run until there are no more results to display

while($row = mysql_fetch_array($result)){
	echo $row['column1']. " - ". $row['column2'];
	echo "<br />";
}

?>

Get familiar with connecting and outputting, and then you can post your code and I'm sure someone will help you with the counting functions...

  • 0

Hey,

mysql_query("INSERT INTO TABLENAME (column1, column2etc) VALUES ('.$_POST['textbox1'].', '.$_POST['textbox2'].' ) ") or die(mysql_error());

Just make sure you validate your input! As anyone could put in some dodgy values into the textboxes and it would be ran as a SQL query.

Look here: http://www.tizag.com/mysqlTutorial/mysql-p...l-injection.php

  • 0
  Knad said:
Hey,

mysql_query("INSERT INTO TABLENAME (column1, column2etc) VALUES ('.$_POST['textbox1'].', '.$_POST['textbox2'].' ) ") or die(mysql_error());

Just make sure you validate your input! As anyone could put in some dodgy values into the textboxes and it would be ran as a SQL query.

Look here: http://www.tizag.com/mysqlTutorial/mysql-p...l-injection.php

We will run the script only on one pc (which doubles as a server) just for one day, and it won't be connected to any networks, so that won't be necessary since I will be the only person entering values.

@Pip: thanks, gonna try it!

  • 0
  Knad said:
Hey,

mysql_query("INSERT INTO TABLENAME (column1, column2etc) VALUES ('.$_POST['textbox1'].', '.$_POST['textbox2'].' ) ") or die(mysql_error());

Just make sure you validate your input! As anyone could put in some dodgy values into the textboxes and it would be ran as a SQL query.

Look here: http://www.tizag.com/mysqlTutorial/mysql-p...l-injection.php

:blush: fair cop guv

@Ambroos, glad you're enjoying it - what knad says is a good habit to get into...

If you're only using form input, you could just stick this line at the top of every page with your connect string

//stolen from php.net
array_map("mysql_real_escape_string",$_POST);

can you tell I'm bored...

  • 0
  pip said:
:blush: fair cop guv

@Ambroos, glad you're enjoying it - what knad says is a good habit to get into...

If you're only using form input, you could just stick this line at the top of every page with your connect string

//stolen from php.net
 array_map("mysql_real_escape_string",$_POST);

can you tell I'm bored...

:D

Thanks, I'll remember it.

Okay, now my score input form is done and everything works fine in my Virtualboxed Xampp! Just using a simple JS to add up all the scores for the single matches. To do: make the scoreboard with autosort... and that'll be tomorrow :p

Ty everyone ^^ I love Neowin

(now i just hope our school's IT department will give me an admin username/pass so i can at least install xampp)

  • 0

Hi everyone!

Just finished my stuff, and I'd just like to show you what I've made! Wouldn't have been possible without Pip's great hints links and examples!

Screenshots are from a virtualboxed XP with Firefox 3.1b3 and the window resolution we will be using to project it with.

1. Select what group you want to edit (uses form post that a php page picks up)

post-151800-1237843550_thumb.png

2. Enter the scores for the group (O1 - O20 stands for the 20 different things ppl can get scores for, eten and geld are two bonusthings they get points for).

A javascripts adds up all the form fields and puts the total in totaal. (the +1 buttons just add 1 to the corresponding text field).

post-151800-1237843666_thumb.png

3. Update done page, shows a quick review of the group you just edited. Go to group input on left side to start new edit

post-151800-1237843713_thumb.png

4. The live scoreboard (for display on a second monitor) shows the Top 10 with groupnames and corresponding scores (the 'totaal' thing). Small between brackets is the group ID (number they will have to remember themselves too) so I can find things quickly if something is wrong etc.

post-151800-1237843832_thumb.png

I know it needs some font tweaking, but that's just some CSS and a 1 minute job, but not today!

If anything goes really wrong I can always just go to PHPMyAdmin and fix it. Nothing should go wrong though, I'm the only one who will be entering scores so I know what to do :p

I am VERY happy with the result as it is EXACTLY what I wanted ^^ It felt awesome to create something yourself if it doesnt exist yet!

Thanks everyone!

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • No operating system works well with programs that modify its interface. There will always be bugs, whether it's MacOS or Linux. Windows too, you'll only suffer from bugs using this crap software.
    • KDE brings UI improvements, bug fixes and more to Plasma 6.4 as stable release draws near by David Uzondu With less than a month to the release of Plasma 6.4, the KDE dev team has shared what it has been working on in the latest issue of its weekly roundup. The update shows a heavy focus on user interface polish and a whole slew of bug fixes as the June 17 release date gets closer. The team has pushed a number of UI refinements for the upcoming version. On the System Settings page for Wi-Fi, the network list can now be fully navigated with a keyboard. KDE also disabled the ability to drag and drop displays on top of one another in the monitor settings. This was done because it could create unsupported arrangements that triggered a cascade of strange bugs throughout the system. Waking up a sleeping computer by pressing the power button no longer causes the bizarre logout screen to appear after you unlock it, which is a relief. Alignment issues in the settings page for the Digital Clock widget were also resolved. The list of bug fixes for 6.4 is extensive. The development team has fixed the most common crash affecting the System Monitor and squashed another one related to a divide-by-zero error. For users with multiple monitors, a long-awaited fix has landed that prevents windows from disappearing when the screen they are on gets disconnected. Even the humble Sticky Notes widget received attention; it will no longer freeze the Plasma shell if you place it on a very thick panel. Discover, the software center, also had a bug patched that caused it to crash if closed too quickly after launch. Here's the full list of improvements: Putting a Sticky Note widget on a very thick panel can no longer cause Plasma to freeze; now, you can use a thick panel with a sticky note on it as a notes sidebar. Fixed the most common System Monitor crash. Fixed another crash in System Monitor, this time a divide-by-zero. Fixed a case where xdg-desktop-portal-kde could crash after you choose a video source to start streaming. Fixed a bug that caused Discover to crash if you close it immediately after it launched. Fixed multiple subtle bugs with the screen chooser widget and OSD that caused it to do the wrong thing on rotated screens or when mirroring screens. Fixed a bug that caused the System Settings’ search field not to be focused properly when pressing Ctrl+F while any UI elements in a settings page already had focus. Fixed the root cause of multiple issues involving windows disappearing when you disconnect the screen they’re on. Clicking a button on a desktop widget that opens a menu no longer inappropriately makes the widget enter Widget Edit Mode. Files with a # or ? character in their name or full path are no longer unexpectedly missing from the history lists in Kicker/Kickoff/etc launchers. Fixed a bug that caused the screen chooser window to sometimes not appear as expected when OBS was launched. Fixed a bug that caused tiled windows on a multi-screen setup to lose their tiling settings when the system went to sleep and woke up again. The "Move window to [activity]" feature now works properly when invoked from the Task Manager widget. Fixed a bug in the Kicker Application Menu that caused keyboard navigation not to work if the popup opened with an item under the pointer. In the Overview effect’s grid view, dragging windows tiled on one virtual desktop over to a different virtual desktop now keeps them tiled as expected. The focus may be on the imminent 6.4 release, but work on what comes next never really stops. Looking ahead, development on Plasma 6.5 is already well underway. Just last week, the KDE team brought several performance improvements to Plasma 6.5.0. This week, the team fixed a nagging bug that sometimes caused the Networks widget to think a hotspot was still enabled after disconnecting from Wi-Fi. On the features side, the System Settings' Fonts page now prevents you from breaking your system entirely by setting fonts below 4pt. In addition to that, switching time spans in the Info Center’s energy page now features smooth graph animations. Performance-wise, kwriteconfig should also be faster, allowing changes you made to the keyboard layout using the tool to reflect immediately.
    • Display Driver Uninstaller (DDU) 18.1.1.4 by Razvan Serea Display Driver Uninstaller (DDU) is a utility for completely removing AMD/NVIDIA/INTEL graphics drivers and related packages from your system, attempting to eliminate all leftovers (including registry entries, folders and files, driver store). Though AMD/NVIDIA/INTEL drivers can usually be removed via the Windows Control Panel, this uninstaller tool was created for situations where standard uninstall fails, or when you need to fully remove NVIDIA or ATI graphics card drivers. After using this driver cleaner, your system will behave as though it’s the first time you’re installing a new driver—similar to a fresh Windows installation. As with all such tools, we recommend creating a restore point beforehand, allowing you to undo changes if issues arise. If you're having trouble installing an older or newer driver, try it—there are reports that it resolves such problems. Recommended usage: The tool can be used in Normal mode but for absolute stability when using DDU, Safemode is always the best. Make a backup or a system restore (but it should normally be pretty safe). It is best to exclude the DDU folder completely from any security software to avoid issues. You do NOT need to uninstall the driver prior using DDU. Requirements: .NET Framework 4.8 Compatible with Windows 7, 8, 8.1, 10, and 11 (32-bit or 64-bit) Note: Using on Insider Preview builds is at your own risk. Display Driver Uninstaller (DDU) 18.1.1.4 changelog: Intel: Added NPU presence detection before removing shared DLL files (these were previously left to prevent potential NPU-related issues). Intel: Added optional NPU removal Improved "Extension" driver removal process. Updated several translations. Download: Display Driver Uninstaller 18.1.1.4 | 1.7 MB (Freeware) Download: DDU Portable | 1.2 MB Links: Display Driver Uninstaller Home Page | Screenshot | Forum Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • That is what I also think to a point. How is 26 necessarily different than just another iteration like 18, 19, 20, etc? At first I think it would be better for Apple to use 2026, 2027, and then maybe truncate it to just 28, 29, and so on. Granted, I also think it makes more sense to use the year when it was released (2025 or 25), not 26/2026. Maybe Apple's thinking is as stated by Aditya that the bulk of a release being the current release is during the following year (2026, for example) after it is released (2025, for example). There are other examples of these sorts of things. In the NBA, the season has always started in the Fall and ends in the Spring. When the season ends is how the season is named. So, this is the 2025 NBA season and the Pacers and Thunder are playing to be the 2025 NBA Champions. The NFL starts in the Fall and the end of the season is always in the beginning of the next year as well. The Super Bowl was played on February 9, 2025, but that was the end of the 2024 NFL season. So, contrary to the NBA, the NFL names it season based on when it starts, not when it ends. Maybe that is because more of the NFL season is played at the end of the year (2024 in the most recent example) whereas most of the NBA season is played in the first half of the following year (2025 in the current example).
  • Recent Achievements

    • Week One Done
      abortretryfail earned a badge
      Week One Done
    • First Post
      Mr bot earned a badge
      First Post
    • First Post
      Bkl211 earned a badge
      First Post
    • One Year In
      Mido gaber earned a badge
      One Year In
    • One Year In
      Vladimir Migunov earned a badge
      One Year In
  • Popular Contributors

    1. 1
      +primortal
      495
    2. 2
      snowy owl
      252
    3. 3
      +FloatingFatMan
      251
    4. 4
      ATLien_0
      228
    5. 5
      +Edouard
      191
  • Tell a friend

    Love Neowin? Tell a friend!