phenner Posted April 3, 2010 Share Posted April 3, 2010 Hi Guys, I am trying to extract data from a database and place it in a table using PHP. When the user first loads the page they should be presented with a list of database records available for them to choose as links. They then click these links and the record is printed out on the page for them. This is not happening at the moment and I am really not sure why! Any chance someone can take a look please? My code is shown below: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Cricket Scorer - Live Scores</title> <style type="text/css"> <!-- body p { font-family: Verdana, Geneva, sans-serif; } .results { font-family: Verdana, Geneva, sans-serif; } .bold { font-family: Verdana, Geneva, sans-serif; font-weight: bold; } --> </style> </head> <body> <?php $username="root"; $password=""; $database="cricket"; mysql_connect(localhost,$username,$password); mysql_select_db($database) or die( "Unable to select database"); $scoresq = mysql_query("SELECT * FROM `scores`") or die(mysql_error()); $scoresa = mysql_fetch_array($scoresq); $teams = $scoresa['matchname']; list($team1name, $team2name) = split('[_]', $teams); $id = $_POST['id']; if(!isset($id)){ ?> <ul> <?php $x = 1; while($scoresb = mysql_fetch_array($scoresq)){ ?> <li><a href="index.php?id=<?php echo $x; ?>"><?php echo $scoresb['matchname'].'-'.$scoresb['date']; ?></a></li> <?php $x++; } ?> </ul> <?php } else{ $scoresqa = mysql_query("SELECT * FROM `scores` WHERE ID = '$id'") or die(mysql_error()); $scoresc = mysql_fetch_array($scoresqa); ?> <div class="bold"><?php echo $team1name; ?></div> <p>SCORE: <?php echo $scoresc['team1runs']; ?> for <?php echo $scoresc['team1wkts']; ?></p> <p>OVERS: <?php echo $scoresc['team1overs']; ?></p><br /> <table border="1"> <th class="results">No.</th> <th class="results">Name</th> <th class="results">How Out</th> <th class="results">Runs</th> <th class="results">Balls</th> <tr><td class="results">1</td> <td class="results"><?php echo $scoresc['team1bat1name']; ?></td> <td class="results"><?php echo $scoresc['team1bat1howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat1runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat1balls']; ?></td> </tr> <tr><td class="results">2</td> <td class="results"><?php echo $scoresc['team1bat2name']; ?></td> <td class="results"><?php echo $scoresc['team1bat2howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat2runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat2balls']; ?></td> </tr> <tr><td class="results">3</td> <td class="results"><?php echo $scoresc['team1bat3name']; ?></td> <td class="results"><?php echo $scoresc['team1bat3howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat3runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat3balls']; ?></td> </tr> <tr><td class="results">4</td> <td class="results"><?php echo $scoresc['team1bat4name']; ?></td> <td class="results"><?php echo $scoresc['team1bat4howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat4runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat4balls']; ?></td> </tr> <tr><td class="results">5</td> <td class="results"><?php echo $scoresc['team1bat5name']; ?></td> <td class="results"><?php echo $scoresc['team1bat5howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat5runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat5balls']; ?></td> </tr> <tr><td class="results">6</td> <td class="results"><?php echo $scoresc['team1bat6name']; ?></td> <td class="results"><?php echo $scoresc['team1bat6howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat6runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat6balls']; ?></td> </tr> <tr><td class="results">7</td> <td class="results"><?php echo $scoresc['team1bat7name']; ?></td> <td class="results"><?php echo $scoresc['team1bat7howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat7runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat7balls']; ?></td> </tr> <tr><td class="results">8</td> <td class="results"><?php echo $scoresc['team1bat8name']; ?></td> <td class="results"><?php echo $scoresc['team1bat8howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat8runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat8balls']; ?></td> </tr> <tr><td class="results">9</td> <td class="results"><?php echo $scoresc['team1bat9name']; ?></td> <td class="results"><?php echo $scoresc['team1bat9howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat9runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat9balls']; ?></td> </tr> <tr><td class="results">10</td> <td class="results"><?php echo $scoresc['team1bat10name']; ?></td> <td class="results"><?php echo $scoresc['team1bat10howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat10runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat10balls']; ?></td> </tr> <tr><td class="results">11</td> <td class="results"><?php echo $scoresc['team1bat11name']; ?></td> <td class="results"><?php echo $scoresc['team1bat11howout']; ?></td> <td class="results"><?php echo $scoresc['team1bat11runs']; ?></td> <td class="results"><?php echo $scoresc['team1bat11balls']; ?></td> </tr> </table> <br /><br /> <div class="bold"><?php echo $team2name; ?></div> <p>SCORE: <?php echo $scoresc['team2runs']; ?> for <?php echo $scoresc['team2wkts']; ?></p> <p>OVERS: <?php echo $scoresc['team2overs']; ?></p><br /> <table border="1"> <th class="results">No.</th> <th class="results">Name</th> <th class="results">How Out</th> <th class="results">Runs</th> <th class="results">Balls</th> <tr><td class="results">1</td> <td class="results"><?php echo $scoresc['team2bat1name']; ?></td> <td class="results"><?php echo $scoresc['team2bat1howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat1runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat1balls']; ?></td> </tr> <tr><td class="results">2</td> <td class="results"><?php echo $scoresc['team2bat2name']; ?></td> <td class="results"><?php echo $scoresc['team2bat2howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat2runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat2balls']; ?></td> </tr> <tr><td class="results">3</td> <td class="results"><?php echo $scoresc['team2bat3name']; ?></td> <td class="results"><?php echo $scoresc['team2bat3howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat3runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat3balls']; ?></td> </tr> <tr><td class="results">4</td> <td class="results"><?php echo $scoresc['team2bat4name']; ?></td> <td class="results"><?php echo $scoresc['team2bat4howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat4runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat4balls']; ?></td> </tr> <tr><td class="results">5</td> <td class="results"><?php echo $scoresc['team2bat5name']; ?></td> <td class="results"><?php echo $scoresc['team2bat5howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat5runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat5balls']; ?></td> </tr> <tr><td class="results">6</td> <td class="results"><?php echo $scoresc['team2bat6name']; ?></td> <td class="results"><?php echo $scoresc['team2bat6howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat6runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat6balls']; ?></td> </tr> <tr><td class="results">7</td> <td class="results"><?php echo $scoresc['team2bat7name']; ?></td> <td class="results"><?php echo $scoresc['team2bat7howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat7runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat7balls']; ?></td> </tr> <tr><td class="results">8</td> <td class="results"><?php echo $scoresc['team2bat8name']; ?></td> <td class="results"><?php echo $scoresc['team2bat8howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat8runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat8balls']; ?></td> </tr> <tr><td class="results">9</td> <td class="results"><?php echo $scoresc['team2bat9name']; ?></td> <td class="results"><?php echo $scoresc['team2bat9howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat9runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat9balls']; ?></td> </tr> <tr><td class="results">10</td> <td class="results"><?php echo $scoresc['team2bat10name']; ?></td> <td class="results"><?php echo $scoresc['team2bat10howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat10runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat10balls']; ?></td> </tr> <tr><td class="results">11</td> <td class="results"><?php echo $scoresc['team2bat11name']; ?></td> <td class="results"><?php echo $scoresc['team2bat11howout']; ?></td> <td class="results"><?php echo $scoresc['team2bat11runs']; ?></td> <td class="results"><?php echo $scoresc['team2bat11balls']; ?></td> </tr> </table> <?php } ?> </body> </html> Thanks! Link to comment https://forums.phpfreaks.com/topic/197465-database-table/ Share on other sites More sharing options...
phenner Posted April 3, 2010 Author Share Posted April 3, 2010 Just fixed one problem! Stupid me! $id = $_POST['id']; should read $id = $_GET['id']; That now allows the user to extract the particular record from the database, but the list is still not being printed :S Link to comment https://forums.phpfreaks.com/topic/197465-database-table/#findComment-1036445 Share on other sites More sharing options...
phenner Posted April 3, 2010 Author Share Posted April 3, 2010 I think the main problem is that it isn't going into the while-loop for some reason. Any ideas? Query seems ok to me :/ Link to comment https://forums.phpfreaks.com/topic/197465-database-table/#findComment-1036455 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.