Ravens PHP Scripts: Forums
 

 

View next topic
View previous topic
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules
Author Message
daftandhungry
New Member
New Member



Joined: Dec 30, 2008
Posts: 14

PostPosted: Sat Jan 24, 2009 2:27 am Reply with quote

Hi all.

I am trying to create a sports tipping module as I have been unable to find any that I could either use or modify.

What I am trying to achieve:
Teams, venues, rounds, dates and times all in the database.
Admin page to enter matches in rounds as the information becomes available (the season isn't completely drawn yet)
Page displaying matches with selection between two teams for each match for each round (roughly 8 matches per round and 26 rounds per season excluding finals, state and international matches)
Submission of tips for each match of each round in the same page as the matches are displayed
Results page showing match results, the users tipping results and tipping leaderboard.

I don't want this written for me my goal is to produce it myself and learn along the way, but I would appreciate some help at times if anyone is willing.

*Edited as I have made progress overnight.

ok got tips submission working for a single match with
Code:


<?php

if (!eregi("modules.php", $PHP_SELF)) {
  die ("You can't access this file directly...");
}

define('INDEX_FILE', true);
require_once("mainfile.php");
$module_name = basename(dirname(__FILE__));
get_lang($module_name);

include('header.php');
OpenTable();
if (is_user($user)) {
   getusrinfo($user);
   $username = $userinfo['username'];
$roundsql = 'SELECT RoundID, RoundName FROM ' . $prefix . '_nrl_rounds WHERE RoundID = 1';
$resultround = $db->sql_query($roundsql);
while ($row = $db->sql_fetchrow($resultround)) {
$round = $row['RoundName'];
}
echo '<center>';
echo '<form method="post" action="">';
echo "Welcome to NRL Tipping for the 2009 season $username. Enter your tips for $round below.";
$matchsql = 'SELECT MatchID, HomeTeam, AwayTeam, VenueName, GameDate, StartTime, RoundID FROM ' . $prefix . '_nrl_matches WHERE RoundID = 1 ORDER BY MatchID ASC';
$resultmatch = $db->sql_query($matchsql);
while ($row = $db->sql_fetchrow($resultmatch)) {
$round = $row['RoundID'];
$mid = $row['MatchID'];
$home = $row['HomeTeam'];
$away = $row['AwayTeam'];
echo '<br /><br />';
echo '<table style="background-color:#eeeeee; border:1px; border-style:solid; border-color:#000000";>';
echo '<tr>';
echo '<th>Home Team</th><th>Away Team</th><th>Venue</th><th>Date</th><th>Time</th><th>Select Team</th>';
echo '</tr>';
echo '<tr style="background-color:#C0C0C0; border:1px; border-style:solid; border-color:#000000";>';
echo '<td>';
echo $row['HomeTeam'];
echo '</td>';
echo '<td>';
echo $row['AwayTeam'];
echo '</td>';
echo '<td>';
echo $row['VenueName'];
echo '</td>';
echo '<td>';
echo $row['GameDate'];
echo '</td>';
echo '<td>';
echo $row['StartTime'];
echo '</td>';
echo '<td>';
echo '<select name="gametip">';
echo "<option value=\"$row[HomeTeam]\">$row[HomeTeam]</option>";
echo "<option value=\"$row[AwayTeam]\">$row[AwayTeam]</option>";
echo '</select>';
echo '</td>';
echo '</tr>';
echo '</table>';
echo '<br /><br />';
}
echo "<input type=\"hidden\" name=\"username\" value=\"$username\">";
echo "<input type=\"hidden\" name=\"Round\" value=\"$round\">";
echo "<input type=\"hidden\" name=\"Match\" value=\"$mid\">";
echo '<input type="submit" value="Submit Tips" name="Submit">';
echo '</form>';
if(isset($_POST['Submit']))
{
$tip = $_POST['gametip'];
$u = $_POST['username'];
$rid = $_POST['Round'];
$match = $_POST['Match'];

$db->sql_query("insert into nuke_nrl_tips(TipID, TipperName, TeamName, RoundID, MatchID) values('null', '$u', '$tip', '$rid', '$match')");

echo "Thank you $username. Your Tips have been submitted.<br />";
#echo "$home VS $away : You chose $tip.<br />";
echo 'Good Luck!';
}
}else {
 echo '<center>Sorry you must be logged in to enter the tipping competition!<br /><br /><a href="modules.php?name=Your_Account&op=New_User">Signup</a>&nbsp;<b>|:.&nbsp;&nbsp;.:|</b>&nbsp;<a href="modules.php?name=Your_Account">Login</a></center>';
}

CloseTable();
include('footer.php');
?>


and passing variables through forms but when I change WHERE MatchID = 1 to WHERE RoundID = 1 to list all games in the round the submission only enters the last tip into the database.

Could someone point me in the right direction to insert multiple rows i.e a row for each game listed from the select - loop or array or something or will I have to create a select statement for each game in the round and pass different variables through a form for each game?

* Included screenshot of four of the eight matches as displayed in the page
Image

Thanks,
Scott.


Last edited by daftandhungry on Sun Jan 25, 2009 4:48 am; edited 2 times in total 
View user's profile Send private message
Raven
Site Admin/Owner



Joined: Aug 27, 2002
Posts: 17088

PostPosted: Sun Jan 25, 2009 3:15 am Reply with quote

Scott,

I just caught up with this but I'm also heading into bed as it's very late or earl depending where you live Wink. If no one has answered you by the time I'm up and back on the forums I'll see if I can help you!
 
View user's profile Send private message
daftandhungry







PostPosted: Sun Jan 25, 2009 4:23 am Reply with quote

Thanks Raven, looking forward to it, spent about 5 hrs today trying loops and arrays with no real luck, probably just down to my beginner coding skills and no doubt messy code to begin with.

From what I have been reading I am pretty sure I have to use some sort of foreach loop but I can't seem to make it work, I had the last tip chosen insert on multiple rows, all I got was more and more confused lol.

So I moved on to form validation so people could only enter tips once and died there too Bang Head

Still I'll keep trying
 
Raven







PostPosted: Sun Jan 25, 2009 9:43 pm Reply with quote

Laughing - Right off the bat you have a problem with this code:

while ($row = $db->sql_fetchrow($resultround)) {
$round = $row['RoundName'];
}

That does loop through the table but it just keeps resetting the same variable $round. So, it will end up as the last record of the table.

After that I get confused in your code because it doesn't make sense to me w/o seeing/understanding the data in the table.
 
daftandhungry







PostPosted: Sun Jan 25, 2009 10:55 pm Reply with quote

ok quick overview.

(Tables)
Teams - TeamID, TeamName
Venues - VenueID, VenueName
Rounds - RoundID, RoundName
Matches - MatchID, HomeTeam, AwayTeam, GameDate, StartTime, RoundID
Tips - TipperName, TeamName, RoundID, MatchID
Image
Image
Image

*ID field in each table is primary key-auto increment
the rest varchar apart from gamedate and starttime.
Teams, Venues, Rounds are all populated through sql imports, Matches is populated through an admin form I made with select lists and text fields.

The fetchrow you posted is just a select so I can echo what round it is on the page using $round later on.

$roundsql = 'SELECT RoundID, RoundName FROM ' . $prefix . '_nrl_rounds WHERE RoundID = 1';
$resultround = $db->sql_query($roundsql);
while ($row = $db->sql_fetchrow($resultround)) {
$round = $row['RoundName'];
}
echo '<center>';
echo '<form method="post" action="">';
echo "Welcome to NRL Tipping for the 2009 season $username. Enter your tips for $round below.";

It is the form section I am having the trouble with.
The form pulls each match in a round from the matches table using the select statement

$matchsql = 'SELECT MatchID, HomeTeam, AwayTeam, VenueName, GameDate, StartTime, RoundID FROM ' . $prefix . '_nrl_matches WHERE RoundID = 1 ORDER BY MatchID ASC';
$resultmatch = $db->sql_query($matchsql);
while ($row = $db->sql_fetchrow($resultmatch)) {
$round = $row['RoundID'];
$mid = $row['MatchID'];
$home = $row['HomeTeam'];
$away = $row['AwayTeam'];


The form and queries make up the tables I posted the picture of with 1 submit button at the end of the form (there are 8 tables in the page but my screenshot only shows the bottom four).

$matchsql = 'SELECT MatchID, HomeTeam, AwayTeam, VenueName, GameDate, StartTime, RoundID FROM ' . $prefix . '_nrl_matches WHERE RoundID = 1 ORDER BY MatchID ASC';

allows me to list all of the matches in round 1 in a separate table each with a selection between the two teams that are playing, but I can't work out how to insert each selection into a new row in the tips table at the same time, I can however make it work only 1 game at a time with

$matchsql = 'SELECT MatchID, HomeTeam, AwayTeam, VenueName, GameDate, StartTime, RoundID FROM ' . $prefix . '_nrl_matches WHERE MatchID = 1 ';
Image

It inserts the tipID, TipperName (from $username variable created before the form), RoundID and MatchID correctly whereas RoundID=1 will only insert the last tip into the table.

But then I would have to create a select statement and form for each game in the round I think.
I'm not sure I am still very new to this.
 
Raven







PostPosted: Mon Jan 26, 2009 1:23 am Reply with quote

Are you familiar with JOINS? I think you need to get a book or 2 on MySQL or take some beginning tutorials on line and really get some background.
 
testy1
Involved
Involved



Joined: Apr 06, 2008
Posts: 484

PostPosted: Mon Jan 26, 2009 2:19 am Reply with quote

package it up (including the database) and Ill try and help.

but Ill only work on the parts with the bronco's Razz
 
View user's profile Send private message
daftandhungry







PostPosted: Mon Jan 26, 2009 4:37 am Reply with quote

I'm not very familiar with joins as my php and sql knowledge is limited to only things I have attempted in the past. I haven't done anything with websites for about 4 years since I last used nuke and even then it wasn't much.

I do tend to dive straight into the deep end as you can no doubt tell.
But one way or another I will pull it off eventually even if it is for the 2010 season lol.
I agree with you completely that I need more knowledge, but I like to try things and learn along the way and I may as well learn by attempting to create something I can use.
Besides it keeps me occupied, much to my wifes dismay - countless hours on the computer.

Sure thing testy i'll zip up what I have done so far, the sql files for the tables and data - I have the draw for the first 5 rounds, but I have only inserted the first round so far, i'll also throw in a description of what I am trying to achieve.

If you do do anything with it, could you please add comments so I can try to grasp what you have done and learn something from it.

Broncos hey... I live in NSW now but born and bred in brissy, curious to see how they go this year without Bennett.

File can be found at http://www.clanpostal.com/NRLTIPS.zip

Thanks for your replies guys.
I'm off to read more about loops.
 
Display posts from previous:       
Post new topic   Reply to topic    Ravens PHP Scripts And Web Hosting Forum Index -> Converting/Creating Modules

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2007 phpBB Group
All times are GMT - 6 Hours
 
Forums ©