Jump to content

Archived

This topic is now archived and is closed to further replies.

Viper007Bond

Getting result(s) using mulitple constraints

Recommended Posts

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.

 

A little help please? Thanks a ton. :)

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites
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 \"&\".)

 

geardownload_table.jpg

 

geardownload_data.jpg

 

http://test.viper007bond.com/download.php?...date=2003-11-16

 

:?

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Nope.

 

geardownload_table_v2.jpg

 

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.