View Full Version : Sql...
rogersnm
06-25-2006, 10:33 AM
OK so i have this: $chocolate = $vbulletin->db->query_read("
SELECT column1
FROM " . TABLE_PREFIX . "test
WHERE columnfudge > '999'
LIMIT 1
");
$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX . "test (column1,columnfudge) VALUES ('[2] $chocolate','0')
"); in a cron. When the cron runs it picks up value of $chocolate (which is abc in this case) It doesn't add it as "[2] abc" and "0" it does "[2] Resource id #18" and "0". Any Ideas?
Guest190829
06-25-2006, 10:37 AM
OK so i have this: $chocolate = $vbulletin->db->query_read("
SELECT column1
FROM " . TABLE_PREFIX . "test
WHERE columnfudge > '999'
LIMIT 1
");
$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX . "test (column1,columnfudge) VALUES ('[2] $chocolate','0')
"); in a cron. When the cron runs it picks up value of $chocolate (which is abc in this case) It doesn't add it as "[2] abc" and "0" it does "[2] Resource id #18" and "0". Any Ideas?
From the code above the value of $chocalate is not the what you may expect it to be, it's actually a resource variable. (As you can tell from the what you get in the database: "Resource id #18".
Use:
$db->query_first
instead of $db->query_read on your first query, since you are only pulling up one value.
rogersnm
06-25-2006, 10:39 AM
it still doesn't work: now i get "[2] Array" intead of "[2] abc"
i have:$chocolate = $vbulletin->db->query_first("
SELECT column1
FROM " . TABLE_PREFIX . "test
WHERE columnfudge > '999'
LIMIT 1
");
$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX . "test (column1,columnfudge) VALUES ('[2] $chocolate','0')
");
and just as reassurance when i run the query SELECT column1 FROM test WHERE columnfudge > '999' LIMIT 1; i do get the right result (abc).
Paul M
06-25-2006, 11:38 AM
$chocolate is an array of the columns you requested in the query. You need to use $chocolate['column1']
rogersnm
06-25-2006, 11:44 AM
Now i getParse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/nick/public_html/dev/includes/cron/autoclose.php on line 30 I attached the cron file.
Paul M
06-25-2006, 12:36 PM
There are too many single quotes in that.
Since it's only one column try this ;
$choc = $vbulletin->db->query_first("
SELECT column1
FROM " . TABLE_PREFIX . "test
WHERE columnfudge > '999'
LIMIT 1
");
$chocolate = $choc['column1'];
$vbulletin->db->query_write("
INSERT INTO " . TABLE_PREFIX . "test (column1,columnfudge) VALUES ('[2] $chocolate','0')
");
$vbulletin->db->query_write("
UPDATE test SET column1 = '[1] $chocolate' WHERE CONVERT( `column1` USING utf8 ) = 'abc'
");
log_cron_action('Hard thing done', $nextitem);
rogersnm
06-25-2006, 12:44 PM
Thanks mate, works now. With a few tweaks.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.