[php] Fuctions

taekwondokid42

New Member
Messages
268
Reaction score
0
Points
0
I need 2 separate functions:

1. A function that will cause a certain script to run at x time of day, every day (or just every so often, it doesn't matter)



2. A function that will enable me to UPDATE every table named duels_* (star meaning there will be multiple tables with different names).


Any help would be appreciated.
 

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
the first one is a cron job you would need to make. there's a bit of info in the forums already on cron jobs, how to make them, and the like

and the second one is a bit too ambiguous for me to help with. basically, what needs updated, and things like that. mostly that one will require some communication with the database to pull all table names, possibly "LIKE 'duels_*'", or using some php string manipulation.
 

taekwondokid42

New Member
Messages
268
Reaction score
0
Points
0
An example code would be:

mysql_query("UPDATE duels_* SET date = $new_date").





Here is specifically what is going on:

I have several tables named

duels_23
duels_24
duels_25
ect.

The number does not start at one, and it skips numbers sometime. A new table with a new number may be created at any time.

How can I write a loop that will hit every table without causing a bunch of errors?


Btw, thanx for the info about the cron jobs.
 
Last edited:

woiwky

New Member
Messages
390
Reaction score
0
Points
0
Try something like:

PHP:
$sql = "SHOW TABLES LIKE 'duel\_%'";
$tables = mysql_query($sql);
while ($table = mysql_fetch_array($tables)) {
    $table = current($table);
    $sql = "UPDATE $table
        SET date = $new_date";
    mysql_query($sql);
}

I think that's what you had in mind.
 

taekwondokid42

New Member
Messages
268
Reaction score
0
Points
0
I'm not fully sure of all the syntax, but it looks like it will do what I want. Thanks.

Going back to cron jobs, is the x10hosting path of php "/usr/local/bin/php"?

Actually, what I'd really like to ask is does this code look correct:

/usr/local/bin/php -q /public_html/agelesscommanders/duels/engine_prune_data.php
 
Last edited:

MasterMax1313

New Member
Messages
84
Reaction score
0
Points
0
not quite....

PHP:
/usr/local/bin/php -q ./public_html/agelesscommanders/duels/engine_prune_data.php

otherwise it will try to look in root for public_html, and our root is not the machine's root (if that makes sense)

I guess you can't really see it, but there is "." in front of /public_html

oh, and there may be more than that, but that was what I saw right off the bat
 
Last edited:
Top