Page 1 of 1

Modify sript that generates a table

Posted: Thu Feb 17, 2011 12:22 am
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.

Re: Modify sript that generates a table

Posted: Thu Feb 17, 2011 2:30 am
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.

Re: Modify sript that generates a table

Posted: Thu Feb 17, 2011 6:11 am
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

Re: Modify sript that generates a table

Posted: Thu Feb 17, 2011 11:37 am
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";
} ?>