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 7 1803
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
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
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
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);
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Greg Bryant |
last post by:
Hi folks. I'm porting a cf site to php, everything's going very well, I
like php much better (this, of course, being the correct forum to make
that statement :).
One problem I have is with...
|
by: Vic Spainhower |
last post by:
Hello,
I am new to php and MySQL and I'm attempting to run a select query on a
MySQL database which is working fine except prior to displaying the table
with the results from the select query it...
|
by: Leszek |
last post by:
I've got a form with a select list:
<select name="$dane">;
After "submit"
$_POST contains the selected value -
Am I right??
I have a problem ith this code:
echo"<select name=\"\$dane\">";
|
by: chsadaki |
last post by:
Hello
I have a problem in retrieving a row form a table that I created in
mysql db.
I insert these values in the table
'Bell',password('123').
But the problem is in my php application I cant...
|
by: bokke |
last post by:
Hi,
I have a page with a link
<a href="Contributor.php?action=&SubCat=<?php echo $row;
?>"><?php echo $row;?></a>
that does to a page with a SELECT
$query = "SELECT * FROM news WHERE...
|
by: pradeep |
last post by:
Hello,
I have problem in PHP String concatination with html select combo
box.
There are 3 files
addressbook.sql :
concat1.php
concat2.php
|
by: Tarik Monem |
last post by:
OK! I've gone through a few tutorials and I cannot understand what I'm doing wrong
casting_registration.php
<table>
<tr>
<td>
<form enctype="multipart/form-data" action="thankyou.php"...
|
by: chaos |
last post by:
Hi ,
I stuck in my project as i face a problem
How to show the available time of the venue when i select the day??
Need to connect to the database to find out the available time of the venue on...
|
by: robin1983 |
last post by:
Hi to all, i m newer to this site and fresher in Ajax world. Actually i get a problem while accessing data from Database. I have a combo box in my pages. Actually i want to access data from the...
|
by: phpnewbie26 |
last post by:
My current form has one multiple select drop down menu as well as few other drop down menus that are single select. Originally I had it so that the multiple select menu was first, but this created...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM)
The start time is equivalent to 19:00 (7PM) in Central...
|
by: Aliciasmith |
last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
|
by: NeoPa |
last post by:
Hello everyone.
I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report).
I know it can be done by selecting :...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
|
by: Teri B |
last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course.
0ne-to-many. One course many roles.
Then I created a report based on the Course form and...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM)
Please note that the UK and Europe revert to winter time on...
|
by: NeoPa |
last post by:
Introduction
For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
|
by: GKJR |
last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...
|
by: SueHopson |
last post by:
Hi All,
I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...
| |