
kingsbest
Members-
Posts
17 -
Joined
-
Last visited
Never
Everything posted by kingsbest
-
Display data from + and - 7 days using curdate.
kingsbest replied to kingsbest's topic in PHP Coding Help
lol date, well spotted now i feel a right plonker. Huge thanks. John. -
Display data from + and - 7 days using curdate.
kingsbest replied to kingsbest's topic in PHP Coding Help
Oops Sorry Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\wamp\www\modsite_fenton\index.php on line 52 line 52-while ($row = mysql_fetch_array($result)) Thanks for looking, John -
Hi All, I'm trying to display the results of fixtures played in the last week and the forthcoming fixtures for the next week, can anyone tell me what's wrong with my code please as im getting an error and im not even sure if this will display what i want? Please keep in mind that im a newbie at PHP thanks. <?php include("includes/db_connect.php"); mysql_select_db($dbname, $con) or die ($dbname); $result = mysql_query("SELECT * FROM scorecards WHERE date <= curdate() AND date >= DATE_SUB(curdate(), INTERVAL 7 day) ORDER BY DESC LIMIT 10"); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td colspan=\"5\">" . $row['date'] . "</td>"; echo "</tr>"; echo "<tr>"; echo "<td class='h5'>" . $row['home_grade_total'] . "</td>"; echo "<td class='h5'><a href='teamhistory.php?name_URL=".$row['home_team']."'>" . $row['home_team'] . "</a></td>"; echo "<td class='h5'>" . $row['result'] . "</td>"; echo "<td class='h5'><a href='teamhistory.php?name_URL=".$row['away_team']."'>" . $row['away_team'] . "</a></td>"; echo "<td class='h5'>" . $row['away_grade_total'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Best wishes, John.
-
Thanks again for the advice, i was planning on updating the database through php myadmin and not a CMS, is this more secure? Plus had a look at mysql_real_escape_string and added the following line=$name = mysql_real_escape_string($name); t0- $name = $_GET['name_URL']; $result = mysql_query("SELECT * FROM scorecards WHERE name = '$name' OR 'aname' = '$name'"); $name = mysql_real_escape_string($name); while ($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td class='h5'>" . $row['id'] . "</td>"; echo "<td class='h5'>" . $row['match_code'] . "</td>"; echo "<td class='h5'>" . $row['board_number'] . "</td>"; echo "<td class='h5'><a href='gamehistory.php?name_URL=".$row['name']."'>" . $row['name'] . "</a></td>"; echo "<td class='h5'>" . $row['home_grade'] . "</td>"; echo "<td class='h5'>" . $row['game_result'] . "</td>"; echo "<td class='h5'><a href='gamehistory.php?name_URL=".$row['aname']."'>" . $row['aname'] . "</a></td>"; echo "<td class='h5'>" . $row['away_grade'] . "</td>"; echo "</tr>"; Is this what you meant? Apologies for my lack of knowledge, only started a few months ago with a couple of books on php and loads of hours watching you tube tutorials. Thanks again. John.
-
Hi WebStyles and thanks for your help, i think i have cracked it with your help, here is my code please let me know what you think- $result = mysql_query("SELECT * FROM members WHERE club='fen' ORDER BY `members`.`id` ASC"); while ($row = mysql_fetch_array($result)){ $percent = $row['played'] > 0 ? round($row['points']/$row['played']*100, 2) : 0; echo "<tr>"; echo "<td class='h5'>" . $row['id'] . "</td>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'><a href='gamehistory.php?name_URL=".$row['name']."'>" . $row['name'] . "</a></td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td class='h5'>" . $percent. "</td>"; echo "</tr>"; and the page the link goes to has this code- $name = $_GET['name_URL']; $result = mysql_query("SELECT * FROM scorecards WHERE name = '$name' OR aname = '$name'"); while ($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td class='h5'>" . $row['id'] . "</td>"; echo "<td class='h5'>" . $row['match_code'] . "</td>"; echo "<td class='h5'>" . $row['board_number'] . "</td>"; echo "<td class='h5'><a href='gamehistory.php?name_URL=".$row['name']."'>" . $row['name'] . "</a></td>"; echo "<td class='h5'>" . $row['home_grade'] . "</td>"; echo "<td class='h5'>" . $row['game_result'] . "</td>"; echo "<td class='h5'><a href='gamehistory.php?name_URL=".$row['aname']."'>" . $row['aname'] . "</a></td>"; echo "<td class='h5'>" . $row['away_grade'] . "</td>"; echo "</tr>"; } echo "</table>"; "name" is the home player and "aname" is the away player, the code is now taking out any games from the URL variable, at first i could not make it display games if the player was in the away field, is this a good way of doing this? Keep in mind that it needs to be simple for me to understand how it works. Also when i click on the links on the second page it displays the games played by the opponent which is what i wanted. Best wishes and thanks, John.
-
I would now like to try sending the name of a player to the next page and have all the chess games that this player has played show on the page, my code is- <?php include("includes/db_connect.php"); mysql_select_db($dbname, $con) or die ($dbname); echo " <tr> <td class='h5'>id</td> <td class='h5'>Ref</td> <td class='h5'>Name</td> <td class='h5'>grade</td> <td class='h5'>club</td> <td class='h5'>played</td> <td class='h5'>Won</td> <td class='h5'>Drawn</td> <td class='h5'>Lost</td> <td class='h5'>Points</td> <td class='h5'>%</td> </tr>"; $result = mysql_query("SELECT * FROM members WHERE club='fenton' ORDER BY `members`.`id` ASC"); while ($row = mysql_fetch_array($result)){ $percent = $row['played'] > 0 ? round($row['points']/$row['played']*100, 2) : 0; echo "<tr>"; echo "<td class='h5'>" . $row['id'] . "</td>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'><a href='gamehistory.php?lc_URL={$row['name']}'>" . $row['name'] . "</a></td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td class='h5'>" . $percent. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> gives the following URL-http://localhost/modsite_new/gamehistory.php?lc_URL=Bloggs Joe The code on the next page- <?php require("includes/db_connect.php"); mysql_select_db($dbname, $con) or die ($dbname); echo" <form action='gamehistory.php' method='get'> <p><input type='hidden' name='lc_URL' /></p> </form>"; $id = $_GET['lc_URL']; $result = mysql_query("select * FROM `scorecards` WHERE player = '$id'"); while ($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td class='h5'>" . $row['id'] . "</td>"; echo "<td class='h5'>" . $row['match_code'] . "</td>"; echo "<td class='h5'>" . $row['board_number'] . "</td>"; echo "<td class='h5'>" . $row['player'] . "</td>"; echo "<td class='h5'>" . $row['home_grade'] . "</td>"; echo "<td class='h5'>" . $row['game_result'] . "</td>"; echo "<td class='h5'>" . $row['aplayer'] . "</td>"; echo "<td class='h5'>" . $row['away_grade'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Can you see any reason why this doesn't show anything? Best wishes and thanks for all the help so far! John.
-
Wow thanks for all the replies, i will give your solution a try PHP blows my mind and there often so many ways of solving a problem, knowing which one is best is tough to find out if your novice. Once again many thanks for your speedy response, hope it works. Best wises, John.
-
I have a members.php page with following code- $result = mysql_query("SELECT * FROM members WHERE club='fent' ORDER BY `members`.`id` ASC"); while ($row = mysql_fetch_array($result)){ $percent = $row['played'] > 0 ? round($row['points']/$row['played']*100, 2) : 0; echo "<tr>"; echo "<td class='h5'><a href='gamehistory.php?lc_URL=".$row['id']."'>Games</a></td>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'>" . $row['name'] . "</td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td class='h5'>" . $percent. "</td>"; echo "</tr>"; I would like to make it so that i can click on the Games link and it go to gamehistory.php and using the id from the click make it display all the games this player has played from the database, can this be done? I'm a complete newbie and would appreciate any help, it took me several days of studying and watching videos on php to work out how to create the dynamic link on this page but im now stuck on what to put on gamehistory.php, also please let me know if i need to add anything to the above code to make it more secure. Best wishes, John.
-
Help please-Warning: Division by zero in C!
kingsbest replied to kingsbest's topic in PHP Coding Help
Thanks for breaking it down for me, you make it sound so simple and i think i found a website that might help me understand a little more at http://www.programmingvideotutorials.com/ thanks again, my next task is to build a league table with (chess) clubs, for a win they get 2 points and a draw 1 point, i also have to work out how to show them in order, with the team with the greatest points at the top and descending from there. I wasn't planning on using a CMS to update, i was just going to update using the mysql database, i thought that way would be more secure unless some one tells me otherwise. Best wishes, John. -
Help please-Warning: Division by zero in C!
kingsbest replied to kingsbest's topic in PHP Coding Help
Thanks that works great, are there any websites on-line that cover this area of php? Once again huge thanks for helping and all the best. John -
Help please-Warning: Division by zero in C!
kingsbest replied to kingsbest's topic in PHP Coding Help
Hi Shawn, I have spent several hours trying to put together something that works and no matter what i try it either supplies an error or it doesn't display the result the way i need it to display, would you mind creating the code so that i can simply copy/paste and i can finally move on? My most recent attempt looks like- <?php include("includes/db_conn.php"); echo "<table width='700'> <tr> <td class='h5'>ref</td> <td class='h5'>last</td> <td class='h5'>first</td> <td class='h5'>grade</td> <td class='h5'>club</td> <td class='h5'>played</td> <td class='h5'>Won</td> <td class='h5'>Drawn</td> <td class='h5'>Lost</td> <td class='h5'>Points</td> <td class='h5'>%</td> </tr>"; $result = mysql_query("SELECT * FROM members WHERE club='fen'"); while ($row = mysql_fetch_array($result)) { if($row['played'] > 0) $percent = round($row['points']/$row['played']*100, 2); echo "<tr>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'>" . $row['last_name'] . "</td>"; echo "<td class='h5'>" . $row['first_name'] . "</td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td>" . $percent. "</td>"; echo "</tr>"; } else { ($row['played'] < 1) echo "<tr>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'>" . $row['last_name'] . "</td>"; echo "<td class='h5'>" . $row['first_name'] . "</td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td></td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> i really wanted to try to solve this on my own as i thought it would help me understand how php works but i guess im not up to the task yet. i appreciate your help. Best wishes, John. -
Help please-Warning: Division by zero in C!
kingsbest replied to kingsbest's topic in PHP Coding Help
Thanks for your help Shawn, i think we are almost there, the amended code= <?php include("connect to database goes here"); echo "<table width='700'> <tr> <td class='h5'>ref</td> <td class='h5'>last</td> <td class='h5'>first</td> <td class='h5'>grade</td> <td class='h5'>club</td> <td class='h5'>played</td> <td class='h5'>Won</td> <td class='h5'>Drawn</td> <td class='h5'>Lost</td> <td class='h5'>Points</td> <td class='h5'>%</td> </tr>"; $result = mysql_query("SELECT * FROM members WHERE club='fen'"); while ($row = mysql_fetch_array($result)) { if($row['points'] > 0) { $percent = round($row['points']/$row['played']*100, 2); } echo "<tr>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'>" . $row['last_name'] . "</td>"; echo "<td class='h5'>" . $row['first_name'] . "</td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td>" . $percent. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> and displayed- ref last first grade club played Won Drawn Lost Points % 249 Smith John 162 Fen 3 2 1 0 2.5 83.33 266 Bloggs Stephen 112 Fen 0 0 0 0 0 83.33 262 Davies Philip 87 Fen 0 0 0 0 0 83.33 143 Jones Anthony 145 Fen 0 0 0 0 0 83.33 262 Thomas Stuart 98 Fen 0 0 0 0 0 83.33 Any idea how to fix this? Apologies for my lack of php knowledge. Best wishes, John. -
How do i make the equation $percent = round($row['points']/$row['played']*100, 2) ; not run if a player has not yet played a game and have it display 0 instead? echo "<table width='700'> <tr> <td class='h5'>ref</td> <td class='h5'>last</td> <td class='h5'>first</td> <td class='h5'>grade</td> <td class='h5'>club</td> <td class='h5'>played</td> <td class='h5'>Won</td> <td class='h5'>Drawn</td> <td class='h5'>Lost</td> <td class='h5'>Points</td> <td class='h5'>%</td> </tr>"; $result = mysql_query("SELECT * FROM members WHERE club='fen'"); while ($row = mysql_fetch_array($result)) { $percent = round($row['points']/$row['played']*100, 2) ; echo "<tr>"; echo "<td class='h5'>" . $row['ref'] . "</td>"; echo "<td class='h5'>" . $row['last_name'] . "</td>"; echo "<td class='h5'>" . $row['first_name'] . "</td>"; echo "<td class='h5'>" . $row['grade'] . "</td>"; echo "<td class='h5'>" . $row['club'] . "</td>"; echo "<td class='h5'>" . $row['played'] . "</td>"; echo "<td class='h5'>" . $row['won'] . "</td>"; echo "<td class='h5'>" . $row['drawn'] . "</td>"; echo "<td class='h5'>" . $row['lost'] . "</td>"; echo "<td class='h5'>" . $row['points'] . "</td>"; echo "<td>" . $percent. "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Example- 2632 Smith John 112 Fen 0 0 0 0 0 0 Best wishes, John.
-
Thanks to both wildteen88 and Insecure Its simply amazing and works, the world of php is mind blowing! Thank you!!! John
-
Thanks Insecure, I'm guessing i now leave points and percentage empty in my database, i then replaced my code with yours and got the following- Notice: Undefined variable: percentage in C:\wamp\www\Website\player_stats_test.php on line 107 Notice: Undefined variable: percentage in C:\wamp\www\Website\player_stats_test.php on line 107 ID Member Grade Played Won Drawn Lost Points &#37; 1 John Amison 142 13 1 10 2 2 Neal Davies 108 8 0 5 3 best wishes, John.
-
I have a table of members (18) with games played, won, drawn, lost and would like to know if its possible to have the points and percentage update automatically, example- ID Member Grade Played Won Drawn Lost Points % 1 Player name 142 13 1 10 2 6 46.15 My web-page is currently static and i go to http://math.about.com/library/weekly/aa061502a.htm fill in the games played and points and it gives the percentage, i have very little knowledge of php and by some miracle have managed to create a database using wamp and have extracted the data onto local host web page, my code as follows please let me know if i have any errors- <?php require "connect.inc.php"; echo "<table width='700'> <tr> <th></th> <th>Member</th> <th>Grade</th> <th>Played</th> <th>Won</th> <th>Drawn</th> <th>Lost</th> <th>Points</th> <th>%</th> </tr>"; $result = mysql_query("SELECT * FROM members"); while ($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['id'] . "</td>"; echo "<td>" . $row['member'] . "</td>"; echo "<td>" . $row['grade'] . "</td>"; echo "<td>" . $row['played'] . "</td>"; echo "<td>" . $row['won'] . "</td>"; echo "<td>" . $row['drawn'] . "</td>"; echo "<td>" . $row['lost'] . "</td>"; echo "<td>" . $row['points'] . "</td>"; echo "<td>" . $row['percentage'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> Please tell me how i can have the points and percentage update automatically and keep in mind im a novice with php. Best wishes, John
-
Hi im new here and new to php coding, i have creating a database for testing purposes using wamp, i want to publish the contents as follows- Player Grade Played Won Drawn Lost Points % J Bloggs 150 16 10 3 3 I then need the php to fill in the points total and the percentage, I think the formula is as follows- points formula- =won+0.5*drawn & formula- =Percentage/(won+drawn+lost)*100 the code i have put together is as follows- <?php $con = mysql_connect("localhost","root","passwordgoeshere"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fentonch_performancetable", $con); $result = mysql_query("SELECT * FROM playersperformance"); echo "<table width='650'> <tr> <td>Player</td> <td>Grade</td> <td>Played</td> <td>Won</td> <td>Drawn</td> <td>Lost</td> <td>Points</td> <td>%</td> </tr>"; while($row = mysql_fetch_array($result)) { $played = $row['Played']; if ($played>0) { $Points = ($row['Won'] + ($row['Drawn'] * 0.5)); $Percentage = ((($row['Won'] + ($row['Drawn'] * 0.5 )) / $played) * 100); mysql_query("UPDATE playersperformance SET Points = " & $Points & " AND Percentage = " & $Percentage & "WHERE Players = " & $row['Players']); } echo "<tr>"; echo "<td>" . $row['players'] . "</td>"; echo "<td>" . $row['grade'] . "</td>"; echo "<td>" . $row['played'] . "</td>"; echo "<td>" . $row['won'] . "</td>"; echo "<td>" . $row['drawn'] . "</td>"; echo "<td>" . $row['lost'] . "</td>"; echo "<td>" . $row['points'] . "</td>"; echo "<td>" . $row['percentage'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> The table appears but with a "0" in the points total and nothing in the percentage row, i also get the following lines- Notice: Undefined index: Played in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 25 Notice: Undefined index: players in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 34 Notice: Undefined index: percentage in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 41 Notice: Undefined index: Played in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 25 Notice: Undefined index: players in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 34 Notice: Undefined index: percentage in C:\wamp\www\chess_website\includes\playerstat_data_input.inc.php on line 41 Apologies if this is posted in the wrong place. Thanks!