PHP & MySQL
I have this PHP page below in my website. It reads a list of newsletters from MySQL and lists them by subject in an option box. I have about 10 newsletters and only the first newletter is showing up in the option box. Can anyone see what I'm doing wrong? Running on PHP Ver. 4.3.8 and MySQL Ver. 12.22 Distrib 4.0.20a, for Win95/Win98 (i32). I would first like to thank paulhiles and php~pro for all their help with my PHP and ASP productions so far. Look how good I'm getting:
<?
require ("menublock.php");
require ('newsletters/connect.php');
$db = @mysql_select_db($db_name, $connection) or die(mysql_error());
$sql = "SELECT id, subject, newstext FROM $table_name ORDER BY subject";
$result = @mysql_query($sql, $connection) or die(mysql_error());
$num = @mysql_num_rows($result);
if ($num < 1) {
$display_block = "
Sorry! No newsletters.</p>";
} else {
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$subject = $row['subject'];
$newstext = $row['newstext'];
$option_block = "<option value=\"$id\">$subject</option>";
}
$display_block = "<form method=\"post\" action=\"show_newsletter.php\">
Newsletter:
<select name=\"id\">
$option_block
</select>
<input type=\"submit\" name=\"submit\" value=\"Select this Newsletter\"></p>
</form>";
}
?>
<html>
<head>
<title>My Contact Management System: Send a Newsletter</title>
</head>
<body>
<h1>My Contact Management System</h1>
<h2>Send a Newsletter - Select from List</h2>
Select a newsletter from the list below, to send that newsletter.</p>
<? echo "$display_block"; ?>
<? echo "$menu_block"; ?>
</body>
</html>
menublock.php is where I am storing my link menu and connect.php is where I am storing my well, MySQL connection info.
OK, made a change:
$option_block .= "<option value=\"$id\">$subject</option>";
Added the concatination thingy . and that took care of displaying multiple options, now I have this error:
Notice: Undefined variable: option_block in C:\Accounts\homesear\wwwRoot\admin\newsletter\pick _newsletter.php on line 15.
$option_block = "<option value=\"$id\">$subject</option>";
|