inhoud mail moet afhangen van SQL

Status
Niet open voor verdere reacties.

McTony

Gebruiker
Lid geworden
23 apr 2009
Berichten
15
Een goede middag,

Alvast mijn excuses als dit in het SQL deel van het forum moet, maar het is een hybride vraagje.

Ik heb een SQL statement waar ik de count van het aantal emailadressen opvraag. Nu wil ik als die count groter is dan 100 dat de message van de email die wordt verstuurd ( $message ) verschild van de message die verstuurd wordt als de count groter of gelijk is aan 100.

Ik weet deels wat ik moet doen, maar kan het niet in code omzetten.

Kan iemand mij helpen ?

Alvast bedankt
 
PHP:
if ( mysql_num_rows( $result_resource ) ) > 100 ) {
  // meer dan 100 mail
}
else {
  // 100 of minder mail
}

Zoiets?
 
Hoe ziet die SQL-statement er eigenlijk uit?
 
Hoe ziet die SQL-statement er eigenlijk uit?

Het is een hele simpele sql.
Eerst steek ik de email in de tabel:
PHP:
$sqlInsert = "INSERT INTO j5_maillist (email) VALUES('$email')";

Dan kijk ik hoeveel mensen er al zijn in de tabel
PHP:
$sql = "SELECT email FROM j5_maillist AS aantalEmails";
$result = mysql_query($sql);

En als dat resultaat <= aan 100 is moet er een andere $message zijn dan als er meer zijn.
PHP:
if( mysql_num_rows($result) <= 100 ){
             $message = '
                   <html>
                    <head>
                      <title>Nihonto Appreciation Day</title>
                    </head>
                    <body>
                        <h2>Nihonto Appreciation Day.</h2>
                      <p>Dear Shogun, </p>
			<br/>
			<p>It is my pleasure to inform you that you are one of the 100 people who wins a free ticket to our Nihonto Appreciation Day. On this day the world will revolve around nihontos even more. We have many plans to make your day occupied. There will be iaido and kendo sessions, an exhibition of antique nihontos, an all-you-can-eat sushi bar,  fireworks and lots more. We would also like to encourage you to bring along your own precious nihonto to show off.</p>
                       <br/>
                       <p>The Nihonto Appreciation Day will be held the 12th of June 2012 in Kyoto, Japan. All travelexpenses ( plain tickets included ) will be refunded after the event. In order to gain acces to the event grounds, you need have to print and bring along this email.</p>
                       <br/>
                       <p>Humble greetings,
                       </p>
			<p><img src="http://discountcddvd.com/images/barcode.gif" alt="barcode" /></p>
                    </body>
                    </html>
                    ';
    } else {
             $message = '
                   <html>
                    <head>
                      <title>Nihonto Appreciation Day</title>
                    </head>
                    <body>
                        <h2>Nihonto Appreciation Day.</h2>
                      <p>Dear Shogun, </p>
			<br/>
			<p>It is my sad duty to inform you that you are not one of the 100 people who wins a free ticket to our Nihonto Appreciation Day.
			But if someone informs us they can\'t make it, we will contact you at once to reinforce us at Nihonto Appreciation Day.
			On this day the world will revolve around nihontos even more. We have many plans to make your day occupied. There will be iaido and kendo sessions, an exhibition of antique nihontos, an all-you-can-eat sushi bar,  fireworks and lots more. We would also like to encourage you to bring along your own precious nihonto to show off.</p>
                       <br/>
                       <p>The Nihonto Appreciation Day will be held the 12th of June 2012 in Kyoto, Japan. All travelexpenses ( plain tickets included ) will be refunded after the event.
                       <br/>
                       <p>Humble greetings,
                       </p>
                    </body>
                    </html>
                    ';
}

        $to      = $email;
        $subject = 'Nihonto Appreciation Day';
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

            // Additional headers
        $headers .= 'To: '.$email.'' . "\r\n";
        $headers .= 'From: Nihonto Appreciation Day' . "\r\n";

        mail($to, $subject, $message, $headers);

        return mysql_query($sql);
 
Laatst bewerkt:
Interessant. Het ziet er opzich goed uit. Krijg je iets van een foutmelding ergens? Controleer je de output van mysql_error()? Misschien zit er een fout in je query ergens.
 
Ik vermoed dat deze query een foutmelding oplevert:
[sql]
SELECT email FROM j5_maillist AS aantalEmails
[/sql]
Volgens mij kun je op die plek geen "AS" gebruiken.

Probeer dit eens:
PHP:
$sql = "SELECT COUNT(email) AS count FROM j5_maillist";
$result = mysql_query($sql) or die(mysql_error());
$aantalEmails = mysql_fetch_assoc($result);

if($aantalEmails['count'] <= 100 ){
             $message = '
                   <html>
                    <head>
                      <title>Nihonto Appreciation Day</title>
                    </head>
                    <body>
                        <h2>Nihonto Appreciation Day.</h2>
                      <p>Dear Shogun, </p>
            <br/>
            <p>It is my pleasure to inform you that you are one of the 100 people who wins a free ticket to our Nihonto Appreciation Day. On this day the world will revolve around nihontos even more. We have many plans to make your day occupied. There will be iaido and kendo sessions, an exhibition of antique nihontos, an all-you-can-eat sushi bar,  fireworks and lots more. We would also like to encourage you to bring along your own precious nihonto to show off.</p>
                       <br/>
                       <p>The Nihonto Appreciation Day will be held the 12th of June 2012 in Kyoto, Japan. All travelexpenses ( plain tickets included ) will be refunded after the event. In order to gain acces to the event grounds, you need have to print and bring along this email.</p>
                       <br/>
                       <p>Humble greetings,
                       </p>
            <p><img src="http://discountcddvd.com/images/barcode.gif" alt="barcode" /></p>
                    </body>
                    </html>
                    ';
    } else {
             $message = '
                   <html>
                    <head>
                      <title>Nihonto Appreciation Day</title>
                    </head>
                    <body>
                        <h2>Nihonto Appreciation Day.</h2>
                      <p>Dear Shogun, </p>
            <br/>
            <p>It is my sad duty to inform you that you are not one of the 100 people who wins a free ticket to our Nihonto Appreciation Day.
            But if someone informs us they can\'t make it, we will contact you at once to reinforce us at Nihonto Appreciation Day.
            On this day the world will revolve around nihontos even more. We have many plans to make your day occupied. There will be iaido and kendo sessions, an exhibition of antique nihontos, an all-you-can-eat sushi bar,  fireworks and lots more. We would also like to encourage you to bring along your own precious nihonto to show off.</p>
                       <br/>
                       <p>The Nihonto Appreciation Day will be held the 12th of June 2012 in Kyoto, Japan. All travelexpenses ( plain tickets included ) will be refunded after the event.
                       <br/>
                       <p>Humble greetings,
                       </p>
                    </body>
                    </html>
                    ';
}
 
        $to      = $email;
        $subject = 'Nihonto Appreciation Day';
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
            // Additional headers
        $headers .= 'To: '.$email.'' . "\r\n";
        $headers .= 'From: Nihonto Appreciation Day' . "\r\n";
 
        mail($to, $subject, $message, $headers);
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan