• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

need some mysql help

invalid

New Member
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:
PHP:
$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";
 
I would use

SELECT * FROM games WHERE platid LIKE '$id' AND firstletter LIKE '$letter' LIMIT 0,30
 
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
 
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...

:)
 
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?
 
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?
 
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]"
 
Thanks so much guys!!! It worked!

PHP:
$query = "SELECT * FROM games WHERE platid LIKE '$id' AND firstletter REGEXP '[0-9]'";
 
Back
Top