|
MTGap!
|
 |
« on: November 01, 2009, 09:02:55 AM » |
|
This is a script that I've been working on to get the upcoming events within 7 days etc. from a mysql database. This is built into php fusion so many functions are used from that to reduce the work on my part. Something goes wrong at dbarray however and it only grabs one row from the db when there are more events that are under 7 days away. Where am I going wrong? (Everything works besides the actual array part.) require_once "maincore.php";
$CurTimeStamp = time(); $CurDateName = date("l"); echo $CurDateName; $Email = ""; define('DB_EVENTS', DB_PREFIX.'aw_ec_events');
/*-------------------------------------------------------+ | Upcoming Events Search - Sunday +--------------------------------------------------------*/
if ($CurDateName=="Sunday") { $Day7 = "600937"; $CurDate7 = date("Y-m-d",$CurTimeStamp + $Day7); $CurDate = date("Y-m-d",$CurTimeStamp);
echo $CurDate7;
echo "Sunday";
$result = dbquery("SELECT * FROM ".DB_EVENTS." WHERE ev_start BETWEEN '$CurDate' AND '$CurDate7' "); if (dbrows($result)) { echo dbrows($result); $data = dbarray($result); var_dump($data); $Email = "1"; echo "Email"; /*-------------------------------------------------------+ | Creation of Email Message - Sunday +--------------------------------------------------------*/ $subject = "Upcoming Events This Week";
foreach ($data as $row) {
$eventinfo = "<ul>"; $eventinfo .= "<li><a href='http://--.com/infusions/aw_ecal_panel/view_event.php?id=".$row['event_id']."'/> ".$row['ev_title']." </a>"; $eventinfo .= " on ".$row['ev_start']." from ".$row['ev_start_time']." ".$row['ev_start_ampm']." </li>"; $eventinfo .= "</ul>";
$message = "<html><table><tr><td><img src='http://--.com/images/calendar.png' /></td><td><h1 style='font-size:125%'>$subject</h1></td></tr>"; $message .= "<tr><td colspan='2'><hr>The following events are taking place this week: <br /><br />$eventinfo</td></tr><tr><td colspan='2'>"; $message .= "<a href='http://--.com/news.php'><img src='http://--.com/images/logo.png' /></a></td></tr></table></html>"; } } } if ($Email=="1") {
echo "Sent";
require_once INCLUDES."sendmail_include.php";
$result = dbquery("SELECT 'user_email' FROM ".DB_USERS." "); $email = dbarray($result);
$toname = "--"; $toemail = "--"; $fromemail ="admin@--.com"; $fromname = "--";
sendemail($toname, $toemail, $fromname, $fromemail, $subject, $message); }
Here are the functions used as defined by PHP-Fusion: function dbquery($query) { $result = @mysql_query($query); if (!$result) { echo mysql_error(); return false; } else { return $result; } } function dbrows($query) { $result = @mysql_num_rows($query); return $result; } function dbarray($query) { $result = @mysql_fetch_assoc($query); if (!$result) { echo mysql_error(); return false; } else { return $result; } }
Something goes wrong at dbarray however, even though it should be pulling up multiple events but it just pulls up the closest one to the current date. And then here is the email I get from it: The following events are taking place this week:
|
|
|
|
« Last Edit: November 12, 2009, 10:48:24 AM by MTGap! »
|
Logged
|
|
|
|
|
MTGap!
|
 |
« Reply #1 on: November 02, 2009, 09:56:11 AM » |
|
Bump I need some help.
|
|
|
|
|
Logged
|
|
|
|
|
robleyd
|
 |
« Reply #2 on: November 02, 2009, 11:06:15 AM » |
|
What do these return? echo dbrows($result);
var_dump($data);
If the former is 1 then your query is not correct assuming you have more than one row that meets the criteria. $data should be an associative array of all the matching records.
|
|
|
|
|
Logged
|
I once had a hard drive clunk-clicking Strange noises, weird sounds and tick-ticking I thought I would wait And procrastinate... But now all my data is missing -------------- dd, a dump, a data dump read a line from standard in $USER, the name I call my self make - a long long time to run .so a library that is shared .ko it's not the same as .so tee, a redirect with in and out and brings us back to dd d d d
|
|
|
|
MTGap!
|
 |
« Reply #3 on: November 02, 2009, 11:53:54 AM » |
|
Just checked and yes it is 1, so is my syntax for my query not correct. I wasn't sure but it didn't seem to give off any errors.
|
|
|
|
|
Logged
|
|
|
|
|
robleyd
|
 |
« Reply #4 on: November 02, 2009, 12:06:59 PM » |
|
Your syntax is correct, otherwise mysql would return an error. But it seems you might be submitting a query that returns no results. Echo your actual query, check the format of your $CurDate and $CurDate7 are correct for ev_date, and check there are actually records in the table that match the criteria. What does $data show when you dump it?
|
|
|
|
|
Logged
|
I once had a hard drive clunk-clicking Strange noises, weird sounds and tick-ticking I thought I would wait And procrastinate... But now all my data is missing -------------- dd, a dump, a data dump read a line from standard in $USER, the name I call my self make - a long long time to run .so a library that is shared .ko it's not the same as .so tee, a redirect with in and out and brings us back to dd d d d
|
|
|
|
MTGap!
|
 |
« Reply #5 on: November 03, 2009, 07:46:26 AM » |
|
Okay here is what I get: Monday2009-11-092009-11-02Sunday2array(25) { ["event_id"]=> string(2) "20" ["user_id"]=> string(1) "1" ["ev_title"]=> string(13) "Test" ["ev_body"]=> string(20) "test" ["ev_location"]=> string(35) "test" ["ev_no_smileys"]=> string(1) "0" ["ctime"]=> string(10) "1256767930" ["mtime"]=> string(1) "0" ["ev_start"]=> string(10) "2009-11-03" ["ev_end"]=> string(10) "0000-00-00" ["ev_start_time"]=> string(  "07:00:00" ["ev_end_time"]=> string(  "08:03:00" ["ev_start_ampm"]=> string(2) "PM" ["ev_end_ampm"]=> string(2) "PM" ["ev_repeat"]=> string(1) "0" ["ev_private"]=> string(1) "0" ["ev_status"]=> string(1) "0" ["ev_allow_logins"]=> string(1) "0" ["ev_max_logins"]=> string(1) "0" ["ev_login_access"]=> string(3) "101" ["ev_login_limit"]=> string(1) "0" ["ev_login_start"]=> string(1) "0" ["ev_login_end"]=> string(1) "0" ["ev_access"]=> string(3) "101" ["published_by"]=> string(1) "1" } EmailSent I added a echo $CurDate; as well and the dates it looks for are between 2009-11-09 2009-11-0
I still need some help with this. I just recently checked and it now sees to two rows. Which means something happens with the array.
|
|
|
|
« Last Edit: November 07, 2009, 10:17:20 AM by inp o҉rtb »
|
Logged
|
|
|
|
|
robleyd
|
 |
« Reply #6 on: November 06, 2009, 10:49:02 AM » |
|
Presumably you now have two rows that match the query criteria; which is entirely possible given that current date has changed.
So what exactly is now happening, and how is that different from what you expect to happen?
|
|
|
|
|
Logged
|
I once had a hard drive clunk-clicking Strange noises, weird sounds and tick-ticking I thought I would wait And procrastinate... But now all my data is missing -------------- dd, a dump, a data dump read a line from standard in $USER, the name I call my self make - a long long time to run .so a library that is shared .ko it's not the same as .so tee, a redirect with in and out and brings us back to dd d d d
|
|
|
|
|
inp o҉rtb
The Gangsta
Global Moderator
Official 110mb Guru
   
Offline
Posts: 15644
experimental theologian
|
 |
« Reply #8 on: November 07, 2009, 10:22:27 AM » |
|
What's happening is that @brickclub has received some example code over at ubuntuforums, but is not changing any of the placeholder variable names to make it work.
|
|
|
|
|
Logged
|
|
|
|
|
robleyd
|
 |
« Reply #9 on: November 07, 2009, 10:23:27 AM » |
|
Why are you using such a convoluted method? What's wrong with something simple like: while ($row = mysql_fetch_assoc($result)) { $eventinfo = "<ul>"; $eventinfo .= "<li><a href='http://--.com/infusions/aw_ecal_panel/view_event.php?id=".$row['event_id']."'/> ".$row['ev_title']." </a>"; $eventinfo .= " on ".$row['ev_start']." from ".$row['ev_start_time']." ".$row['ev_start_ampm']." </li>"; $eventinfo .= "</ul>";
$message = "<html><table><tr><td><img src='http://--.com/images/calendar.png' /></td><td><h1 style='font-size:125%'>$subject</h1></td></tr>"; $message .= "<tr><td colspan='2'><hr>The following events are taking place this week: <br /><br />$eventinfo</td></tr><tr><td colspan='2'>"; $message .= "<a href='http://--.com/news.php'><img src='http://--.com/images/logo.png' /></a></td></tr></table></html>"; }
|
|
|
|
|
Logged
|
I once had a hard drive clunk-clicking Strange noises, weird sounds and tick-ticking I thought I would wait And procrastinate... But now all my data is missing -------------- dd, a dump, a data dump read a line from standard in $USER, the name I call my self make - a long long time to run .so a library that is shared .ko it's not the same as .so tee, a redirect with in and out and brings us back to dd d d d
|
|
|
|
MTGap!
|
 |
« Reply #10 on: November 07, 2009, 10:43:10 AM » |
|
I just tried that and I see nothing at all from that section for $eventinfo.
|
|
|
|
|
Logged
|
|
|
|
|
robleyd
|
 |
« Reply #11 on: November 07, 2009, 12:09:36 PM » |
|
Well, as I can't see what your script is doing, I'd have to hazard a guess that you maybe aren't using that variable for anything? What do you expect it to do?
Sorry to ask all these dumb questions, but my crystal ball is broken today.
|
|
|
|
|
Logged
|
I once had a hard drive clunk-clicking Strange noises, weird sounds and tick-ticking I thought I would wait And procrastinate... But now all my data is missing -------------- dd, a dump, a data dump read a line from standard in $USER, the name I call my self make - a long long time to run .so a library that is shared .ko it's not the same as .so tee, a redirect with in and out and brings us back to dd d d d
|
|
|
|
MTGap!
|
 |
« Reply #12 on: November 08, 2009, 12:49:57 AM » |
|
Okay I guess I'll try this out: http://pastebin.com/m1f170441Okay currently no changes and I'm sorry I'm not explaining this well. Basically I want to send out an email to a list of email addresses (Currently it doesn't do that I'm just testing it with my own) with all of the upcoming events. It gets the current date and then adds 7 days to it ($CurDate7) then I do a query for all of the events that fall between those two dates. Then I make the actual content for the email. What I'm trying to do for $eventinfo is for each event that is in $result to have its own bullet with that information. So I basically I want it to loop through for each event. Then it will send out the email after it has generated the email. Currently when I test it I get the email but I only see one event with a bullet next to it. Not all 3. I know there should be three since I did a echo dbrows($result); and there are 3. I did comment out part of it but only because I was experimenting around with it, so how exactly can I get this to function properly? Thanks for any help. Here is the output of the file as determined by the many echos in the code: Saturday2009-11-142009-11-07Sunday3EmailSent
|
|
|
|
|
Logged
|
|
|
|
|
robleyd
|
 |
« Reply #13 on: November 08, 2009, 02:23:06 PM » |
|
Ah, young grasshopper, you have much to learn  You have a logic error in your creation of $message and $eventinfo. each time through the while ($row = loop you are initialising both variables. Hence, you only get the last row's values. What you should be doing is this (pseudocode, leaving you to write the actual php): $eventinfo = ''; while (row= ... concatenate the info you want to $eventinfo end while $message = message stuff concatenate $eventinfo concatenate other message stuff Over to you.
|
|
|
|
« Last Edit: November 08, 2009, 02:25:46 PM by robleyd »
|
Logged
|
I once had a hard drive clunk-clicking Strange noises, weird sounds and tick-ticking I thought I would wait And procrastinate... But now all my data is missing -------------- dd, a dump, a data dump read a line from standard in $USER, the name I call my self make - a long long time to run .so a library that is shared .ko it's not the same as .so tee, a redirect with in and out and brings us back to dd d d d
|
|
|
|
darrenbeige
|
 |
« Reply #14 on: November 08, 2009, 09:25:00 PM » |
|
Ah, young grasshopper, you have much to learn  You have a logic error in your creation of $message and $eventinfo. each time through the while ($row = loop you are initialising both variables. Hence, you only get the last row's values. What you should be doing is this (pseudocode, leaving you to write the actual php): $eventinfo = ''; while (row= ... concatenate the info you want to $eventinfo end while $message = message stuff concatenate $eventinfo concatenate other message stuff Over to you. If you want to do some more complex stuff with the retrieved data, in the long run, fetching an array might be the better option.
|
|
|
|
|
Logged
|
|
|
|
|
MTGap!
|
 |
« Reply #15 on: November 11, 2009, 08:43:59 AM » |
|
I'm confused as to what you're saying robleyd..... Yeah I understand it but don't see how that helps me, or I guess why.
I'm not asking you to do it for me, but could you just show me the basis?
|
|
|
|
|
Logged
|
|
|
|
|