Forum Moderators: coopster
<?php
include("config.php");
// Connect to the database server
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database $DBName");
mysql_select_db($DBName) or die("Unable to select database $DBName");
?>
<p> Here are all the email address in our orders database:
</p>
<blockquote>
<?php
$result = @mysql_query("SELECT email FROM
orders");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() .
"</p>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
echo($row["email"] . "<br>");
}
?>
<?php
include("config.php");
// Connect to the database server
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database $DBName");
mysql_select_db($DBName) or die("Unable to select database $DBName");
?>
<p> Here are all the email address in our orders database:
</p>
<blockquote>
<?php
$result = @mysql_query("SELECT email FROM
orders");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() .
"</p>");
exit();
}
// while ( $row = mysql_fetch_array($result) ) {
// echo($row["email"] . "<br>");
// }
while ( $row = mysql_fetch_array($result) ) {
if ($row['edata']=="Yes subscribe me")
{
echo($row['email'] . "<br>");
}
}
?>
I am hoping to use this to make it easier for me to add my customers to my mailing list. I want to eventually have it create a field with a yes value for added or maybe check the list DB itself to see if they are added or not and only display the ones that need to be added.
I am trying hard to learn this code but am having trouble with the syntax and structure at this stage.
Your help is much appreciated and I'm sure it will increase my learning curve.
Cheers
Gruntre
while ( $row = mysql_fetch_array($result) ) {
if ($row['edata']=="Yes subscribe me")
{
Are you certain that you are testing the right condition? It appears that your database contains 'Yes please subscribe me' and you are testing for 'Yes subscribe me'. That will return... nothing.
I am trying hard to learn this code but am having trouble with the syntax and structure at this stageYour troubles will melt away in no time.
:) I'm an old programmer but still green with PHP. I bet I only use about 10 PHP functions, and there appear to be more than 100 available. Maybe someone knows the exact number...
In addition to knowing the language specific requirements, I find it helpful to having a broader understanding of the programming cycle. One thing that helped me early on was a class that discussed 6 Steps of Successful Programming. I can't recall the specifics, but believe me when I say that the process happens before I write a program. That's especially helpful for designing a structure for your code. You could look into psuedo code for more structuring information.
Unless I miss something why do not you add a "where" clause in your query for ex: where yes=yes
if you have a col named yes
$sql = "select * from XXXX where yes = '$yes'";
$yes being whatever is entered as Y or yes etc...
$sql = "select * from extra where yes = '$Yes subscribe me'"; but am not 100% sure where to put it and how $sql is relevent to the rest of the code. Gruntre
include("config.php");
// Connect to the database server
mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database $DBName");mysql_select_db($DBName) or die("Unable to select database $DBName");
?>
<p> Here are all the email address in our orders database:
</p>
<blockquote>
<?php
$yes = "Yes subscribe me";
$result = @mysql_query("SELECT email FROM
orders WHERE edata = '$yes'");
if (!$result) {
echo("<p>Error performing query: " . mysql_error() .
"</p>");
exit();
}
while ( $row = mysql_fetch_array($result) ) {
echo($row["email"] . "<br>");
}
?>
Gruntre