Viper007Bond Posted November 17, 2003 Share Posted November 17, 2003 I\'m new to MySQL and I frankly don\'t know how to do this. I need to get the value in the collumn \"url\" for the line where \"show\" is set to X and \"date\" is set to Y. I have this: [php:1:a38248ae1d]$query = mysql_query(\"SELECT * FROM $table_name WHERE show=\'fifth\' AND date=\'$date\'\"); $result = mysql_fetch_array($query); echo $result;[/php:1:a38248ae1d] but no luck. 1064: You have an error in your SQL syntax near \'show=\'fifth\' AND date=\'2003-11-16\'\' at line 1 A little help please? Thanks a ton. Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/ Share on other sites More sharing options...
shivabharat Posted November 17, 2003 Share Posted November 17, 2003 Try this $query = mysql_query("SELECT * FROM \'$table_name\' WHERE show=\'fifth\' AND date=\'$date\'") or die(mysql_error()); $result = mysql_fetch_array($query); echo $result[\'url\']; Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4555 Share on other sites More sharing options...
Viper007Bond Posted November 17, 2003 Author Share Posted November 17, 2003 You have an error in your SQL syntax near \'\'geardownload\' WHERE show=\'fifth\' AND date=\'2003-11-16\'\' at line 1 [php:1:d83d06ade9]<?php // Input format: download.php?show=______&date=______ $hostname = \"localhost\"; $database = \"<database>\"; $username = \"<username>\"; $password = \"<password>\"; $table_name = \"geardownload\"; $connection = mysql_connect($hostname,$username,$password); mysql_select_db($database,$connection); if (isset($show) && isset($date)) { if ($show == \"fifthgear\") { echo \"You picked the show Fifth Gear and the episode from $date.<br />\"; $query = mysql_query(\"SELECT * FROM \'$table_name\' WHERE show=\'fifth\' AND date=\'$date\'\") or die(mysql_error()); $result = mysql_fetch_array($query); echo $result[\'url\']; } elseif ($show == \"topgear\") { echo \"You picked the show Top Gear and the episode from \".$date.\".<br />\"; } else { echo \"You picked an invalid show.<br />\"; echo \"<br />\"; echo \"<a href=\"http://5thgear.viper007bond.com/\">Return to the site.</a>\"; } } else { echo \"You must specify both a show and an episode date.<br />\"; echo \"<br />\"; echo \"<a href=\"http://5thgear.viper007bond.com/\">Return to the site</a> to get a valid link.\"; } ?>[/php:1:d83d06ade9] (No, I don\'t have \"&\" in my code, it\'s really \"&\".) http://test.viper007bond.com/download.php?...date=2003-11-16 :? Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4556 Share on other sites More sharing options...
shivabharat Posted November 17, 2003 Share Posted November 17, 2003 Hi, Have a look at this http://www.mysql.com/doc/en/Fulltext_Search.html the issue is because you have defined the datatype as BLOB and you cant match them using the = . Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4557 Share on other sites More sharing options...
Viper007Bond Posted November 18, 2003 Author Share Posted November 18, 2003 So how should I set up my database? I can\'t make sense of that link. :? Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4576 Share on other sites More sharing options...
Viper007Bond Posted November 18, 2003 Author Share Posted November 18, 2003 Nevermind. I get what you\'re saying. I can\'t compare text collumns. Gotta use varchar or char or whatever. Thanks. Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4581 Share on other sites More sharing options...
Viper007Bond Posted November 18, 2003 Author Share Posted November 18, 2003 I\'m still getting the same SQL error. Why can\'t I just get this to work? Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4582 Share on other sites More sharing options...
mtoynbee Posted November 18, 2003 Share Posted November 18, 2003 I dont think you can call a column \"date\" can you? Check out the list of words not recommended to use in SQL elements: http://developer.mimer.se/validator/sql-re...erved-words.tml Try renaming it \"date_id\" and see if it works... Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4583 Share on other sites More sharing options...
Viper007Bond Posted November 18, 2003 Author Share Posted November 18, 2003 Nope. You have an error in your SQL syntax near \'\'geardownload\' WHERE show=\'fifth\' AND dateofshow=\'2003-11-18\'\' at line 1 *EDIT* - I removed the quotes around the table name that weren\'t supposed to be there: [php:1:59f0ba3813]$query = mysql_query(\"SELECT * FROM $table_name WHERE show=\'fifth\' AND dateofshow=\'$date\'\") or die(mysql_error()); $result = mysql_fetch_array($query); echo $result[\'fileurl\'];[/php:1:59f0ba3813] You have an error in your SQL syntax near \'show=\'fifth\' AND dateofshow=\'2003-11-18\'\' at line 1 Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4584 Share on other sites More sharing options...
mtoynbee Posted November 18, 2003 Share Posted November 18, 2003 \"SHOW\" is a reserved word, use show_name or similar. Have tested and it works. http://developer.mimer.com/validator/parse...words-sql99.tml Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4585 Share on other sites More sharing options...
Viper007Bond Posted November 18, 2003 Author Share Posted November 18, 2003 Excuse me while I pound my head with a hammer. :roll: Thanks for the help guys. Link to comment https://forums.phpfreaks.com/topic/1379-getting-results-using-mulitple-constraints/#findComment-4591 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.