Closed Thread Icon

Preserved Topic: MySQL SELECT * from.... question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=13063" title="Pages that link to Preserved Topic: MySQL SELECT * from.... question (Page 1 of 1)" rel="nofollow" >Preserved Topic: MySQL SELECT * from.... question <span class="small">(Page 1 of 1)</span>\

 
marf
Bipolar (III) Inmate

From: Canada
Insane since: Oct 2001

posted posted 02-25-2004 23:58

ok I want to do the following

" SELECT * from tutorials where cat_id='$category' ";

and

"SELECT * from tutorials order by date desc";


I want to do both of those.
Must I combine them together like so?


"SELECT * from tutorials where cat_id='$category' && order by date desc";

Will that work? I don't think it rocognizes the && symbols

synax
Maniac (V) Inmate

From: Cell 666
Insane since: Mar 2002

posted posted 02-26-2004 00:14

SELECT * FROM tutorials WHERE cat_id='$category' ORDER BY date DESC;

"Nothin' like a pro-stabbin' from a pro." -Weadah

bitdamaged
Maniac (V) Mad Scientist

From: 100101010011 <-- right about here
Insane since: Mar 2000

posted posted 02-26-2004 00:18

Nope you don't need anything

"SELECT * from tutorials where cat_id='$category' order by date desc";

You're not combining operators so it's basically three statemtents

SELECT ...
WHERE ...
ORDER BY...

( I usually write my sql like that vertically it tends to make it easier to read ).

If you are combining then it's just the word "AND"

SELECT from people
WHERE firstname = 'homer'
AND secondname = 'simpson'
ORDER BY birthdate

Second note is that it's a bad practice to use the asterisk wild card in production, only use that for testing.



.:[ Never resist a perfect moment ]:.

marf
Bipolar (III) Inmate

From: Canada
Insane since: Oct 2001

posted posted 02-26-2004 01:25

Ok,
Here is what im trying now

Code:

code:
$result=mysql_query("SELECT * from tutorials WHERE cat_id='$category' ORDER BY tname ASC)or die("Could not execute $q.".mysql_error());



Where tname is the title, and I want to list it alphabetically

But when I try that code I get this error


could not execute SELECT * from tutorials WHERE cat_id='1' ORDER BY tname ASCLIMIT 0, 5.You have an error in your SQL syntax near 'ASCLIMIT 0, 5' at line 1

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 02-26-2004 01:52

Bit, I can see some performance reasons for not using the wildcard, but I am wondering if there are more reasons that you have hidden under your cloak of knowledge to make it prohibitive for using it in a production enviornment?

-Dan-

marf
Bipolar (III) Inmate

From: Canada
Insane since: Oct 2001

posted posted 02-26-2004 03:09

Ok, I'm assuming the LIMIT 0, 5 is the Error
Could that mean it can't Sort tname by Ascending because its a varchar?

Here is my SQL table code i use to make it.


CREATE TABLE tutorials (
id int(5) DEFAULT '0' NOT NULL auto_increment,
tname varchar(50) DEFAULT '0' NOT NULL,
name varchar(50) NOT NULL,
cat_id varchar(50) NOT NULL,
entry text NOT NULL,
description text NOT NULL,
icon text NOT NULL,
date datetime NOT NULL,
PRIMARY KEY (ID)
);

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 02-26-2004 08:38

well, reading the error output, I'm seening that there's no space between ASC and LIMIT. There should be one. Even if I have no idea where you're pulling that limit from. Certainly not from the query you posted.

Edit: In addition, the php snippet containt your query is short a "

[This message has been edited by Tyberius Prime (edited 02-26-2004).]

« BackwardsOnwards »

Show Forum Drop Down Menu