Jump to content


Photo

Getting result(s) using mulitple constraints


  • Please log in to reply
10 replies to this topic

#1 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 17 November 2003 - 08:17 AM

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[url];[/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. :)
- Viper007Bond

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 17 November 2003 - 09:00 AM

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\'];

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 17 November 2003 - 09:27 AM

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 \"&amp;\" in my code, it\'s really \"&\".)

Posted Image

Posted Image

http://test.viper007...date=2003-11-16

:?
- Viper007Bond

#4 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 17 November 2003 - 09:55 AM

Hi,

Have a look at this

http://www.mysql.com...ext_Search.html

the issue is because you have defined the datatype as BLOB and you cant match them using the = .
Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#5 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 18 November 2003 - 06:06 AM

So how should I set up my database? I can\'t make sense of that link. :?
- Viper007Bond

#6 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 18 November 2003 - 10:55 AM

Nevermind. I get what you\'re saying. I can\'t compare text collumns. Gotta use varchar or char or whatever. Thanks. :)
- Viper007Bond

#7 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 18 November 2003 - 11:18 AM

I\'m still getting the same SQL error. :cry: Why can\'t I just get this to work?
- Viper007Bond

#8 mtoynbee

mtoynbee
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationHythe, SE England

Posted 18 November 2003 - 11:55 AM

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.mim...erved-words.tml

Try renaming it \"date_id\" and see if it works...

#9 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 18 November 2003 - 12:02 PM

Nope.

Posted Image

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


- Viper007Bond

#10 mtoynbee

mtoynbee
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationHythe, SE England

Posted 18 November 2003 - 12:33 PM

\"SHOW\" is a reserved word, use show_name or similar. Have tested and it works.

http://developer.mim...words-sql99.tml

#11 Viper007Bond

Viper007Bond
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationPortland, Oregon, USA

Posted 18 November 2003 - 03:17 PM

Excuse me while I pound my head with a hammer. :roll:

Thanks for the help guys. :)
- Viper007Bond




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users