[PHP] sql query and some math

2003-12-17 Thread Patrik Fomin
Hi,

q1)
i got a database with 2 diffrent tables,
i want to take out all the information that arent duplicated from
on of the tables, like this:

$sql = SELECT t1.rubrik, t1.info, t2.priser FROM table1 AS t1, table2 AS t2
WHERE t1.arkiv = '0' ORDER BY t1.rubrik;

the problem is that i got alot of duplicates (its for another purpose), so i
need to filter out the duplicates in the rubrik field to get just one match
each, like:

id - rubrik - info

0 -  - some info
1 -  - some info
2 -  - some info
3 -  - some info
4 -  - some info

would print out
0 -  - some info
1 -  - some info
2 -  - some info
3 -  - some info


q2)
i got like 100 matches from a database into a $num variable,
then i want to devide that by 3 aslong as it can be done, eg:

while ($num != 0) {

ïf ($num / 3 = true){
some code to display some fields from a database

$num = $num - 3;
}
else {
some other code to display
$num = 0;
}
}

basicly i want the if statement to check if its more then 3 posts left to
print out, if not its gonna print out the remaining last 1 - 2 post in a
diffrent way (for the looks)


regards
patrick

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] sql query and some math

2003-12-17 Thread Jay Blanchard
[snip]
q1)
i got a database with 2 diffrent tables,
i want to take out all the information that arent duplicated from
on of the tables, like this:

$sql = SELECT t1.rubrik, t1.info, t2.priser FROM table1 AS t1, table2 AS t2
WHERE t1.arkiv = '0' ORDER BY t1.rubrik;
[/snip]

It's a SQL question, but I'll answer...

$sql = SELECT DISTINCT(t1.rubrik), t1.info, t2.priser FROM table1 AS t1, table2 AS t2
WHERE t1.arkiv = '0' ORDER BY t1.rubrik;

[snip]
q2)
i got like 100 matches from a database into a $num variable,
then i want to devide that by 3 aslong as it can be done, eg:

while ($num != 0) {

ïf ($num / 3 = true){
some code to display some fields from a database

$num = $num - 3;
}
else {
some other code to display
$num = 0;
}
}

basicly i want the if statement to check if its more then 3 posts left to
print out, if not its gonna print out the remaining last 1 - 2 post in a
diffrent way (for the looks)
[/snip]

if(($num / 3) == true)

Happy Holidays!

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php