Jump to content

Getting result(s) using mulitple constraints


Viper007Bond

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. :)

Link to comment
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

 

:?

Link to comment
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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.