I could use a little php help, please

Eos

Diamond Member
Jun 14, 2000
3,463
17
81
Hi there.

I've been using this code for quite some time to delete dead torrents from my tracker. It works great, but I'd like a slight change to be added to it so I can delete certain torrents from a category of my choosing.

The issue I see is in this line: $a = mysql_query("SELECT id, added, size, times_completed, name FROM torrents WHERE UNIX_TIMESTAMP() - UNIX_TIMESTAMP(torrents.last_action) > 1209600");

How does this look: FROM torrents WHERE ????(torrents.category) = 3

The question mark is obviously where I need the helping hand.

The category field has 4 variables; int(10), UNSIGNED, NOT NULL, and a default of 0.
 

clamum

Lifer
Feb 13, 2003
26,256
406
126
If you're putting the category number in your code, it would be something like this:
$cat_num = 3
"...WHERE torrents.category = " . $cat_num

If you want to enter in the number, you'd have to add a text box and then retrieve the number from either GET or POST, depending on what method you used:
$cat_num = $_GET['category_number'] (or $_POST['category_number'])
"... WHERE torrents.category = " . $cat_num

I think that's what you're asking. If you have other boolean tests in the WHERE part, you'll have to add an AND keyword in there too to separate them.
 

Eos

Diamond Member
Jun 14, 2000
3,463
17
81
Originally posted by: clamum
Did that answer your question or am I way off? Haha. :)

I'm afraid to try it! :eek: Are there spaces here: (torrents.category = ".$cat_num = 3) or not?

$a = mysql_query("SELECT id, added, size, times_completed, name FROM torrents WHERE (torrents.category = ".$cat_num = 3);
 

clamum

Lifer
Feb 13, 2003
26,256
406
126
Spaces around the dot (concatenation) operator? It doesn't matter. I put spaces around it because I think the code is a little easier to read but that's just me.

Your statement is pretty close. It should look like this (removed the left parenthesis before torrents.category):

$a = mysql_query("SELECT id, added, size, times_completed, name FROM torrents WHERE torrents.category = ".$cat_num = 3);
 

Eos

Diamond Member
Jun 14, 2000
3,463
17
81
No luck, but no errors either.

Here's what I ran:

<?
require_once("backend/functions.php"); //Include the handy functions file
dbconn(); // Connect to the MySQL database
$a = mysql_query("SELECT id, added, size, times_completed, name FROM torrents WHERE torrents.category = ".$cat_num = 3);

$num = mysql_numrows($a); // Queries the database and selects the 2 day old rows (172800 secs=2 days)
mysql_close(); //disconnect
echo "Please wait...<br>";

$i=0;
while ($i < $num) {

$id=mysql_result($a,$i,"id");

$date=mysql_result($a,$i,"added");

$snatch=mysql_result($a,$i,"times_completed"); //Print the id#s of the torrents that the last seeder was more than 2 days ago.

$size=mysql_result($a,$i,"size");

$name=mysql_result($a,$i,"name");

deletetorrent($id);

$email="Dead torrent deleted!\n--------------------\nName: $name\nDate Added: $date\nSize: ".mksize($size)." (".number_format($size)."bytes)\nSnatched $snatch times";

$sdate=explode(" ",$date);
mail("goatbased@gmail.com","Torrent From $sdate[0] Deleted.",$email,"From: torrent-admin@goatbased.com\n");

$i++;
}
echo "<br>Success!";
?>