View Full Version : need some mysql help
invalid
March 26th, 2002, 17:29
usually i'm the one "helping" people, but now i need some help.
i need to run a mqsql query that selects the table "codes" where platid equals $id and where firstletter equals $letter
here's what i tried:
$query = "SELECT * FROM games WHERE platid=$id AND firstletter=$letter limit 0,30";
$query = "SELECT * FROM games WHERE platid=$id AND WHERE firstletter=$letter limit 0,30";
$query = "SELECT * FROM games WHERE platid=$id firstletter=$letter limit 0,30";
Dusty
March 26th, 2002, 17:32
I would use
SELECT * FROM games WHERE platid LIKE '$id' AND firstletter LIKE '$letter' LIMIT 0,30
invalid
March 26th, 2002, 17:35
THANKS!!! it worked :biggrin2:
invalid
March 26th, 2002, 17:35
Oh yeah, thanks for the super quick reply too!
invalid
March 26th, 2002, 17:44
one more questions:
how can i do something like:
SELECT * FROM games WHERE platid LIKE '$id' AND firstletter LIKE 'A NUMBER'
'A NUMBER' being any number
Dusty
March 26th, 2002, 17:52
Sure.
StreetWarz
March 26th, 2002, 18:26
maybe use...
SELECT * FROM games WHERE platid LIKE '$id' AND firstletter > 0
not sure if that will work for you but it works for me in a few items..
exactly what do you want it to do... explain a little more.. and maybe there is a better way...
:)
Dusty
March 26th, 2002, 19:27
Were you saying "any number" as in you can put any number there or were you saying "any number" as in it'll match any number?
invalid
March 26th, 2002, 19:32
I have a col. in my database called firstletter... so when i want to display rows with say the first letter of A i do my query with "WHERE firstletter LIKE A", but there are some rows with the firstletter of a number.
How can i display them?
Did that clear it up?
invalid
March 26th, 2002, 19:33
Originally posted by Dusty
Were you saying "any number" as in you can put any number there or were you saying "any number" as in it'll match any number?
YES!!!
Dusty
March 26th, 2002, 19:38
Yes? Yes meaning any number you enter or yes meaning any number at all?
Anyway. If you want to just match an entered number, just do the same as with a letter, i.e. firstletter LIKE '6'. If you want to match any number, then you could do something like firstletter REGEXP "[0-9]"
invalid
March 26th, 2002, 19:42
Thanks so much guys!!! It worked!
$query = "SELECT * FROM games WHERE platid LIKE '$id' AND firstletter REGEXP '[0-9]'";
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.