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.
Modify sript that generates a table
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Modify sript that generates a table
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";
“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
Re: Modify sript that generates a table
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
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
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: Modify sript that generates a table
Try thisAlpal wrote:I can't work out what I need to replace "$field" with ???
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