Jump to content

grrraaagh

Members
  • Posts

    13
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

grrraaagh's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Triumphantly, i declare that the solution to the problem is as follows; <html><body> TABLES TEST<BR> <H3>Group A</H3> <?php $conn=mysql_connect("localhost", "server", "password") or die ("could not connect"); $rs=mysql_select_db("database", $conn)or die ("could not connect to database"); $sql=stripslashes("SELECT `stage`,`team`,`p`,`pts`,`w`,`d`,`l`,`gf`,`ga`, (gf - ga) AS 'gd' FROM `lgtables` WHERE `stage` LIKE 'GP A' ORDER BY 'pts' desc, 'gd' desc"); $rs=mysql_query($sql,$conn) or die("could not execute query because ".mysql_error()); $list="<table border=\"1\" cellpadding=\"2\">"; $list.="<tr><th>Team</th>"; $list.="<th>P</th>"; $list.="<th>PTS</th>"; $list.="<th>W</th>"; $list.="<th>D</th>"; $list.="<th>L</th>"; $list.="<th>GF</th>"; $list.="<th>GA</th>"; $list.="<th>GD</th></tr>"; $counter = 1; while($row=mysql_fetch_array($rs)) { switch($counter++) { case 1: case 2: $color = '#ffcc99'; break; case 3: case 4: $color = '#ffcc66'; break; default: $color = '#ffffff'; } $list.="<tr style='background-color: $color'>"; $list.="<td><b>".$row["team"]."</b></td>"; $list.="<td><center><b>".$row["p"]."</b></center></td>"; $list.="<td><center><b>".$row["pts"]."</b></center></td>"; $list.="<td><center>".$row["w"]."</center></td>"; $list.="<td><center>".$row["d"]."</center></td>"; $list.="<td><center>".$row["l"]."</center></td>"; $list.="<td><center>".$row["gf"]."</center></td>"; $list.="<td><center>".$row["ga"]."</center></td>"; $list.="<td><center><b>".$row["gd"]."</b></center></td>"; $list.="</tr>"; } $list.="</table>"; echo($list); ?> </body></html>
  2. Your reply looked really promising, and gave me food for thought in trying new angles on the problem. The logic of it reads to me - a novice - as seeming to be just the job. Unfortunately, upon trying your solution it just offered up the table headings with a white background. I then inserted a section of code that was removed from your sample namely, while($row=mysql_fetch_array($rs)) { as it threw me that your code slotted straight between the two Slist sections. However, i was obviously wrong in adding that as i received an error stating 'Parse error: parse error, unexpected $ in ...... on line 45 '
  3. Please note this is not the frequent 'how do i colour rows alternately' question that you see across the internet. Upon displaying a sports league table i wish for the top two rows to have a certain background colour. The next two rows to be a different shade again. This would help highlight, for instance, that the top two teams qualify direct to the finals of a coompetition, whilst the third and fourth placed teams go into a play-off match for the third qualifying slot. The rest of the table would just be the default colour (white). I've Googled for hours and exhaustively tried every function i could find, all without success. <html><body> TABLES TEST<BR> <H3>Group A</H3> <?php $conn=mysql_connect("localhost", "server", "password") or die ("could not connect"); $rs=mysql_select_db("database", $conn)or die ("could not connect to database"); $sql=stripslashes("SELECT `stage`,`team`,`p`,`pts`,`w`,`d`,`l`,`gf`,`ga`, (gf - ga) AS 'gd' FROM `lgtables` WHERE `stage` LIKE 'GP A' ORDER BY 'pts' desc, 'gd' desc"); $rs=mysql_query($sql,$conn) or die("could not execute query because ".mysql_error()); $list="<table border=\"1\" cellpadding=\"2\">"; $list.="<tr><th>Team</th>"; $list.="<th>P</th>"; $list.="<th>PTS</th>"; $list.="<th>W</th>"; $list.="<th>D</th>"; $list.="<th>L</th>"; $list.="<th>GF</th>"; $list.="<th>GA</th>"; $list.="<th>GD</th></tr>"; while($row=mysql_fetch_array($rs)) { $list.="<tr bgcolor=\"#ffcc99\">"; $list.="<td><b>".$row["team"]."</b></td>"; $list.="<td><center><b>".$row["p"]."</b></center></td>"; $list.="<td><center><b>".$row["pts"]."</b></center></td>"; $list.="<td><center>".$row["w"]."</center></td>"; $list.="<td><center>".$row["d"]."</center></td>"; $list.="<td><center>".$row["l"]."</center></td>"; $list.="<td><center>".$row["gf"]."</center></td>"; $list.="<td><center>".$row["ga"]."</center></td>"; $list.="<td><center><b>".$row["gd"]."</b></center></td>"; $list.="</tr>"; } $list.="</table>"; echo($list); ?> </body></html> I've tried various formulas around firstly stating that $row_color1 = "#ffcc99"; $row_color2 = "#ffcc66"; Thereafter, i've tried a bewildering array of tailoring suggestions for 'alternate rows' from the internet. These have used $row_count, $mysql_num_rows, 'if' statements, 'else if' statements etc. I finally gave up when the 'mysql_if_this_does_not_work_i'll_jump_off_a_very_high_building' function also failed to work.
  4. [code]My basic codes are as follows. To select a team i enter the name, or for speed the first few letters (cze is less laborious that czechoslovakia), into a form interface on a web page. All quite simple with; [code]<form action="getgames.php" method="get"><input type="submit" name="submit" value="SELECT"></form> This targets the following script; <?php $conn=@mysql_connect("localhost", "database", "password") or die("could not connect"); $rs=@mysql_select_db("database_name", $conn) or die("could not connect to database"); $sql=stripslashes ("select match_id, home_team, away_team, result, report FROM worldcup WHERE home_team = '%$tm%' OR away_team = '%$tm%'"); $rs=mysql_query($sql, $conn) or die("could not execute query because ".mysql_error()); $list="<table border=\"1\" cellpadding=\"2\">"; $list.="<tr><td><center><b></b></center></td></tr>"; $list.="<tr><td></td></tr>"; while($row=mysql_fetch_array($rs)) { $list.="<tr>"; $list.="<td bgcolor=\"#ffcc99\"><center><b><u>".$row["match_id"]."</u></b></center></td>"; $list.="<td bgcolor=\"#ffcc99\"><center><b><u>".$row["home_team"]."</u></b></center></td>"; $list.="<td bgcolor=\"#ffcc99\"><center><b><u>".$row["away_team"]."</u></b></center></td>"; $list.="<td bgcolor=\"#ffcc99\"><center><b><u>".$row["result"]."</u></b></center></td>"; $list.="<td bgcolor=\"#ffcc99\"><center><b><u>".$row["report"]."</u></b></center></td>"; $list.="</tr>"; } $list.="</table>"; echo($list); ?> This will then produce a table with rows containing the data eg.; 1267 England Germany 2-0 Report 1389 Russia England 1-3 Report 1897 England Scotland 3-2 Report When finished in the future i will have the id number 'hidden'. When the table is initially displayed the last cell in each row just shows the word 'Report'. Once clicked on - in a separate window - it would bring up the detailed match report.I am stuck on the placement and syntax of the coding required to do the aforementioned task. At the moment, in every row of my database in the field 'report', I have been trying various forms of syntax. I have only succeeded in getting a code which brings up ALL reports available in the DB, as opposed to the selected search parameters. I've got the basic operating of the 'Report' button working in that it will 'action' on a script and get the MySql statement to operate. Therefore, is the sticking point simply my wording of the MySql syntax - crucially - the reference of the rows id?. In the script below i have put question marks at the point where i think it's all going wrong. This is the start of the script that the 'Report' button utilises, it attempts to display the previously undisplayed field of 'match_report' (this i have assigned as mediumtext, whether text will suffice i'm not sure); <?php $conn=@mysql_connect("localhost", "database", "password") or die("could not connect"); $rs=@mysql_select_db("database_name", $conn) or die("could not connect to database"); $sql=stripslashes ("SELECT match_report FROM worldcup WHERE ?????"); $rs=mysql_query($sql, $conn) or die("could not execute query because ".mysql_error()); ....... ?> Hopefully, the above makes it a little clearer that the previously prevailing mud.[/code][/code]
  5. I realise it's a lame cowardly way to accede defeat, but i need to get this database working very soon now. I had come so close to sorting the matter out. However, my brain has bled so heavily that, i am now so punch drunk, i 'm losing grasp of basic syntax and coding.I have designed really interactive databases in the past where i can search for a term which throws up several records that contain it. I can then (all via a web page interface) update/edit/replace/insert data to my hearts content.I have engineered 'live' editing windows and all sorts of goodies.They are far better to use than the ones provided by my website host. They do more, clearer and faster than their interface. I can insert multiple records and alter swathes of data at a single stroke. But, i'm so frustrated and bewildered trying to sort out this 'simple' task that i'm totally at sea with the basics. It's not helped by the fact i was away from, messing about with, coding for quite a while. Just as i was starting to make sense of what i had self-taught myself. So ! in order that i can find an easier solution to the problem, i'll put all data in a single BIG table - forget the demonic Join's and Last ID() etc. In an effort to ellicit some help, i will strip the field down to a minimum for example purposes. Here goes, please someone help if they can. I have a table that has the following fields Home_Team, Away_Team, Result, Report. When i enter a search for a team in the web page interface i want it to produce rows containing only the Home_Team, Away_Team & Result fields/columns At the end of each row/record i further wish to have displayed a submit button. Upon pressing this, it will open in a new window the contents of the Report field for the match referred to in that same row. I see this done all over the web, virtually on every sports site if you click on the result of a match it brings up the match report. To make things as simple as possible, i am no longer keeping the reports in a separate table. I have no problem scripting the submit button to display ALL reports upon clicking it. However, i'm so dizzy, i've lost all track of how (and where) to phrase the mysql statement so that it only selects rows with conditions attached. I can't for the life of me figure out where what (mysql/php/html statements) go where in relation to the DB fields,form fields and web page scripts. Many thanks in advance of help.
  6. The solution to the problem posed lay in LAST_INSERT_ID( ). I'll explain further as soon as possible, i'm finished for the night. I've still got a a couple of things to do with general interacting with the db via a web page. By the way, i hope others will eventually be able to benefit from my talking to myself throughout this thread
  7. I've made - to me - some amazing progress on this problem. I've now just two things to sort out, one of them is possibly relatively easy to sort. However, i still need help on one matter. Is there any way of automatically inserting the auto-incremented id into both tables at the same time?. By that i mean, when i insert a new record into the main table and enter data into the various fields, can i get it to automatically generate a (initially empty) record with the same id into the report tables. To clarify further; if my new record in the main table automatically generates the auto-incremented id of '216', can i get it to create a record in the other table with the same id of '216' (the contents of the field in this table will initially be empty and added to a day later) ?. Hopefully, someone can please assist with this. I have slaved away for hours in getting the 'joins' to work (for now) to a certain degree.
  8. A further complication/hurdle to cross is that, i would be adding the report contents at a later date than the initial fields. Therefore, how do i ensure that the id for the record in both tables is the same? By that i mean, i need to trigger the creation of the report field at the time of entering all the original (other) fields. This report field will be empty until a day or so later. I can't figure out how to assign an id (auto-increment) for a record to cover two different tables. I can't create a manual id every time i make a new record. It would be too time-consuming, so i need an auto-increment to do it automatically. My key task - to me - seems (wrongly???) to enable a (HTML?) link to my second tables entries. This second tables entries would have the same id for the match record in the main table. During use of my database (via a web page) i would search for a team's games. I would then have on display the venue, date score etc. At the end of each of the displayed rows there would be a clickable link that will bring up in a separate window or frame the match report.
  9. I've cross posted whilst editing my original query to make it clearer. I'll try and get my head around your suggestion but i'm a little lost on the use of so many AS's. I guess i'm about to put a lot of study time into LEFT JOIN etc.
  10. I wish to have two tables in a database. The rows/records on the second table will consist of a column for ID and a text (blob???) column containing a football match report. The main table will have in each row fields for ID, competition, round, venue, date, home team ranking, away team ranking, home team, away team, result, and then ideally the final field will be a link to the match report. This should when clicked open up in either a separate window/floating window or frame. Basically, if i enter a search for a particular team, the main table will show all the matches they have played in on a row by row basis. But, i would only want a match report to display when i click on the link. Please can anyone let me know how i can achieve this?. I've Googled away relentlessly after exhausting all efforts of my own. I would have thought this is far from a rare function to be needed. Many thanks in advance of assistance.
  11. I couldn't get that to work as it gave zero's again. I was about to leave it for now, but decided to persevere for a few minutes longer. I replaced the word 'calc' with the actual name of the column in the table 'pts'. Was i expected to do that as a matter of course? (i did warn you i have some massive gaps in my basic use of code and syntax). I added the stripslashes, and subsequently required, parentheses. Also, as i was testing it on old NHL tables i took the chance of inserting extra fields in the calculation. The following worked to perfection, $sql=stripslashes("SELECT standings.*, w*2 + t + ol AS pts FROM standings ORDER BY pts desc, w desc"); I was even more amazed to be able to add within it a 'where' clause. This enables me to present various subtables on the page. By that i mean i can have League, Conference and Division tables automatically churned out. $sql=stripslashes("SELECT standings.*, w*2 + t + ol AS pts FROM standings where c like 'e' ORDER BY pts desc, w desc"); MANY, MANY THANKS for your help. You can see the test results on this webpage All Tables At-A-Glance Incidentally on that page, during the season, i have next to each of the current tables a 'projected' table. This is because in the NHL you can often have a wide difference in the number of matches a team has played at any given moment. So, i divide the amount of points gained by the number of games played, and then multiply by 82. This gives me the total number of points that a team would amass after all teams would have played the same amount of fixtures. I find it helps one to vizualise where a team is heading, as each year roughly the same points assure division titles and play-off berths. Obviously my next task is to work out how to get that to happen within the framework of the code that you gave me for my original problem. I certainly look forward to trying to work it out now that i am on firmer ground. Thanks again. Incidentally, when i was Googling for a solution before using the forum, i noticed many others requiring a solution to the problem i posed.
  12. Sorry if this is a stupid answer to your question. I wish the table to appear when i go to the webpage that it is on. This is the script that i am presently using which produces the table on the webpage. As i say, the only problem is that i have to manually calculate the points total for each team and then type them in within the database admin interface. <?php $conn=@mysql_connect("localhost", "user", "password") or die("could not connect"); $rs=@mysql_select_db("database", $conn) or die("could not connect to database"); ?> <tr> <td valign=top width="50%"> <h3><a name="all"><font color="#ff0000">ALL TEAMS</font></a></h3> <?php $sql=stripslashes ("select * from standings order by pts desc, w desc"); $rs=mysql_query($sql, $conn) or die("could not execute query because ".mysql_error()); $list="<table border=\"1\" cellpadding=\"2\">"; $list.="<tr><th>C</th>"; $list.="<th>LG</th>"; $list.="<th>TEAM</th>"; $list.="<th>P</th>"; $list.="<th>W</th>"; $list.="<th>L</th>"; $list.="<th>T</th>"; $list.="<th>OL</th>"; $list.="<th>GF</th>"; $list.="<th>GA</th>"; $list.="<th>PTS</th></tr>"; while($row=mysql_fetch_array($rs)) { $list.="<tr>"; $list.="<td>".$row["c"]."</td>"; $list.="<td>".$row["lg"]."</td>"; $list.="<td>".$row["team"]."</td>"; $list.="<td>".$row["p"]."</td>"; $list.="<td>".$row["w"]."</td>"; $list.="<td>".$row["l"]."</td>"; $list.="<td>".$row["t"]."</td>"; $list.="<td>".$row["ol"]."</td>"; $list.="<td>".$row["gf"]."</td>"; $list.="<td>".$row["ga"]."</td>"; $list.="<td>".$row["pts"]."</td>"; $list.="</tr>"; } $list.="</table>"; echo($list); ?> </td>
  13. Hi, Please forgive me for any laughable questions i pose, i am a relative newcomer to any sort of coding. Although i'm not totally ignorant of such things, as it only took me a couple of minutes of trial and error to work out how to have a formula do what i wished in Excel and Microsoft works. However, i have spent hours of frustration trying to get php and mysql to do what i would consider is a relatively simple task for even the most basic of computer programmes. I was relieved recently when i - hopefully correctly - gathered that it was not actually possible until the recent addition of Triggers to attain my wish. All i want to do, which took minutes to arrange in Excel, Microsoft Works and on a stand-alone PHP page is to be able to publish a sports league table whereby the points total for a team is automatically calculated. For example if you gain 3 points for a win and one for a draw a formula similar to pts = w*3 + d works on everything else i have tried. I've spent ages again trying to get the new triggers to work on this and i can't. I don't know if it is because of basic syntax mistakes, or just as likely the wrong placement of it, or indeed whether it is yet another dead end for my hopes in that the code will not accomplish what i want to do. I'm now at such a confused state i can't even figure out what goes where within the scripts on the webpage that creates the table and within the database fields. I've always praised and promoted both MySql and PHP, but am ready to abndon them altogether if i'm unable to achieve such a simple task. I don't know if it is my own denseness at being unable to grasp the terminology within the documentation as a newcomer that is the problem. Please could someone help me with my simple aim of having the points column in a sports table automatically generate it's total from the fields of wins and draws. I don't have any problems with a PHP form page where i enter into it the played, won, drawn, and lost fields, and then upon pressing the submit button it returns with an additional column of the computed points total. Why can't i get PHP and MySql database to produce the same?. I am using PHP 5.0.2 and MySql 5.0
×
×
  • 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.