Hello

first code

I need to know the code to get data from mysql table that have a letter a

i mean i have a table called "Games"

there's a games start with a b c d e f g h

I need to retrieve games That begin with (( A ))

second code

i have a field contain prices

10$
20$
30$
40$

i need to get the code to show a price from 10$ To 40$

I think this is the first code

SELECT `name`
  FROM users
 WHERE `name` LIKE 'B%'

is this right ?

Did you try it? Did it work?

commented: Thanks Sir +2

That looks correct for your first request. on the second, I am not aware of a way to do this. You cannot use any of the greater or less than opperators because the data isn't numeric. I would suggest changing this cell to an integer and if you need the dollar sign to indicate currency, put it in another cell. Alternatively if all your prices are integers you you use a for loop to build a very long query.

$query="SELECT * FROM table WHERE ";
for ($i=10;$i<=40;$i++){
   $query.= " price = '" . $i . "$' OR";
}
$query=substr($query, 0, -2);

yes, first part is seems to be correct:

SELECT `name`
    FROM users
    WHERE `name` LIKE 'A%'

But are the prices on the same table? in another column? plese provide full sql table structure and I can write you a query.

SELECT `name`, 'price'
    FROM users
    WHERE `name` LIKE 'A%'
    $retid = mysql_query($sql,$dblink) or die(mysql_error());
    
    if ($row = mysql_fetch_array($retid)) {	
         $name = $row['name'];
         $price = $row['price'];
    }
     // note will only process 1 row, if you want several use a while statement.

anyway... post db structure for more help

commented: Thanks Sir +2

Did you try it? Did it work?

Sorry Didnt Tried It Yet

That looks correct for your first request. on the second, I am not aware of a way to do this. You cannot use any of the greater or less than opperators because the data isn't numeric. I would suggest changing this cell to an integer and if you need the dollar sign to indicate currency, put it in another cell. Alternatively if all your prices are integers you you use a for loop to build a very long query.

$query="SELECT * FROM table WHERE ";
for ($i=10;$i<=40;$i++){
   $query.= " price = '" . $i . "$' OR";
}
$query=substr($query, 0, -2);

Thanks Iam Gonna Try This

yes, first part is seems to be correct:

SELECT `name`
    FROM users
    WHERE `name` LIKE 'A%'

But are the prices on the same table? in another column? plese provide full sql table structure and I can write you a query.

SELECT `name`, 'price'
    FROM users
    WHERE `name` LIKE 'A%'
    $retid = mysql_query($sql,$dblink) or die(mysql_error());
    
    if ($row = mysql_fetch_array($retid)) {	
         $name = $row['name'];
         $price = $row['price'];
    }
     // note will only process 1 row, if you want several use a while statement.

anyway... post db structure for more help

Thanks So Much I Will try This If I Failed I Will Post My Full Code

Sorry Didnt Tried It Yet

Why bother to post this at all then? If you aren't willing to even try out any code on your own, why should others spend their time on it?

Why bother to post this at all then? If you aren't willing to even try out any code on your own, why should others spend their time on it?

Coz Iam Trying The Other Code And When I Finish I Will Use It So Iam Asking First

Did You Get It ?

That makes no sense at all.

Why not type the code into a simple query against your data and see if it works before you post it to a forum and ask others if it looks right?

That makes no sense at all.

Why not type the code into a simple query against your data and see if it works before you post it to a forum and ask others if it looks right?

Hey Hey After I Posted The Topic I Found The Code On Google

So I Ask First Did You Get That ?

commented: don't get uppity, ezzaral just said what EVERYBODY else was thinking -3

It seems rather lazy and unproductive to me.

You could have tried it out yourself first and then if it didn't work you could have posted "Hey, I tried this... but it gave me this... what do I need to change?" If it did work, you could focus directly on the other query without taking up any more time on the first.

It seems rather lazy and unproductive to me.

You could have tried it out yourself first and then if it didn't work you could have posted "Hey, I tried this... but it gave me this... what do I need to change?" If it did work, you could focus directly on the other query without taking up any more time on the first.

Yes I Was Lazy Iam Sorry For That In The Next Time I Will try To Do My Best Before Posting Thread :(

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.