PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Jun 15, 2010 12:33 pm
Code: Select all
<?php
$filename = "keywords.txt";
$filehandle = fopen($filename, 'w') or die("can't open file");
include("config.php");
$query="select * from downloads";
$result=mysql_query($query) or die(mysql_error());
$query1="update downloads set keyword=1 where release=1";
mysql_query($query1) or die(mysql_error());
while($word=mysql_fetch_array($result,MYSQL_BOTH))
{
if($word['release']==1)
{
$string=$string." ".$word['title'];
}
}
fwrite($filehandle, $string);
fclose($filehandle);
?>
the below line
Code: Select all
$query1="update downloads set keyword=1 where release=1";
is giving this error
Code: Select all
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'release=1' at line 1...whats wrong with update query?
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Jun 15, 2010 12:42 pm
release is a reserved word. wrap tics around it:
Code: Select all
update downloads set keyword=1 where `release`=1
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Jun 15, 2010 1:16 pm
k now error gone away buts it not setting the keyword value to 1 where release=1
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Jun 15, 2010 1:38 pm
run this, and let me know the result:
Code: Select all
SELECT COUNT(*) FROM downloads WHERE `release`=1;
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Jun 15, 2010 1:47 pm
is keyword an enum, or a char?
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Jun 15, 2010 1:53 pm
ok, do this then:
Code: Select all
SELECT COUNT(*) FROM downloads WHERE keyword = 1;
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Jun 15, 2010 1:59 pm
right now value for the keyword column is null so this will give a zero..i checked it its a zero
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Jun 15, 2010 2:06 pm
Could you give me a "SHOW CREATE TABLE downloads"?
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Jun 15, 2010 2:08 pm
i am not getting this there are 30 rows for which release has the value =1 but when i run this query
Code: Select all
update downloads set keyword=1 where 'release'=1
it says zero rows effetecd even when the value of rows in keyword column is zero
andyhoneycutt
Forum Contributor
Posts: 468 Joined: Wed Aug 27, 2008 10:02 am
Location: Idaho Falls
Post
by andyhoneycutt » Tue Jun 15, 2010 2:10 pm
Oh, use backticks as I showed above: ` not '
' is for values.
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Jun 15, 2010 2:11 pm
here it goes
Code: Select all
CREATE TABLE IF NOT EXISTS `downloads` (
`title` text,
`downloadlink` text,
`pagelink` text,
`category` text,
`release` int(1) NOT NULL,
`id` int(11) NOT NULL AUTO_INCREMENT,
`keyword` int(1) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=376 ;
mayanktalwar1988
Forum Contributor
Posts: 133 Joined: Wed Jul 08, 2009 2:44 am
Post
by mayanktalwar1988 » Tue Jun 15, 2010 2:13 pm
k i mistaken back ticks for single inverted commas sorry i wasted your time..thanks