Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with PHP newsletter system 1

Status
Not open for further replies.

mroos81

MIS
Nov 14, 2003
16
NL
Hello everybody,

I'm working on a newsletter system in PHP4 & MySQL.
People can subscribe for the list, and can choose their areas of interest. There's a minimum of 1 and a maximum of 5 interests.

I allready have the main mailingsystem working, but I want it a little more complex.
I've seperated the mailform into 6 sections, the first one for general news that everybody gets, the second one for interest 1, the third one for interest 2, etc.

Now I want my recipients just to receive the information for the interests they've signed up for. So somebody who signed up for interest 2 and 5 should recieve the general part, and the parts for 2 and 5.

This is the bit of code I allready have, but I think I'm completely out of direction...

$query_tekst = "SELECT personen.persoon_id, interesse_persoon.interesse_id FROM interesse_persoon, personen WHERE interesse_persoon.persoon_id = '$id'";
$txt_tekst = mysql_fetch_assoc(mysql_query($query_tekst));
$interesse = $txt_tekst["interesse_id"];

IF ($interesse == "1")
$message = $message1;
IF ($interesse == "2")
$message = $message2;
IF ($interesse == "3")
$message = "$message1<p>$message2";


Is there someone who built a system like this before? And otherwise, is there someone who can give me some advise on how to make it work?

Many thanks!

Michael
 
SELECT B.persoon_id, A.interesse_id FROM personen B JOIN interesse_persoon A on A.persoon_id = B.persoon_id order by b.persoon_id

This way you get all the persons and the interests.

Then you can do this:

//
$query="query above";
$res=mysql_query($query);
$lastid="";
while(mysql_num_rows($res) && $row=mysql_fetch_array($res)){
if($lastid <> $row["personId"] && $lastid <> ""){
mail(... $message[1].$suffix ...);
}
$suffix.="<p>".$message[$row["interestId"]];
$lastId=$row["personId"];
}



Hope this will help you out

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin@anikin-skywalker.com
 
Hello,

Thanks very much for your reaction. I tried it immediately, but when I run the script, I get the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource etc, etc...

Do you know how this error is caused? Does it have something to do with the version of PHP?

Thanks!

Michael
 
mroos81:
If there is a problem with your query myssq_query() returns FALSE, not a resource handle. If a script attempts to use the FALSE false as a resource handle to fetch data from a MySQL return, you will get that error.

Your script is not testing the return from mysql_query().

I recommend that instead of:

Code:
$txt_tekst = mysql_fetch_assoc(mysql_query($query_tekst));

You use:
Code:
$text_handle = mysql_query($query_tekst) or die (mysql_error());
$txt_tekst = mysql_fetch_assoc($text_handle);

This will output sufficient debugging information to know what is wrong.



Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top