Forum Moderators: coopster

Message Too Old, No Replies

confused by shorthand and how to stuff an array

mysql, php

         

sukebe

8:41 pm on Oct 4, 2010 (gmt 0)

10+ Year Member



I have a customer emailer that is timing out. so, I want to put the query into a array and work from it to push out emails. However,
all the code is in, what I call, shorthand and I've not found a good resource to help me 'get' this fully.

Here is the opening, where the (trimmed) query starts:
$db->query("SELECT * FROM email_list WHERE newsletters='Yes';

while($db->movenext()){
send_mail($db->col["email"], $subject, $content_html, $from_name." <".$from_email.">", "html");
$uc++;
}
---------------------
'query' is a function:

function query($_query){
list($usec, $sec) = explode(" ",microtime());
$time_start = ((float)$usec + (float)$sec);

$this->query = $_query;
$this->result = @mysql_query($_query, $this->link_id) or die("<b>error in sql query</b><br><pre>".$_query."</pre>.mysql error : <b>".mysql_error($this->link_id)."</b><p>");

list($usec, $sec) = explode(" ",microtime());
$time_end = ((float)$usec + (float)$sec);
$time = $time_end - $time_start;
}
---------------------------
I'm thinking that I can make a version of the query function that returns an array, or is it that $db is already an array? Or, does $this->result actually mean 'foreach ($query->result() as $row)'?
Or, can I put 'foreach ($query->result() as $row)', or something like it in the opening portion of this? Ugh, I'm so clueless.

Again, I'm dealing with timeouts and basically want to get the mysql results as quickly as possible and process the code afterwards.

Thanks!

coopster

8:03 pm on Dec 15, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Looks like you are using a class here and yes, $this->result is going to contain the result "resource" on success that you will need to further process by passing it to mysql_fetch_array() and/or other functions for dealing with result tables, to access the returned data.

sukebe

9:47 pm on Dec 15, 2010 (gmt 0)

10+ Year Member



Thanks, I'm still working on this project. Thanks for the tip.
If I have a selection of months, can I create arrays based on the loop? Like month[$dates], month[$dates], month[$dates]. Is there an easier method?