468,249 Members | 1,469 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,249 developers. It's quick & easy.

select and echo problem

Hello,

I do hope some kind soul can help me with what I thought was not going
to be difficult, but for this newbie it's a bit harder than I thought.

Here's what I'm trying to do.....

I can select from my database the records that I need, but I need to
insert them somewhere down the page so that I can process them. Here's
my select statement......

SELECT email,equipment,username,status FROM table WHERE status = 'J'

That's all fine and dandy and php admin returns the correct info.

What I want to do is pass the returned information into 4 variables
that I can use to cal into a php() mail function.

I need to end up with....
$email
$equipment
$username
$status
.......so that I can use the variables as below.....
$to = "$email";
$headers .= "$username";
$headers .= "$equipment";
$headers .= "$status";

mail("$to", "$status", "message", "additional headers")

I'm going to use a cron job to do this, and I have other cron jobs
running so it's not a problem to do that. But how do I get the
variables to be able to use? I know I need to use a loop of some kind,
and honestly I have been trying to figure this for a couple of days
and I just can't seem to make it work....sob... :-(

If anyone could show me how to do this I would be ever so grateful as
I have just plain run out of ideas.

Thanks for reading :-)

Nelly

Jul 17 '05 #1
7 1665
Neil < me@nospam.net > wrote:
Hello,
I do hope some kind soul can help me with what I thought was not going
to be difficult, but for this newbie it's a bit harder than I thought.
Here's what I'm trying to do.....
I can select from my database the records that I need, but I need to
insert them somewhere down the page so that I can process them. Here's
my select statement......
SELECT email,equipment,username,status FROM table WHERE status = 'J'
That's all fine and dandy and php admin returns the correct info.
What I want to do is pass the returned information into 4 variables
that I can use to cal into a php() mail function.
I need to end up with....
$email
$equipment
$username
$status
......so that I can use the variables as below.....
$to = "$email";
$headers .= "$username";
$headers .= "$equipment";
$headers .= "$status";
mail("$to", "$status", "message", "additional headers")
I'm going to use a cron job to do this, and I have other cron jobs
running so it's not a problem to do that. But how do I get the
variables to be able to use? I know I need to use a loop of some kind,
and honestly I have been trying to figure this for a couple of days
and I just can't seem to make it work....sob... :-(

Umm, do you have a connection to the database anywhere? Something like this
(example using mysql):

$link = mysql_connect('server','username','password');
$res = mysql_query("SELECT email,equipment,username,status FROM table WHERE
status = 'J'",$link);
//different ways to do this following line, see docs:
//the while loop keeps setting $row to the next record
// in the resultset until no more records are left
// at which point $row gets set to null (I think)
// and loop exits
while ($row = mysql_fetch_array($res,MYSQL_NUM))
{
// $row[0] is email
// $row[1] is equipment
//etc.
}

mysql_close($link);
--
Jeff Evans
Morgan Stanley Investment Management IT
www.jeffevans.us
Jul 17 '05 #2
On Fri, 12 Nov 2004 03:49:07 -0600, "Jeff Evans"
<jwevans1@you_eye_you_see.edu> wrote:

Umm, do you have a connection to the database anywhere? Something like this
(example using mysql):

$link = mysql_connect('server','username','password');
$res = mysql_query("SELECT email,equipment,username,status FROM table WHERE
status = 'J'",$link);
//different ways to do this following line, see docs:
//the while loop keeps setting $row to the next record
// in the resultset until no more records are left
// at which point $row gets set to null (I think)
// and loop exits
while ($row = mysql_fetch_array($res,MYSQL_NUM))
{
// $row[0] is email
// $row[1] is equipment
//etc.
}

mysql_close($link);

Yes, I have the connection and everything else is working
fine.....updates, deletes etc etc, it's just this one problem that I
can't figure out.

Thanks for your reply :-)

Nelly

Jul 17 '05 #3
Neil < me@nospam.net > wrote:
On Fri, 12 Nov 2004 03:49:07 -0600, "Jeff Evans"
<jwevans1@you_eye_you_see.edu> wrote:
Umm, do you have a connection to the database anywhere? Something
like this (example using mysql):
$link = mysql_connect('server','username','password');
$res = mysql_query("SELECT email,equipment,username,status FROM table
WHERE status = 'J'",$link);
//different ways to do this following line, see docs:
//the while loop keeps setting $row to the next record
// in the resultset until no more records are left
// at which point $row gets set to null (I think)
// and loop exits
while ($row = mysql_fetch_array($res,MYSQL_NUM))
{
// $row[0] is email
// $row[1] is equipment
//etc.
}
mysql_close($link);

Yes, I have the connection and everything else is working
fine.....updates, deletes etc etc, it's just this one problem that I
can't figure out.


Well, what is happening? Is the loop simply not executing at all? Is it
not returning a valid resource for $res? If so you probably have a syntax
error or something (check mysql_error()).

It would help a lot if you posted your actual code for fetching/iterating
over records for the database, and what errors/behaviors you're seeing at
what lines.
--
Jeff Evans
Morgan Stanley Investment Management IT
www.jeffevans.us
Jul 17 '05 #4
On Fri, 12 Nov 2004 10:24:19 -0600, "Jeff Evans"
<jwevans1@you_eye_you_see.edu> wrote:

Well, what is happening? Is the loop simply not executing at all? Is it
not returning a valid resource for $res? If so you probably have a syntax
error or something (check mysql_error()).

It would help a lot if you posted your actual code for fetching/iterating
over records for the database, and what errors/behaviors you're seeing at
what lines.

Thanks for the interest Jeff.....here is my code, which doesn't
execute at al!! With a couple of modifcations I was able to check the
number of records returned, and the number was '2'...which is correct
as I have 2 test users with 'J' status. Anyway...here is my
code.........As you can see I haven't got as far as sorting out other
details to loop through yet as I can't even return the 2 email
addresses from the database. PhpMyAdmin returns the 2 test email
addresses perfectly, so the query is good. I would be happy to get
them into the $bcc variable at this stage as that would get me started
and I could probably figure the rest out..

Thanks you for helping.

regards,
Nelly
$email = array();
$query = "SELECT distinct users.email FROM entry,users WHERE
entry.create_by=users.username AND type='J' ORDER BY users.username
desc";
$result = mysql_query($query);
$num = mysql_num_rows($result);

for($i=0;$i<$num;$i++) {
$row = mysql_fetch_array($result);
$email[] = $row['email'];
}
if(count($email)) {
$bcc = implode(",",$email);
}
$subject = "BCC Test";
$message = "testing this bcc thingee";
$headers .= "To: Neil <my@iemail.co.nz>\r\n";
$headers .= "From: Test <te**@email.com>\r\n";
$headers .= "Bcc: $bcc";
mail($to, $subject, $message, $headers);

Jul 17 '05 #5
Neil wrote (in part):

$email = array();
$query = "SELECT distinct users.email FROM entry,users WHERE
entry.create_by=users.username AND type='J' ORDER BY users.username
desc";
$result = mysql_query($query);


Just as a test, to see what you're getting, try:

while ($row = mysql_fetch_assoc($result))
echo '<pre>';print_r($row);echo '</pre>',"\n";
This may give you a hint as to why your code might not be working.

Ken

Jul 17 '05 #6
Neil wrote (in part):
$email = array();
$query = "SELECT distinct users.email FROM entry,users WHERE
entry.create_by=users.username AND type='J' ORDER BY users.username
desc";
$result = mysql_query($query);

Use the following code to see what you're getting from the database:

while($row=mysql_fetch_assoc($result)) {
echo '<pre>';print_r($row);echo '</pre>',"\n"; }

Once you see what you're getting, then you can figure out what's wrong
with your code.

Ken

Jul 17 '05 #7
On 12 Nov 2004 13:28:58 -0800, "Ken Robinson" <ke******@rbnsn.com>
wrote:

Use the following code to see what you're getting from the database:

while($row=mysql_fetch_assoc($result)) {
echo '<pre>';print_r($row);echo '</pre>',"\n"; }

Once you see what you're getting, then you can figure out what's wrong
with your code.

Ken

Thanks Ken, I'll give that a try. I'm away from the machine that I can
access this application at the moment, but I'll be sure to let you
know how I get on. I never thought I'd run into so much difficulty
just trying to get the results of a query into a variable to use with
php mail(). Oh well, we all know what thought did....hee hee!!

Regards,
Nelly
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Greg Bryant | last post: by
2 posts views Thread by Vic Spainhower | last post: by
2 posts views Thread by Leszek | last post: by
6 posts views Thread by chsadaki | last post: by
12 posts views Thread by bokke | last post: by
reply views Thread by pradeep | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.