I have been working on this problem for the last 2 days and have not been able to figure it out!
I am trying to take data received from a form that is saved in my MySQL database and display it on another page using html.
Here is the first php script (get_data_picks.php) I use to pull my data from the database:
<?php
// open the connection
$conn = mysql_connect("host","database","password");
// pick the database to use
mysql_select_db("database",$conn);
// create the SQL statement
$sql = "SELECT * FROM wkly_forms WHERE (week = '01')";
// execute the SQL statement
$result = mysql_query($sql, $conn) or die(mysql_error());
//go through each row in the result set and get data
while ($newArray = mysql_fetch_array($result)) {
// give a name to the fields
$wkly_forms_name = $newArray['name'];
$wkly_forms_gm_01 = $newArray['gm_01'];
$wkly_forms_gm_02 = $newArray['gm_02'];
$wkly_forms_gm_03 = $newArray['gm_03'];
$wkly_forms_gm_04 = $newArray['gm_04'];
$wkly_forms_gm_05 = $newArray['gm_05'];
$wkly_forms_gm_06 = $newArray['gm_06'];
$wkly_forms_gm_07 = $newArray['gm_07'];
$wkly_forms_gm_08 = $newArray['gm_08'];
$wkly_forms_gm_09 = $newArray['gm_09'];
$wkly_forms_gm_10 = $newArray['gm_10'];
$wkly_forms_gm_11 = $newArray['gm_11'];
$wkly_forms_gm_12 = $newArray['gm_12'];
$wkly_forms_gm_13 = $newArray['gm_13'];
$wkly_forms_gm_14 = $newArray['gm_14'];
$wkly_forms_gm_15 = $newArray['gm_15'];
$wkly_forms_gm_16 = $newArray['gm_16'];
$wkly_forms_tot_pts = $newArray['tot_pts'];
$wkly_forms_week = $newArray['week'];
}
?>
If I echo the variables directly inside this script, I get a complete list of all the records in the wkly_forms table that have '01' in the 'week' column.
However, If I try include this script in the following page, the last record meeting the criteria is always displayed:
<?php
include("get_data_picks.php");
?>
<html>
<head>
<title>Week 01 Summary</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<tr>
<td bordercolor="#FFCC00"><b><?php printf ("%s",$wkly_forms_name) ?></b></td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_01) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_02) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_03) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_04) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_05) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_06) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_07) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_08) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_09) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_10) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_11) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_12) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_13) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_14) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_15) ?>.gif"></b></div>
</td>
<td bordercolor="#33FF00">
<div align="center"><b><img src="/weekly_summary/images/small_icons/<?php printf ("%s",$wkly_forms_gm_16) ?>.gif"></b></div>
</td>
<td bordercolor="#FFCC00">
<div align="center"><b><?php printf ("%s",$wkly_forms_tot_pts) ?></b></div>
</td>
</tr>
</html>
This is only one table row from from my web page. On the actual page, I would like to repeat this row for each record in the database that meets the criteria, "WHERE (week = '1').
I realize that there is a major flaw in this coding because the printf statements are run after the loop has gone through all the records and only the last record is being refferenced, but I am completely ignorant on how I would correct it.
Is there a way to put the html inside the loop? Is there a way to specify which record in the array I wish to print? Any guidance or reccomendations would be GREATLY APPRECIATED!!
Thanks,
Deadlast99
P.S. Sorry about the code not being formatted correctly, I'm still trying to figure out how to use the site.