Jump to content

laarchie

Members
  • Posts

    9
  • Joined

  • Last visited

laarchie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I have applied myself and read a bit more and came up with this code. Do you think this is better now? <div id="tablecontent"> <?php $query = "SELECT Players.FirstName, Players.Surname, Players.SchoolYear, Teams.TeamName, Statistics.MVP_Score ". "FROM Players, Teams, Statistics ". "WHERE Players.id = Statistics.id"; $result = mysql_query($query) or die(mysql_error()); ?> <table style="width:100%" > <tr> <td><strong>MVP Rankings</strong></td> </tr> <tr> <td><strong>First Name</strong></td> <td><strong>Surname</strong></td> <td><strong>Team</strong></td> <td><strong>School Year</strong></td> <td><strong>MVP Score</strong></td> </tr> <?php while($row = mysql_fetch_array($result)){ ?> <tr> <td><? echo $row['FirstName']; ?></td> <td><? echo $row['Surname']; ?></td> <td><? echo $row['TeamName']; ?></td> <td><? echo $row['SchoolYear']; ?></td> <td><? echo $row['MVP_Score']; ?></td> </tr> <?php // close while loop } ?> </table> <?php // close connection mysql_close(); ?>
  2. Thanks a lot for this answer. I do appreciate the problems in my algorithm. However, I am getting the output I do need and the IDs do work. It does make sense to use JOIN but I am not sure my knowledge will allow me to do this. Thanks, though, great response and very well explained.
  3. Hi guys. So far I have find the forum very helpful in getting started with my first project. I have one issue now which I am sure has come up before but in slightly different ways. I have got a PHP script that obtains data from MySQL and outputs it as a table in HTML. I need to make this table sortable, i.e. be able to click the headings and sort in asc/desc order. I have tried loads of Javascript codes I have found but none seem to work for my table. Here is the code for my script: <div id="tablecontent"> <?php //Obtain minimum id $sqlMinID = "SELECT MIN(id) as min_id FROM Players"; $resultminID = mysql_query($sqlMinID); $rows11 = mysql_fetch_array($resultminID); $minimumID = $rows11['min_id']; //Obtain maximum id $sqlMaxID = "SELECT MAX(id) as max_id FROM Players"; $resultmaxID = mysql_query($sqlMaxID); $rows12 = mysql_fetch_array($resultmaxID); $maximumID = $rows12['max_id']; $playerID = $minimumID; ?> <table id="mvp" style="width:100%"> <thead> <tr> <td><strong>Most Valuable Player</strong></td> </tr> <tr> <th><strong>Name</strong></th> <th><strong>Surname</strong></th> <th><strong>Team</strong></th> <th><strong>Year Group</strong></th> <th><strong>MVP Score</strong></th> </tr> </thead> <?php while ($playerID <= $maximumID){ $sqlFirstName = "SELECT `FirstName` FROM `Players` WHERE `id` = '$playerID'"; $resultName = mysql_query($sqlFirstName); $rows2 = mysql_fetch_array($resultName); $firstName = $rows2['FirstName']; $sqlSurname = "SELECT `Surname` FROM `Players` WHERE `id` = '$playerID'"; $resultSurname = mysql_query($sqlSurname); $rows3 = mysql_fetch_array($resultSurname); $surname = $rows3['Surname']; $sqlMVP = "SELECT MVP_Score FROM `Statistics` WHERE `id` = '$playerID'"; $resultMVP = mysql_query($sqlMVP); $rows4 = mysql_fetch_array($resultMVP); //MUST ADD TEAM FUNCTION ?> <tbody> <tr> <td><?php echo $firstName; ?></td> <td><?php echo $surname; ?></td> <td>NONE</td> <td>NONE</td> <td><?php echo $rows4['MVP_Score']; ?></td> </tr> <?php $playerID = $playerID + 1 ; // close while loop } ?> </tbody> </table> Can anyone point me in the right direction? Thanks in advance
  4. I guess I would have to include the form before that script?
  5. Chaps, as a beginner developing his first web app in PHP, I have done fairly well. However, I am struggling when it comes to validation. I have written different ELSEIF statements as seen below which would actually carry out the validation itself. // First name must be filled and in correct format. if(empty($FirstName)) { $errFirstName = '<p class="errText"> Please enter a value</p>'; echo $errFirstName; }elseif(!preg_match('/^[a-z]+$/i',$FirstName)){ $errFirstName = '<p class="errText">Name may not start with a dash. Letters, spaces and dashes are accepted.</p>'; echo $errFirstName; } The problem is that I do not know how to make them "pop up" when the user makes a mistake. I have a form in addteam.php seen below: <form action="pushteam.php" method="post"> <p>Team name: <input type="text" name="TeamName" /></p> <p>Description: </p> <p><textarea name="Description" rows="4" cols="50">Add your description here.</textarea></p> <p><input type="submit"/></p> </form> And a pushplayer.php script that pushes it to a mysql database: // Get values from form $TeamName=$_POST['TeamName']; $Description=$_POST['Description']; } // Insert data into database $sql="INSERT INTO Teams(TeamName, Description)VALUES('$TeamName', '$Description')"; $result=mysql_query($sql); //If successful return to success.php else print error if($result){ header( 'Location: success.php'); } else { header( 'Location: failure.php'); } The scripts function properly. I would really appreciate if someone could guide me in the right direction here. Make the error pop up and make sure the data is not input. At the moment, if I add my ELSEIF statements, it will carry on and insert the data anyway and redirect me. Thanks
  6. Thanks for the quick reply. At the moment I am brushing up my PHP skills on Codecademy as well as following the steps required by my coursework (SDLC). I have studied normalization so that should not be an issue. As for the algorithm that will actually perform the calculation I thought about doing it all in a spreadsheet first. So i can see how everything links together and tweak accordingly. To be fair, my project is just a fancy spreadsheet, the user would input scores and then obtain a ranking pretty much. Much appreciated, thanks.
  7. Hi there, I am a student from the UK and I am taking PHP and mySql programming for the first time. I have done a bit of python and html before. I do have some experience with PHP though. I need to create a project for my coursework. My system will be an MVP system (Cricket) where scores will be input and then MVP scores obtained. I wanted to know if anyone has any experience with this and thus could helpfully guide me in the right direction with resources and anything that could be deemed relevant. I am more than happy to explain further and send my prototype over. Many thanks.
×
×
  • 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.