Modify sript that generates a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alpal
Forum Commoner
Posts: 39
Joined: Mon Jul 26, 2010 4:08 am

Modify sript that generates a table

Post by Alpal »

Have this script that generates a table with the results of a query.

<?php

$query = "SELECT team_grade, day_played, COUNT(team_grade) FROM Team_entries GROUP BY team_grade ORDER BY day_played" ;

$result = mysql_query($query) or die(mysql_error());
{
$num_rows = mysql_num_rows($result);

print "<table width=600 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
echo "<td>ladder</td>";
print "</tr>\n";

}
print "</table>\n";
}
?>


Have added this line to the script
echo "<td>ladder</td>";
it adds another column to the table, with the text "ladder"in it, that is what I want to do

Problem, how can I create a link from the text "Ladder" to a detail page eg. <a href="detailfile.php?ladder=<?php echo $row_Team_entries['team_grade']; ?">

Do not have a good understanding of php, but I am a tryer !! Any help would be greatly appreciated.
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Modify sript that generates a table

Post by social_experiment »

Code: Select all

print "<table width=600 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
echo "<td>ladder</td>";
// add this line
echo '<td><a href="detailfile.php?ladder='. $field .'">Ladder</a></td>';
print "</tr>\n";
Since you are already using php this part <?php echo $row_Team_entries['team_grade']; ?"> is not necessary. I don't use mysql_fetch_row() much so I'm not sure what the value of $field will be in this case, the one in the the query string of the link.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Alpal
Forum Commoner
Posts: 39
Joined: Mon Jul 26, 2010 4:08 am

Re: Modify sript that generates a table

Post by Alpal »

Thankyou, yes that works.
Problem - it is passing the value of the count, I want it to pass the value of "team_grade" in that row of the table
I can't work out what I need to replace "$field" with ???

Current Script

<?php

$query = "SELECT team_grade, day_played, COUNT(team_grade) FROM Team_entries GROUP BY team_grade ORDER BY day_played" ;

$result = mysql_query($query) or die(mysql_error());
{

$num_rows = mysql_num_rows($result);

print "<table width=600 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td>$field</td>\n";
echo '<td><a href="Ladders_S1.php?ladder='. $field .'">Ladder</a></td>';
print "</tr>\n";

}
print "</table>\n";
}
?>

Thanks again, appreciate any further assistance
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Modify sript that generates a table

Post by social_experiment »

Alpal wrote:I can't work out what I need to replace "$field" with ???
Try this

Code: Select all

<?php
 while ($get_info = mysql_fetch_row($result)){
 print "<tr>\n";
  // what value does $field represent here? 
 print "\t<td>$field[1]</td>\n";
 // first index in the array is 0
 echo '<td><a href="Ladders_S1.php?ladder='. $field[0] .'">Ladder</a></td>';
 print "</tr>\n";
} ?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply