Jump to content


Photo

Query


  • Please log in to reply
6 replies to this topic

#1 rh91uk

rh91uk
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 June 2006 - 12:38 PM

Hiya

I haveb a php script set up, but I want the folllowing query to display only records whos type fields are set up as, "Web Design"

SELECT title, id, type, description, updated FROM portfolio ORDER BY id DES

Probably simple for some people, hehe

thanx,


Richard

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 22 June 2006 - 12:41 PM

[!--quoteo(post=386810:date=Jun 22 2006, 08:38 AM:name=rh91uk)--][div class=\'quotetop\']QUOTE(rh91uk @ Jun 22 2006, 08:38 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hiya

I haveb a php script set up, but I want the folllowing query to display only records whos type fields are set up as, "Web Design"

SELECT title, id, type, description, updated FROM portfolio ORDER BY id DES

Probably simple for some people, hehe

thanx,
Richard
[/quote]

this is where your WHERE clause comes in:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] title, id, type, description, [span style=\'color:blue;font-weight:bold\']update[/span]d FROM portfolio WHERE type = 'Web Design' ORDER BY id DESC [!--sql2--][/div][!--sql3--]

good luck
You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx

#3 rh91uk

rh91uk
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 June 2006 - 12:45 PM

Thank you kind sir ;)

Am going to go try it out now!




#4 rh91uk

rh91uk
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 June 2006 - 12:55 PM

[!--quoteo(post=386811:date=Jun 22 2006, 07:41 AM:name=obsidian)--][div class=\'quotetop\']QUOTE(obsidian @ Jun 22 2006, 07:41 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
this is where your WHERE clause comes in:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] title, id, type, description, [span style=\'color:blue;font-weight:bold\']update[/span]d FROM portfolio WHERE type = 'Web Design' ORDER BY id DESC [!--sql2--][/div][!--sql3--]

good luck
[/quote]

Parse error: parse error, unexpected T_STRING in e:\domains\n\notonlybutalso.net\user\htdocs\richardcmstest\websites.php on line 162

Line 162 is :

$result = @mysql_query('SELECT title, id, type, description, updated FROM portfolio WHERE type = 'Web Design' ORDER BY id DESC'); 


#5 Wildbug

Wildbug
  • Members
  • PipPipPip
  • Advanced Member
  • 1,149 posts

Posted 22 June 2006 - 02:32 PM

[!--quoteo(post=386814:date=Jun 22 2006, 08:55 AM:name=rh91uk)--][div class=\'quotetop\']QUOTE(rh91uk @ Jun 22 2006, 08:55 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Parse error: parse error, unexpected T_STRING in e:\domains\n\notonlybutalso.net\user\htdocs\richardcmstest\websites.php on line 162

Line 162 is :

$result = @mysql_query('SELECT title, id, type, description, updated FROM portfolio WHERE type = 'Web Design' ORDER BY id DESC'); 
[/quote]

Either escape the single quotes (\') or use double quotes.
Twice a day my clock works PERFECTLY!  I can't figure out what's wrong with it.

#6 rh91uk

rh91uk
  • Members
  • PipPip
  • Member
  • 15 posts

Posted 22 June 2006 - 03:40 PM

Hmmm that doesnt seem to want to work either

Any other ideas anyone?

#7 Wildbug

Wildbug
  • Members
  • PipPipPip
  • Advanced Member
  • 1,149 posts

Posted 22 June 2006 - 05:23 PM

[!--quoteo(post=386853:date=Jun 22 2006, 11:40 AM:name=rh91uk)--][div class=\'quotetop\']QUOTE(rh91uk @ Jun 22 2006, 11:40 AM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hmmm that doesnt seem to want to work either

Any other ideas anyone?
[/quote]

If the code you've posted is what you're using, then you're getting a "unexpected T_STRING" parse error because you're using single quotes within single quotes. PHP thinks you're ending your string when you just want to quote 'Web Design.'

Use any of the following:
$result = @mysql_query('SELECT title, id, type, description, updated FROM portfolio WHERE type = "Web Design" ORDER BY id DESC');
$result = @mysql_query("SELECT title, id, type, description, updated FROM portfolio WHERE type = 'Web Design' ORDER BY id DESC");
$result = @mysql_query('SELECT title, id, type, description, updated FROM portfolio WHERE type = \'Web Design\' ORDER BY id DESC');
$result = @mysql_query("SELECT title, id, type, description, updated FROM portfolio WHERE type = \"Web Design\" ORDER BY id DESC");

Twice a day my clock works PERFECTLY!  I can't figure out what's wrong with it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users