Click to See Complete Forum and Search --> : Problem with SQL


swl7
04-26-2008, 10:39 AM
Hey guys I have a SQL database which has a list of games and has numbers as an id. I was wondering if anyone knows how to put an output in to a html file if a user writes something like greater than or less than an amount specified. Heres what i got so far:


$conn = pg_connect(" blah blah");
$res = pg_query ($conn, "select * from table2");
echo "<table border='1'>";
while($a = pg_fetch_row($res)) {
echo "<tr>";
for ($j = 0; $j < pg_num_fields($res); $j++){
echo "<td>" . $a[$j] . "</td>";
}
echo "</tr>";
}
echo "</table>\n";
<table>


Cheers guys!

chazzy
04-26-2008, 10:50 AM
i have no clue what you're asking for, but it looks more like a PHP question than sql.

swl7
04-26-2008, 10:57 AM
Ok I think if a users says some thing like : £100 the page will output all prices and games that are either greater than or less than the £100 hope this helps.

chazzy
04-26-2008, 11:02 AM
can you tell us more about your table? what kind of columns does it have? is price stored in it anywhere?

swl7
04-26-2008, 11:15 AM
The table has got 4 columns the first one has got a number in it for like an id the 2nd has got the name of the game, the third has got the description and fourth the price but without the £ sign.

nonamepub
04-27-2008, 12:49 PM
pg_query ($conn, "select * from table2");

So you want to display those games that are above the given price, and then display those that are below this same price??

I'd say query the database twice.
1. select game_name from table2 where price > $x
2. select game_name from table2 where price <= $x

The $x can be provided by some form input. Use PHP to pass the x value to this "processing" page.

Using the SQL to make the mathmatical comparisions is much better. Otherwise, you're going to run into problems trying to make comparisions with PHP, since the fetch_row is giving you string values, NOT integers (e.g. numbers).

swl7
04-28-2008, 10:59 AM
Thanks for your help its solved know doubt i will be back soon with another problem ha ha cheers guys