0

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$

4
Contributors
13
Replies
14
Views
6 Years
Discussion Span
Last Post by -==Zero==-
Featured Replies
0

I think this is the first code

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

is this right ?

0

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);
1

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

Votes + Comments
Thanks Sir
0

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

0

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

0

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?

0

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 ?

0

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?

-1

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 ?

Votes + Comments
don't get uppity, ezzaral just said what EVERYBODY else was thinking
0

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.

0

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 :(

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.