Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-18-2004, 04:13 PM
WebProWorld Pro
 

Join Date: Aug 2004
Location: Maryland
Posts: 219
webmasterjunkie RepRank 0
Default 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>";
Reply With Quote
  #2 (permalink)  
Old 10-18-2004, 05:23 PM
WebProWorld Pro
 

Join Date: Aug 2004
Location: Maryland
Posts: 219
webmasterjunkie RepRank 0
Default Nevermind

I got frustrated and just gave up that's why I posted. I kept plugging at it, and I GOT IT! After I added the concatination I got the error so I just added and option value of Select One right before the while statement!

Duh!
Reply With Quote
  #3 (permalink)  
Old 10-19-2004, 07:41 PM
Deep13's Avatar
WebProWorld Veteran
 

Join Date: Dec 2003
Location: India
Posts: 306
Deep13 RepRank 0
Default

you are doing it outside the while loop

or you can do like this also


instead of $option_block = "<option value=\"$id\">$subject</option>";

use this $option_block .= "<option value=\"$id\">$subject</option>";

Regards
Deep
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0