[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

how to store the query in the db and execute it at a certain time php/mysql

Posted on 2004-09-03
7
Medium Priority
?
279 Views
Last Modified: 2008-02-20
Hi

check this http://www.esvon.com/pg/products/p_classifieds/mod_notify/

It would have 2 multiple select boxes to select 1 or more cities and 1 or more property types, user would type first name, last name and his/her email in and subscribe.
Can you please help me i'm confused - how to get that criteria from boxes, get it compared to the data in the db , how to store that query and get it sent every day around midnight.

Any help would be appreciated
Grazias
0
Comment
Question by:mimalune
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 20

Expert Comment

by:Muhammad Wasif
ID: 11979149
It seems to me a promotion of your porducts :-P
0
 
LVL 25

Accepted Solution

by:
Marcus Bointon earned 2000 total points
ID: 11979757
I think that's someone else's site that he wants to emulate.

Add each multiple select box like this:

<select name="city[]" multiple="multiple">
<option value="london">London</option>
<option value="newyork">New York</option>
<option value="paris">Paris</option>
</select>

<select name="propertytype[]" multiple="multiple">
<option value="flat">Flat</option>
<option value="studio">Studio</option>
<option value="house">House</option>
</select>

then normal text input boxes for the other properties:

<input type="text" name="firstname" />
<input type="text" name="lastname" />
<input type="text" name="email" />

Storing this in a database with appropriate columns:

$query = "INSERT INTO notifications SET
firstname = '{$_REQUEST['firstname']}',
lastname = '{$_REQUEST['lastname']}',
email = '{$_REQUEST['email']}',
cities = '".implode(',', $_REQUEST['city']})."',
propertytypes = '".implode(',', $_REQUEST['propertytype']})."'";
mysql_query($query);

In a script run from a cron job, look for matching ads for each registered person:

$query = "SELECT * FROM notifications";
$result = mysql_query($query);
while ($data = mysql_fetch_array($result)) {
$query = "SELECT * FROM ads WHERE city IN({$data['cities']}) AND propertytype IN({$data['propertytypes']})";
$properties = mysql_query($query);
if (mysql_num_rows($properties) > 0) {
$details = '';
while ($property = mysql_fetch_array($properties)) {
$details .= "{$property['id'} {$property['name']} {$property['description']} {$property['price']}\n";
}
$mail = new PHPMailer;
$mail->AddAddress($data['email'], "{$data['firstname']} {$data['lastname']}");
$mail->From = 'notifications@mypropertystore.com';
$mail->Subject = "Matching properties found";
$mail->Body = "$details";
$mail->send();
}
}

That should cover the basics. I've just written this off the top of my head, so it's not tested or anything. You need to look up how to set up a cron job (plenty of examples in EE), and you need to set up the database appropriately and connect to it. Some error checking and validation would be a good idea (using $_REQUEST elements directly in SQL is not a good habit). It's using PHPMailer, which you'll need to download from here: http://phpmailer.sourceforge.net/

Hope that gets you going in the right direction.
0
 

Author Comment

by:mimalune
ID: 11983108
Thanks a bunch..this was really great.
.i have small prob with this line
$query = "SELECT * FROM ads WHERE city IN({$data['cities']}) AND propertytype IN({$data['propertytypes']})";

this is how it looks in mine code

$q1 = "SELECT * FROM re2_notifications";
$p1 = mysql_query($q1) or die(mysql_error());
while($a1 = mysql_fetch_array($p1))
{
$q2 = "SELECT * FROM re2_listings WHERE city IN('$a1[sub_cities]') AND PropertyType IN('$a1[sub_types]')";
$properties = mysql_query($q2) or die(mysql_error());
$lrows = mysql_num_rows($properties);
if ($lrows > 0) {
$details = '';
while($property = mysql_fetch_array($properties)) {
$details .= "$property[ListingID] $property[Price]\n";
}

echo "$a1[sub_email], $a1[first_name] $a1[last_name]";
echo "$details";
}
}

It works only when there is a single city or single property type - with multiple - nope
This is how the table looks like...
 sub_ID  first_name  last_name  sub_email                      sub_cities                  sub_types  
  5           John     Wayne2   contact@mine-it.com          TORONTO                     Residential  
 4           John     Wayne1   john@mine-it.com     BRAMPTON,TORONTO             Residential  

is there some other way to query it or it has to be using IN, or if i missed some quotes (putting {} doesn't change anything)??
Thank you
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:mimalune
ID: 11983151
OK i realized that cities have to have qoutes in order to get things working
'BRAMPTON', 'TORONTO'
i'm struggling to get them inserted into DB in that format now..
this is the insertions part
            $query = "INSERT INTO re2_notifications SET
      first_name = '$_POST[f_name]',
      last_name = '$_POST[l_name]',
      sub_email = '$_POST[semail]',
      sub_cities = '".implode(',', $_POST[s_city])."',
      sub_types = '".implode(',', $_POST[s_pt])."'";
    mysql_query($query);

0
 

Author Comment

by:mimalune
ID: 11983156
got it working..:)))) thanks a bunch once more....
appreciate your help greatly
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 11987900
Glad it's working. One small thing - you must quote indices of associative arrays, otherwise you'll find your error log filling up with warnings. Instead of saying this:

$_POST[f_name]

say this:

$_POST['f_name']

this can occasionally cause conflicts with quoting within SQL strings, so use {} syntax to remove ambiguity:

          $query = "INSERT INTO re2_notifications SET
     first_name = '{$_POST['f_name']}',
     last_name = '{$_POST['l_name']}',
     sub_email = '{$_POST['semail']}',
     sub_cities = '".implode(',', $_POST['s_city'])."',
     sub_types = '".implode(',', $_POST['s_pt'])."'";
0
 

Author Comment

by:mimalune
ID: 11992978
k..thanks for the tip..appreciate very much :)
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question