[PHP-DB] Query and math

2003-12-16 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 Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] silly problem

2003-07-22 Thread Patrik Fomin

  $sql = UPDATE dagensfraga SET nej = '$nej' WHERE id = '$iid' AND
aktuellfraga = '1';
  mysql_query($sql);
 $sql = INSERT INTO dagensfragaip (aid, ip) VALUES('$iid',
'$REMOTE_ADDR');
 mysql_query(sql);

when i run this only the first line is recorded into the databse?,
when i run the second line in a mysql_prompt it adds just fine, so why
dosent it add when the script runs?



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



Re: [PHP-DB] silly problem

2003-07-22 Thread Patrik Fomin
yeah ofcourse, sometimes u can go blind stairing at the code and still not
see it :D

thanks
Edward Peloke [EMAIL PROTECTED] skrev i meddelandet
news:[EMAIL PROTECTED]
 you are missing the $ sign on your second mysql_query call

 -Original Message-
 From: Patrik Fomin [mailto:[EMAIL PROTECTED]
 Sent: Tuesday, July 22, 2003 4:41 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP-DB] silly problem



   $sql = UPDATE dagensfraga SET nej = '$nej' WHERE id = '$iid' AND
 aktuellfraga = '1';
   mysql_query($sql);
  $sql = INSERT INTO dagensfragaip (aid, ip) VALUES('$iid',
 '$REMOTE_ADDR');
  mysql_query(sql);

 when i run this only the first line is recorded into the databse?,
 when i run the second line in a mysql_prompt it adds just fine, so why
 dosent it add when the script runs?



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




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



[PHP-DB] Hi, simple question

2003-07-01 Thread Patrik Fomin
Hi,

im adding a post to the database, is there any way to retrive back the ID
for the post that i just created?

the id is auto_increment and primary key.

like
$sql = insert into test (namn, www) values('test', 'test.com');
mysql_query($sql);

$row = mysql_get_post(id);
?

the only way i could think of was to create a tempfield in the database and
each time you post you give the temp field a unique value, like:

$sql = insert into test (namn, www, unique) values('test',
'test.com','25323324');
mysql_query($sql);

$sql = select id from test where unique = '25323324';
$res = mysql_query($sql);


regards
patrick



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