PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.php > Scripting Advice
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Scripting Advice

Réponse
 
LinkBack Outils de la discussion
Vieux 08/11/2007, 21h25   #1
trawets
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Scripting Advice

Hi
I am trying to write something which will enable me to run a php
script from cron which will delete news item entries from a mysql db.

Criteria here is that the script would look at a field 'publish_down'
which has this format '2007-01-29 16:00:08' check this date is passed
and then delete if it is more than 90 days older.


I have tried to come up with something but a little advise would be
grateful


$today = date("Y-m-d", publish_down("-90 days"));


mysql_query("DELETE FROM table WHERE date = '$today'") or
die(mysql_error());

(publish_down = a table field which is a date)

how would I adopt this type of query into php script


please
trawets

  Réponse avec citation
Vieux 08/11/2007, 22h01   #2
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Scripting Advice

trawets wrote:
> Hi
> I am trying to write something which will enable me to run a php
> script from cron which will delete news item entries from a mysql db.
>
> Criteria here is that the script would look at a field 'publish_down'
> which has this format '2007-01-29 16:00:08' check this date is passed
> and then delete if it is more than 90 days older.
>
>
> I have tried to come up with something but a little advise would be
> grateful
>
>
> $today = date("Y-m-d", publish_down("-90 days"));
>
>
> mysql_query("DELETE FROM table WHERE date = '$today'") or
> die(mysql_error());
>
> (publish_down = a table field which is a date)
>
> how would I adopt this type of query into php script
>
>
> please
> trawets
>
>


I'm not sure what you mean when you say "adopt this type of query into
php script". It should work pretty much like you have it.

Although personally I would not have a column named date (reserved
word), would not call the variable $today (it's not - it's 90 days ago
and could be confusing), and I would check for date <= '$today', just in
case the script doesn't get run one day.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Vieux 09/11/2007, 20h28   #3
trawets
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Scripting Advice

On 8 Nov, 22:01, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> trawets wrote:
> > Hi
> > I am trying to write something which will enable me to run a php
> > script from cron which will delete news item entries from a mysql db.

>
> > Criteria here is that the script would look at a field 'publish_down'
> > which has this format '2007-01-29 16:00:08' check this date is passed
> > and then delete if it is more than 90 days older.

>
> > I have tried to come up with something but a little advise would be
> > grateful

>
> > $today = date("Y-m-d", publish_down("-90 days"));

>
> > mysql_query("DELETE FROM table WHERE date = '$today'") or
> > die(mysql_error());

>
> > (publish_down = a table field which is a date)

>
> > how would I adopt this type of query into php script

>
> > please
> > trawets

>
> I'm not sure what you mean when you say "adopt this type of query into
> php script". It should work pretty much like you have it.
>
> Although personally I would not have a column named date (reserved
> word), would not call the variable $today (it's not - it's 90 days ago
> and could be confusing), and I would check for date <= '$today', just in
> case the script doesn't get run one day.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================- Hide quoted text -
>
> - Show quoted text -


Hi
Thanks for the reply I have taken on board what you mean about some of
the labels used and will address this

What I meant (I think) was this would require incorporating in a full
stand alone script which would log into the db and do the required
look and delete maybe on a daily basis

I am sorry if it all sound a bit weird, as I am a novice a this with
just some basic skills in this area
Again thanks for the reply a least now I know it might work
trawets

  Réponse avec citation
Vieux 09/11/2007, 21h28   #4
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Scripting Advice

trawets wrote:
> On 8 Nov, 22:01, Jerry Stuckle <jstuck...@attglobal.net> wrote:
>> trawets wrote:
>>> Hi
>>> I am trying to write something which will enable me to run a php
>>> script from cron which will delete news item entries from a mysql db.
>>> Criteria here is that the script would look at a field 'publish_down'
>>> which has this format '2007-01-29 16:00:08' check this date is passed
>>> and then delete if it is more than 90 days older.
>>> I have tried to come up with something but a little advise would be
>>> grateful
>>> $today = date("Y-m-d", publish_down("-90 days"));
>>> mysql_query("DELETE FROM table WHERE date = '$today'") or
>>> die(mysql_error());
>>> (publish_down = a table field which is a date)
>>> how would I adopt this type of query into php script
>>> please
>>> trawets

>> I'm not sure what you mean when you say "adopt this type of query into
>> php script". It should work pretty much like you have it.
>>
>> Although personally I would not have a column named date (reserved
>> word), would not call the variable $today (it's not - it's 90 days ago
>> and could be confusing), and I would check for date <= '$today', just in
>> case the script doesn't get run one day.
>>
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================- Hide quoted text -
>>
>> - Show quoted text -

>
> Hi
> Thanks for the reply I have taken on board what you mean about some of
> the labels used and will address this
>
> What I meant (I think) was this would require incorporating in a full
> stand alone script which would log into the db and do the required
> look and delete maybe on a daily basis
>
> I am sorry if it all sound a bit weird, as I am a novice a this with
> just some basic skills in this area
> Again thanks for the reply a least now I know it might work
> trawets
>
>


It's not hard. The script would be very similar to what you have for a
website, except it wouldn't echo, print, etc. anything. Rather any
messages would be written to a log file.

Start it out daily as a cron job (Linux) or scheduled task (Windows) and
let it go.

Nothing really special about it at all.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 22h53.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,19102 seconds with 12 queries