Forum Moderators: coopster
<html>
<body>
<?php
session_start();
include ("odbc.inc");
include ("utils.inc");
$php_self = $_SERVER['PHP_SELF'];
if ( isset($_POST['submit']) ) { // if form is submitted, process it
for($i=1; $i<=$_POST['lobcod']; $i++) {
if ( isset($_POST["lobcod$i"] ) ) {
print $_POST["lobcod$i"]." is checked.<br/>";
}
}
} else { // if form isn't submitted, output the form
print "<form action=\"tables.php\" method=\"POST\">\n";
$sql_rset = "SELECT admissions FROM bh_systems.net_bh_followups_lob_alos n";
$link = mysql_connect("", "", "");
$db_link = db_connect("");
$resultrset = odbc_exec($db_link, $sql_rset) or die("SELECT FAILED: $sql_rset".odbc_errormsg());
if ($resultrset) {
print "<table width=200 border=1>\n";
print "<tr>\n";
print "<th> </th>\n";
print "<th> Admissions </th>\n";
print "<th> followups7</th>\n";
print "<th> percent_followups7</th>\n";
print "</tr>\n";
//create table
$i = 0;
while ( $row = odbc_fetch_array($resultrset) ) {
$i++;
print "<tr>\n";
print "<td><input type=\"checkbox\" name=\"lobcod$i\" value=\"$row[lobcod]\"></td>\n";
echo "<td>{$row['Admissions']}</td>\n";
echo "<td>{$row['lobcod']}</td>\n";
echo "</tr>\n";
}//end while
print "</table>\n";
} else {
echo("<P>Error performing query: " .
odbc_error() . "</P>");
}
}
?>
</form>
</body>
</html>
That means something like this:
$thevar = $first_time_used; If you had not previously set $first_time_used, it would give that warning, because the variable is undefined. However, you should still be able to run the script, as it merely uses an undefined (blank) for its value. PHP doesn't really have "junked" variable space like C or C++.
Here's my updated code:
<html>
<body>
<?php
session_start();
include ("odbc.inc");
include ("utils.inc");
$php_self = $_SERVER['PHP_SELF'];
if ( isset($_POST['submit']) ) { // if form is submitted, process it
for($i=1; $i<=$_POST['lobcod']; $i++) {
if ( isset($_POST["lobcod$i"] ) ) {
print $_POST["lobcod$i"]." is checked.<br/>";
}
}
} else { // if form isn't submitted, output the form
print "<form action=\"tables.php\" method=\"POST\">\n";
$sql_rset = "SELECT * FROM bh_systems.net_bh_followups_lob_alos n";
$db_link = db_connect();
$resultrset = odbc_exec($db_link, $sql_rset) or die("SELECT FAILED: $sql_rset".odbc_errormsg());
print odbc_num_rows($resultrset);
if ($resultrset) {
print "<table width=200 border=1>\n";
print "<tr>\n";
print "<th> </th>\n";
print "<th> lobcod </th>\n";
print "<th> Admissions </th>\n";
print "<th> followups7</th>\n";
print "<th> percent_followups7</th>\n";
print "</tr>\n";
//create table
$i = 0;
while ( $row = odbc_fetch_array($resultrset) ) {
$i++;
//print $row['admissions'];
print "<tr>\n";
if (isset($lobcod)) {
print "<td><" .$row['lobcod']. "</td>\n";
//echo "<td>{.$row['lobcod']}."</td>\n";
}
echo "</tr>\n";
}//end while
print "</table>\n";
} else {
echo("<P>Error performing query: " .
odbc_error() . "</P>");
}
}
?>
</form>
</body>
</html>
I did see this [w3schools.com], which might be helpful.
I suspect that what is happening is you are not getting back a proper associative array, or the keys aren't exactly what you expect them to be.
I'd do a
print_r ( $row ); to see what's coming out of the DB. Also, this doesn't make a whole lot of sense:
if (isset($lobcod)) {
print "<td><" .$row['lobcod']. "</td>\n";
} It will always fail the test. I think you mean to do this:
if (isset($row['lobcod'])) {
print "<td><" .$row['lobcod']. "</td>\n";
} By the way, welcome to WebmasterWorld.
I thought that this [webmasterworld.com] was a pretty good post.