[PHP-DB] table join
Hi everyone I'm having a whole lot of fun playing with this project. It just keeps expanding and taking me to new territory and I'm really enjoying it. I got a quick question though. I've been playing around with table joins and I tried to join based on the ID but I quickly realized this is not a good solutions, because the ID's in each table aren't always going to match. This is a simple join that I was messing around with: $sql = 'SELECT * FROM inventory, extended_info WHERE inventory.id = extended_info.id'; So I'm wondering if I should figure a way to always make my ID's in each table match, which is probably not possible or I'm thinking a unique field for both tables and use that to match up the records, but I know zilch about cars (funny considering what I chose to start with) and I couldn't think of 1 thing that would be unique to match up... LOL so what would be a wise way to go about this type of thing. PS I'm not looking for code, just some feedback on logic. -- Regards David M.
Re: [PHP-DB] table join
On Tuesday, September 04, 2012 06:27:43 PM David McGlone wrote: Hi everyone I'm having a whole lot of fun playing with this project. It just keeps expanding and taking me to new territory and I'm really enjoying it. I got a quick question though. I've been playing around with table joins and I tried to join based on the ID but I quickly realized this is not a good solutions, because the ID's in each table aren't always going to match. This is a simple join that I was messing around with: $sql = 'SELECT * FROM inventory, extended_info WHERE inventory.id = extended_info.id'; So I'm wondering if I should figure a way to always make my ID's in each table match, which is probably not possible or I'm thinking a unique field for both tables and use that to match up the records, but I know zilch about cars (funny considering what I chose to start with) and I couldn't think of 1 thing that would be unique to match up... LOL so what would be a wise way to go about this type of thing. PS I'm not looking for code, just some feedback on logic. I don't think I should reply to my own post, but I had a light bulb go off and I'm thinking maybe I should get the last inserted record and work it from there. Is that smart? -- Regards David M.
Re: [PHP-DB] table join
On Sep 4, 2012, at 5:27 PM, David McGlone wrote: Hi everyone I'm having a whole lot of fun playing with this project. It just keeps expanding and taking me to new territory and I'm really enjoying it. I got a quick question though. I've been playing around with table joins and I tried to join based on the ID but I quickly realized this is not a good solutions, because the ID's in each table aren't always going to match. This is a simple join that I was messing around with: $sql = 'SELECT * FROM inventory, extended_info WHERE inventory.id = extended_info.id'; So I'm wondering if I should figure a way to always make my ID's in each table match, which is probably not possible or I'm thinking a unique field for both tables and use that to match up the records, but I know zilch about cars (funny considering what I chose to start with) and I couldn't think of 1 thing that would be unique to match up... LOL so what would be a wise way to go about this type of thing. PS I'm not looking for code, just some feedback on logic. -- Regards David M. I think your needing to do something like this. $sql = 'SELECT in.id FROM inventory in, extended_info ex WHERE in.id = ex.id'; Karl DeSaulniers Design Drumm http://designdrumm.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table html with PHP
Hello everyone, I need to know how do I do a two columns table with a register per cell. table tr ?php $i = 0; while(array) { echo td$varible[0]/td; } j++ if j 2 echo /tr ? /table this dont work very well. Thanks a lot
RE: [PHP-DB] table html with PHP
I assume you're looking for something like: table tr ?php $i = 0; while(array) { echo td$varible[0]/td; $i++; If ($i1) { $i=0; echo '/trtr'; } } ? /tr /table -Original Message- From: Emiliano Boragina [mailto:emiliano.borag...@gmail.com] Sent: Tuesday, June 15, 2010 3:21 PM To: php-db@lists.php.net Subject: [PHP-DB] table html with PHP Hello everyone, I need to know how do I do a two columns table with a register per cell. table tr ?php $i = 0; while(array) { echo td$varible[0]/td; } j++ if j 2 echo /tr ? /table this dont work very well. Thanks a lot -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] table html with PHP
sorry... why $i = 0 again? 2010/6/15 Systems syst...@3dgtech.com I assume you're looking for something like: table tr ?php $i = 0; while(array) { echo td$varible[0]/td; $i++; If ($i1) { $i=0; echo '/trtr'; } } ? /tr /table -Original Message- From: Emiliano Boragina [mailto:emiliano.borag...@gmail.com] Sent: Tuesday, June 15, 2010 3:21 PM To: php-db@lists.php.net Subject: [PHP-DB] table html with PHP Hello everyone, I need to know how do I do a two columns table with a register per cell. table tr ?php $i = 0; while(array) { echo td$varible[0]/td; } j++ if j 2 echo /tr ? /table this dont work very well. Thanks a lot
Re: [PHP-DB] table html with PHP
sorry again... thanks for your answer... 2010/6/15 Emiliano Boragina emiliano.borag...@gmail.com sorry... why $i = 0 again? 2010/6/15 Systems syst...@3dgtech.com I assume you're looking for something like: table tr ?php $i = 0; while(array) { echo td$varible[0]/td; $i++; If ($i1) { $i=0; echo '/trtr'; } } ? /tr /table -Original Message- From: Emiliano Boragina [mailto:emiliano.borag...@gmail.com] Sent: Tuesday, June 15, 2010 3:21 PM To: php-db@lists.php.net Subject: [PHP-DB] table html with PHP Hello everyone, I need to know how do I do a two columns table with a register per cell. table tr ?php $i = 0; while(array) { echo td$varible[0]/td; } j++ if j 2 echo /tr ? /table this dont work very well. Thanks a lot
Re: [PHP-DB] table html with PHP
thank youu... work... I understand why the $i = 0 again... thanks thanks thanks 2010/6/15 Systems syst...@3dgtech.com I assume you're looking for something like: table tr ?php $i = 0; while(array) { echo td$varible[0]/td; $i++; If ($i1) { $i=0; echo '/trtr'; } } ? /tr /table -Original Message- From: Emiliano Boragina [mailto:emiliano.borag...@gmail.com] Sent: Tuesday, June 15, 2010 3:21 PM To: php-db@lists.php.net Subject: [PHP-DB] table html with PHP Hello everyone, I need to know how do I do a two columns table with a register per cell. table tr ?php $i = 0; while(array) { echo td$varible[0]/td; } j++ if j 2 echo /tr ? /table this dont work very well. Thanks a lot
RE: [PHP-DB] table html with PHP
Sure thing, Eli (you might need to revisit the variable index - $variable[0], since this will return the same var all the time. unless of course that's what you want to do.) From: Emiliano Boragina [mailto:emiliano.borag...@gmail.com] Sent: Tuesday, June 15, 2010 4:16 PM To: Systems Cc: php-db@lists.php.net Subject: Re: [PHP-DB] table html with PHP thank youu... work... I understand why the $i = 0 again... thanks thanks thanks 2010/6/15 Systems syst...@3dgtech.com I assume you're looking for something like: table tr ?php $i = 0; while(array) { echo td$varible[0]/td; $i++; If ($i1) { $i=0; echo '/trtr'; } } ? /tr /table -Original Message- From: Emiliano Boragina [mailto:emiliano.borag...@gmail.com] Sent: Tuesday, June 15, 2010 3:21 PM To: php-db@lists.php.net Subject: [PHP-DB] table html with PHP Hello everyone, I need to know how do I do a two columns table with a register per cell. table tr ?php $i = 0; while(array) { echo td$varible[0]/td; } j++ if j 2 echo /tr ? /table this dont work very well. Thanks a lot
Re: [PHP-DB] Table optimization ideas needed
On Thu, Mar 27, 2008 at 1:55 PM, Chris [EMAIL PROTECTED] wrote: Good idea. But I wonder whether calling the trigger each insert will loose any performance. It's going to affect things slightly but whether it'll be noticable only you can answer by testing. Another option I sometimes see is set up a replicated slave and run your reports off that instead of the live system, then: 1) it won't bog the live db down 2) it doesn't really matter how many queries you run 3) it doesn't really matter how long they take to run Hm... This makes sense. :) I indeed have several slaves running. Great. Thank you. Thank you for all your help. -- Postgresql php tutorials http://www.designmagick.com/ -- Regards, Shelley
Re: [PHP-DB] Table optimization ideas needed
Thank you very much, Chris. :) Fyi, On Wed, Mar 26, 2008 at 1:27 PM, Chris [EMAIL PROTECTED] wrote: Shelley wrote: +--+---+--+-+---++ | Field| Type | Null | Key | Default | Extra | +--+---+--+-+---++ | id | int(11) | | PRI | NULL | auto_increment | | owner_id | int(11) | | MUL | 0 || | owner_name | varchar(50) | | | || | visitor_id | int(11) | | MUL | 0 || | visitor_name | varchar(100) | | | || | visit_time | timestamp | YES | | CURRENT_TIMESTAMP || | first_time | int(10) unsigned | | | 0 || | last_time| int(10) unsigned | | MUL | 0 || | visit_num| mediumint(8) unsigned | | | 0 || | status | tinyint(3) unsigned | | MUL | 0 || +--+---+--+-+---++ That's the table which has more than 20 million records. And what query are you running? What does: explain your_query_here; show? mysql explain select count(*) from message; ++-+-+---+---++-+--+--+-+ | id | select_type | table | type | possible_keys | key| key_len | ref | rows | Extra | ++-+-+---+---++-+--+--+-+ | 1 | SIMPLE | message | index | NULL | status | 1 | NULL | 23051499 | Using index | ++-+-+---+---++-+--+--+-+ Three queries return the same results. I can see indexes on at least owner_id, visitor_id, last_time and status, but at least one of those is across multiple columns ('MUL'). Can you show us the index definitions: show indexes from table_name; or show create table table_name; and just include the indexes at the bottom. mysql show indexes from message; +-+++--+-+---+-+--++--++-+ | Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | +-+++--+-+---+-+--++--++-+ | message | 0 | PRIMARY|1 | id | A |23051499 | NULL | NULL | | BTREE | | | message | 1 | owner_id |1 | owner_id| A | 922059 | NULL | NULL | | BTREE | | | message | 1 | visitor_id |1 | visitor_id | A | 501119 | NULL | NULL | | BTREE | | | message | 1 | status |1 | status | A | 18 | NULL | NULL | | BTREE | | | message | 1 | last_time |1 | last_time | A |11525749 | NULL | NULL | | BTREE | | +-+++--+-+---+-+--++--++-+ 5 rows in set (1.09 sec) -- Postgresql php tutorials http://www.designmagick.com/ -- Regards, Shelley
Re: [PHP-DB] Table optimization ideas needed
mysql explain select count(*) from message; ++-+-+---+---++-+--+--+-+ | id | select_type | table | type | possible_keys | key| key_len | ref | rows | Extra | ++-+-+---+---++-+--+--+-+ | 1 | SIMPLE | message | index | NULL | status | 1 | NULL | 23051499 | Using index | ++-+-+---+---++-+--+--+-+ Three queries return the same results. That's never going to be fast because you're using innodb tables. From a previous post: Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? I thought that's what you needed help with. ? -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table optimization ideas needed
On Thu, Mar 27, 2008 at 10:03 AM, Chris [EMAIL PROTECTED] wrote: mysql explain select count(*) from message; ++-+-+---+---++-+--+--+-+ | id | select_type | table | type | possible_keys | key| key_len | ref | rows | Extra | ++-+-+---+---++-+--+--+-+ | 1 | SIMPLE | message | index | NULL | status | 1 | NULL | 23051499 | Using index | ++-+-+---+---++-+--+--+-+ Three queries return the same results. That's never going to be fast because you're using innodb tables. Should I change it to MyISAM ones? From a previous post: Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? I thought that's what you needed help with. ? No. That's only part of it. I have a cron job, which get the total visits often. -- Postgresql php tutorials http://www.designmagick.com/ -- Regards, Shelley
Re: [PHP-DB] Table optimization ideas needed
That's never going to be fast because you're using innodb tables. Should I change it to MyISAM ones? It depends. Do you need or use transactions? You can't change - myisam doesn't support them. No. That's only part of it. I have a cron job, which get the total visits often. If you are using mysql 5.0+, use a trigger to update a counter: It'll depend on your data set and what you need to get out of the data (ie what queries you are running) but if you just need a total or even total per day, this would be the best. Might need to do it as a stored procedure so you can see if the date already exists in that table so you can either do an update or insert, or maybe you can use replace into without needing to do that check. See http://dev.mysql.com/doc/refman/5.0/en/using-triggers.html and http://dev.mysql.com/doc/refman/5.0/en/triggers.html - and look at the comments: Triggers can call 'CALL' method. DROP TRIGGER cinema.TESTTRIGGER; CREATE TRIGGER cinema.TESTTRIGGER AFTER INSERT ON film FOR EACH ROW CALL cinema.CHECKFILM('Old boy'); It works. The trigger is perform and do its job. The only request is to use the word 'AFTER' when you call your trigger. 'BEFORE' doesn't work (the trigger is called ans work but the insert failed in all case). -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table optimization ideas needed
On Thu, Mar 27, 2008 at 10:40 AM, Chris [EMAIL PROTECTED] wrote: That's never going to be fast because you're using innodb tables. Should I change it to MyISAM ones? It depends. Do you need or use transactions? You can't change - myisam doesn't support them. I haven't tried transactions so far. :( No. That's only part of it. I have a cron job, which get the total visits often. If you are using mysql 5.0+, use a trigger to update a counter: It is 5.0+. It'll depend on your data set and what you need to get out of the data (ie what queries you are running) but if you just need a total or even total per day, this would be the best. Good idea. But I wonder whether calling the trigger each insert will loose any performance. Might need to do it as a stored procedure so you can see if the date already exists in that table so you can either do an update or insert, or maybe you can use replace into without needing to do that check. See http://dev.mysql.com/doc/refman/5.0/en/using-triggers.html and http://dev.mysql.com/doc/refman/5.0/en/triggers.html - and look at the comments: Triggers can call 'CALL' method. DROP TRIGGER cinema.TESTTRIGGER; CREATE TRIGGER cinema.TESTTRIGGER AFTER INSERT ON film FOR EACH ROW CALL cinema.CHECKFILM('Old boy'); It works. The trigger is perform and do its job. The only request is to use the word 'AFTER' when you call your trigger. 'BEFORE' doesn't work (the trigger is called ans work but the insert failed in all case). -- Postgresql php tutorials http://www.designmagick.com/ -- Regards, Shelley
Re: [PHP-DB] Table optimization ideas needed
Good idea. But I wonder whether calling the trigger each insert will loose any performance. It's going to affect things slightly but whether it'll be noticable only you can answer by testing. Another option I sometimes see is set up a replicated slave and run your reports off that instead of the live system, then: 1) it won't bog the live db down 2) it doesn't really matter how many queries you run 3) it doesn't really matter how long they take to run -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table optimization ideas needed
Yes, Index can help a lot. But actually there has been five indices. The table takes 1.4G space while the indices take 2.3G. The select sentence is still slow. :( On Tue, Mar 25, 2008 at 11:50 AM, Chris [EMAIL PROTECTED] wrote: Shelley wrote: Hi all, I made a post a week ago to ask for the idea of the fastest way to get table records. Fyi, http://phparch.cn/index.php/mysql/35-MySQL-programming/126-fastest-way-to-get-total-records-from-a-table Look at the time even a 'count(1)' took. Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? I pretty much follow what I've said in this article: http://www.designmagick.com/article/16/PostgreSQL/How-to-index-a-database -- Postgresql php tutorials http://www.designmagick.com/ -- Regards, Shelley
Re: [PHP-DB] Table optimization ideas needed
Shelley wrote: Yes, Index can help a lot. But actually there has been five indices. The table takes 1.4G space while the indices take 2.3G. The select sentence is still slow. :( Post your exact query, table definition(s), indexes and see if anyone has some suggestions. If it's a mysql db, join one of the mysql lists and see if anyone has some suggestions (though they will ask for the same info). Same for any other db. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table optimization ideas needed
+--+---+--+-+---++ | Field| Type | Null | Key | Default | Extra | +--+---+--+-+---++ | id | int(11) | | PRI | NULL | auto_increment | | owner_id | int(11) | | MUL | 0 || | owner_name | varchar(50) | | | || | visitor_id | int(11) | | MUL | 0 || | visitor_name | varchar(100) | | | || | visit_time | timestamp | YES | | CURRENT_TIMESTAMP || | first_time | int(10) unsigned | | | 0 || | last_time| int(10) unsigned | | MUL | 0 || | visit_num| mediumint(8) unsigned | | | 0 || | status | tinyint(3) unsigned | | MUL | 0 || +--+---+--+-+---++ That's the table which has more than 20 million records. On Wed, Mar 26, 2008 at 10:20 AM, Chris [EMAIL PROTECTED] wrote: Shelley wrote: Yes, Index can help a lot. But actually there has been five indices. The table takes 1.4G space while the indices take 2.3G. The select sentence is still slow. :( Post your exact query, table definition(s), indexes and see if anyone has some suggestions. If it's a mysql db, join one of the mysql lists and see if anyone has some suggestions (though they will ask for the same info). Same for any other db. -- Postgresql php tutorials http://www.designmagick.com/ -- Regards, Shelley
Re: [PHP-DB] Table optimization ideas needed
Shelley wrote: +--+---+--+-+---++ | Field| Type | Null | Key | Default | Extra | +--+---+--+-+---++ | id | int(11) | | PRI | NULL | auto_increment | | owner_id | int(11) | | MUL | 0 || | owner_name | varchar(50) | | | || | visitor_id | int(11) | | MUL | 0 || | visitor_name | varchar(100) | | | || | visit_time | timestamp | YES | | CURRENT_TIMESTAMP || | first_time | int(10) unsigned | | | 0 || | last_time| int(10) unsigned | | MUL | 0 || | visit_num| mediumint(8) unsigned | | | 0 || | status | tinyint(3) unsigned | | MUL | 0 || +--+---+--+-+---++ That's the table which has more than 20 million records. And what query are you running? What does: explain your_query_here; show? I can see indexes on at least owner_id, visitor_id, last_time and status, but at least one of those is across multiple columns ('MUL'). Can you show us the index definitions: show indexes from table_name; or show create table table_name; and just include the indexes at the bottom. -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table optimization ideas needed
Hi all, I made a post a week ago to ask for the idea of the fastest way to get table records. Fyi, http://phparch.cn/index.php/mysql/35-MySQL-programming/126-fastest-way-to-get-total-records-from-a-table Look at the time even a 'count(1)' taken. Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? Thanks in advance. -- Regards, Shelley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table optimization ideas needed
Hi all, I made a post a week ago to ask for the idea of the fastest way to get table records. Fyi, http://phparch.cn/index.php/mysql/35-MySQL-programming/126-fastest-way-to-get-total-records-from-a-table Look at the time even a 'count(1)' took. Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? Thanks in advance. -- Regards, Shelley -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table optimization ideas needed
Shelley wrote: Hi all, I made a post a week ago to ask for the idea of the fastest way to get table records. Fyi, http://phparch.cn/index.php/mysql/35-MySQL-programming/126-fastest-way-to-get-total-records-from-a-table Look at the time even a 'count(1)' took. Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? I pretty much follow what I've said in this article: http://www.designmagick.com/article/16/PostgreSQL/How-to-index-a-database -- Postgresql php tutorials http://www.designmagick.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table optimization ideas needed
From a quick perusal of the article Chris mentions, I'd generally agree with that view about table optimization -- I'm not an expert on Postgres, but the recommendations generally seem to apply to MySQL as well. My basic view is that, if you are routinely doing a select on millions of rows, you probably need to take a step back and consider your general structure. Without revising the structure and other than indexing as Chris suggested, a couple off-the-cuff ideas: if the stability of the table is not critical, use MyISAM tables rather than InnoDB tables; try using stored procedures (MySQL=5.0). While it isn't always true, my experience is that any table with a million rows or more is a problem created because the initial assumption was that the table would never grow that large so the general data structure was not fully thought through. Google is capable of handling searches through billions of rows of data not because it uses supercomputers but because of its data structure. Just my two centavos, Jeff Chris wrote: Shelley wrote: Hi all, I made a post a week ago to ask for the idea of the fastest way to get table records. Fyi, http://phparch.cn/index.php/mysql/35-MySQL-programming/126-fastest-way-to-get-total-records-from-a-table Look at the time even a 'count(1)' took. Then you can imagine how much time sql such as select a,b from table_name where c='d' will take. I have a lot of tables like that. So my questions is: What's your practice to optimize tables like that? I pretty much follow what I've said in this article: http://www.designmagick.com/article/16/PostgreSQL/How-to-index-a-database -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table
I think I should be something like this: table width=50% border=0 cellspacing=7 cellpadding=0 tr td?php echo img src='/album/img/.$photoFileName[2].'/ ; ?/td td?php echo img src='/album/img/.$photoFileName[3].'/ ; ?/td /tr tr tdnbsp;/td td?php echo img src='/album/img/.$photoFileName[0].'/ ; ?/td /tr /table - Looking for earth-friendly autos? Browse Top Cars by Green Rating at Yahoo! Autos' Green Center.
Re: [PHP-DB] Table sorting problem - further thought
At 10:16 PM 1/12/2006, Miles Thompson wrote: At 05:51 PM 1/12/2006, Charles River wrote: I am a novice in both PHP and MySQL, otherwise I would be able to do this myself. :-) A non-profit I assist has a table (http://www.lbc4cc.org/04-05board.php) that is displayed by a simple PHP script. That was fine last year, but now we have some new officers and some new board members and I have no idea how to change the script so that Officers and Members table is presented officers first (Pres, Vice-pres, Sec and Treas) and then an alpha listing of board members who are not officers. The existing script looks like this: ?php $sql = SELECT * FROM members; $result=mysql_query($sql); if (!$result) { echo Could not successfully run query ($sql) from DB: . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo No rows found, nothing to print so am exiting; exit; } echo table cellspacing='0' border='1' cellpadding='2' bgcolor='#CC' width='100%'; echo tr\n; echo thOffice/td\n; echo thName/td\n; echo thAddress/td\n; echo thPhones/td\n; echo thChurch/td\n; echo thEmail/td\n; echo thTermbrEnds/td\n; echo /tr\n; while ( $row = mysql_fetch_array($result,MYSQL_ASSOC) ) { echo tr\n; if ($row['Office'] == ) { echo tdnbsp;/td\n; } else { echo tdb{$row['Office']}/b/td\n; } echo td{$row['Name']}/td\n; echo td{$row['Address']}/td\n; echo td{$row['Phone']}/td\n; if ($row['Church'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Church']}/td\n; } if ($row['Email'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Email']}/td\n; } echo td{$row['Term']}/td\n; echo /tr\n; } echo /table\n; ? Can some kind soul bang out the code I need? Thanks. I'd cheat and add a numeric field, let's call it num_rank, ranking the offices in the order you want them displayed, e.g. President 10 Vice-President 20 . . . Board Member50 Board Member50 Board Member50 and change the query to SELECT * from members order by num_rank, last_name which would provide officers and board member in the order you want them, automatically sorted by name. Incidentally, why do you have a separate table for officers and directors? Maybe the answer is because it was cheap and easy, but is there a separate listing for all members who are not on the Board? In that case, you would be better off with two tables: 1. Add a logical lBoardMbr field to your general list of members, and this general list of members also has to have a unique primary key. MySQL will do that for you with an autoincrement field, with a table type of MyISAM. That table type ensures no re-use of deleted keys. 2. Your BoardMbr table then consists of fields like this: nMbrId - primary key of the person in the general list cOffice - text, President, Vice-President Board Member etc. num_rank - as discussed above cTerm - text field describing term. When a member becomes an officer you do four things: a) set the lBoardMbr field to true in the general table b) enter the member's primary key value in nMbrId field in BoardMbr table c) enter correct value cTerm in the same table d) set the lBoardMbr field to false in the general members table for those members who are leaving the board. The query to select the officers and directors would then change to SELECT general.nMbrdID as nGenId, BoardMbr.nMbrID as nBrdId, * from general, BoardMbr WHERE nGenID = nBrdID AND lBoardMbr != 0 ORDER BY num_rank, last_name Advantage? Data more closely approaches 3rd normal form, no redundancy, no errors when retyping, etc. Long answer - hope it's been helpful. Regards - Miles Thompson PS If this is pedantic, and you know how to do all this stuff, pls forgive. PPS Note I've assumed you have first_name and last_name fields /mt And when I was lying bed this morning, in that half-state between full wakefulness and sleep, I thought, WHY BOTHER WITH THE lBoardMbr FIELD? AN ENTRY AND LINK IN THE BoardMbr TABLE IS ENOUGH!!! Good example of why one should sleep on solutions. Which changes the SELECT to SELECT general.nMbrdID as nGenId, BoardMbr.nMbrID as nBrdId, * from general, BoardMbr WHERE nGenID = nBrdID ORDER BY num_rank, last_name Cheers - Miles -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.371 / Virus Database: 267.14.17/228 - Release Date: 1/12/2006 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table sorting problem
I am a novice in both PHP and MySQL, otherwise I would be able to do this myself. :-) A non-profit I assist has a table (http://www.lbc4cc.org/04-05board.php) that is displayed by a simple PHP script. That was fine last year, but now we have some new officers and some new board members and I have no idea how to change the script so that Officers and Members table is presented officers first (Pres, Vice-pres, Sec and Treas) and then an alpha listing of board members who are not officers. The existing script looks like this: ?php $sql = SELECT * FROM members; $result=mysql_query($sql); if (!$result) { echo Could not successfully run query ($sql) from DB: . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo No rows found, nothing to print so am exiting; exit; } echo table cellspacing='0' border='1' cellpadding='2' bgcolor='#CC' width='100%'; echo tr\n; echo thOffice/td\n; echo thName/td\n; echo thAddress/td\n; echo thPhones/td\n; echo thChurch/td\n; echo thEmail/td\n; echo thTermbrEnds/td\n; echo /tr\n; while ( $row = mysql_fetch_array($result,MYSQL_ASSOC) ) { echo tr\n; if ($row['Office'] == ) { echo tdnbsp;/td\n; } else { echo tdb{$row['Office']}/b/td\n; } echo td{$row['Name']}/td\n; echo td{$row['Address']}/td\n; echo td{$row['Phone']}/td\n; if ($row['Church'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Church']}/td\n; } if ($row['Email'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Email']}/td\n; } echo td{$row['Term']}/td\n; echo /tr\n; } echo /table\n; ? Can some kind soul bang out the code I need? Thanks. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table sorting problem
are the officers id'ed by some column? if so then add ORDER by COLUMN_NAME bastien From: Charles River [EMAIL PROTECTED] Reply-To: [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Table sorting problem Date: Thu, 12 Jan 2006 16:51:29 -0500 I am a novice in both PHP and MySQL, otherwise I would be able to do this myself. :-) A non-profit I assist has a table (http://www.lbc4cc.org/04-05board.php) that is displayed by a simple PHP script. That was fine last year, but now we have some new officers and some new board members and I have no idea how to change the script so that Officers and Members table is presented officers first (Pres, Vice-pres, Sec and Treas) and then an alpha listing of board members who are not officers. The existing script looks like this: ?php $sql = SELECT * FROM members; $result=mysql_query($sql); if (!$result) { echo Could not successfully run query ($sql) from DB: . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo No rows found, nothing to print so am exiting; exit; } echo table cellspacing='0' border='1' cellpadding='2' bgcolor='#CC' width='100%'; echo tr\n; echo thOffice/td\n; echo thName/td\n; echo thAddress/td\n; echo thPhones/td\n; echo thChurch/td\n; echo thEmail/td\n; echo thTermbrEnds/td\n; echo /tr\n; while ( $row = mysql_fetch_array($result,MYSQL_ASSOC) ) { echo tr\n; if ($row['Office'] == ) { echo tdnbsp;/td\n; } else { echo tdb{$row['Office']}/b/td\n; } echo td{$row['Name']}/td\n; echo td{$row['Address']}/td\n; echo td{$row['Phone']}/td\n; if ($row['Church'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Church']}/td\n; } if ($row['Email'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Email']}/td\n; } echo td{$row['Term']}/td\n; echo /tr\n; } echo /table\n; ? Can some kind soul bang out the code I need? Thanks. -- 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
Re: [PHP-DB] Table sorting problem
At 05:51 PM 1/12/2006, Charles River wrote: I am a novice in both PHP and MySQL, otherwise I would be able to do this myself. :-) A non-profit I assist has a table (http://www.lbc4cc.org/04-05board.php) that is displayed by a simple PHP script. That was fine last year, but now we have some new officers and some new board members and I have no idea how to change the script so that Officers and Members table is presented officers first (Pres, Vice-pres, Sec and Treas) and then an alpha listing of board members who are not officers. The existing script looks like this: ?php $sql = SELECT * FROM members; $result=mysql_query($sql); if (!$result) { echo Could not successfully run query ($sql) from DB: . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo No rows found, nothing to print so am exiting; exit; } echo table cellspacing='0' border='1' cellpadding='2' bgcolor='#CC' width='100%'; echo tr\n; echo thOffice/td\n; echo thName/td\n; echo thAddress/td\n; echo thPhones/td\n; echo thChurch/td\n; echo thEmail/td\n; echo thTermbrEnds/td\n; echo /tr\n; while ( $row = mysql_fetch_array($result,MYSQL_ASSOC) ) { echo tr\n; if ($row['Office'] == ) { echo tdnbsp;/td\n; } else { echo tdb{$row['Office']}/b/td\n; } echo td{$row['Name']}/td\n; echo td{$row['Address']}/td\n; echo td{$row['Phone']}/td\n; if ($row['Church'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Church']}/td\n; } if ($row['Email'] == ) { echo tdnbsp;/td\n; } else { echo td{$row['Email']}/td\n; } echo td{$row['Term']}/td\n; echo /tr\n; } echo /table\n; ? Can some kind soul bang out the code I need? Thanks. I'd cheat and add a numeric field, let's call it num_rank, ranking the offices in the order you want them displayed, e.g. President 10 Vice-President 20 . . . Board Member50 Board Member50 Board Member50 and change the query to SELECT * from members order by num_rank, last_name which would provide officers and board member in the order you want them, automatically sorted by name. Incidentally, why do you have a separate table for officers and directors? Maybe the answer is because it was cheap and easy, but is there a separate listing for all members who are not on the Board? In that case, you would be better off with two tables: 1. Add a logical lBoardMbr field to your general list of members, and this general list of members also has to have a unique primary key. MySQL will do that for you with an autoincrement field, with a table type of MyISAM. That table type ensures no re-use of deleted keys. 2. Your BoardMbr table then consists of fields like this: nMbrId - primary key of the person in the general list cOffice - text, President, Vice-President Board Member etc. num_rank - as discussed above cTerm - text field describing term. When a member becomes an officer you do four things: a) set the lBoardMbr field to true in the general table b) enter the member's primary key value in nMbrId field in BoardMbr table c) enter correct value cTerm in the same table d) set the lBoardMbr field to false in the general members table for those members who are leaving the board. The query to select the officers and directors would then change to SELECT general.nMbrdID as nGenId, BoardMbr.nMbrID as nBrdId, * from general, BoardMbr WHERE nGenID = nBrdID AND lBoardMbr != 0 ORDER BY num_rank, last_name Advantage? Data more closely approaches 3rd normal form, no redundancy, no errors when retyping, etc. Long answer - hope it's been helpful. Regards - Miles Thompson PS If this is pedantic, and you know how to do all this stuff, pls forgive. PPS Note I've assumed you have first_name and last_name fields /mt -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.1.371 / Virus Database: 267.14.17/227 - Release Date: 1/11/2006 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table sorting problem
On 1/12/06, Miles Thompson [EMAIL PROTECTED] wrote: I'd cheat and add a numeric field, let's call it num_rank, ranking the offices in the order you want them displayed, e.g. President 10 Vice-President 20 . . . Board Member50 Board Member50 Board Member50 and change the query to SELECT * from members order by num_rank, last_name which would provide officers and board member in the order you want them, automatically sorted by name. This is exactly how I implemented this page: http://www.arls-lilies.org/h/board.php -- Gerry http://portal.danen.org/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table Output Question
I have a table, where each line is the output of a query from a MySQL database. I do not use borders, so the page is a little difficult to read sometimes. Is it possible, or how do I, alternate the background color of each row when I output it? My code is like this: while (query) { TR TD/TD /TR } I am not sure how to output two rows in the same while loop. Thanks for any help you can offer me. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table Output Question
You don't have to output two rows.. just do this: $color = red; // init first color. while ($row = mysql_fetch_assoc($data)) { if ($color == red) { $color = blue; } else { $color = red; } ? tr bgcolor=?=$color?td../td/tr ? } -Micah On Monday 14 November 2005 3:37 pm, Jeff Grossman wrote: I have a table, where each line is the output of a query from a MySQL database. I do not use borders, so the page is a little difficult to read sometimes. Is it possible, or how do I, alternate the background color of each row when I output it? My code is like this: while (query) { TR TD/TD /TR } I am not sure how to output two rows in the same while loop. Thanks for any help you can offer me. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table Output Question
?php $row1 = FF; $row2 = AA; $counter = 0; while ($rows = mysql_fetch_array($result)) { $color = ($counter % 2 ==0) ? $row1 : $row2 ; echo tr style='backgroundcolor:$color'td...; } bastien ps: a class css definition would be better here From: Jeff Grossman [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Table Output Question Date: Mon, 14 Nov 2005 15:37:36 -0800 I have a table, where each line is the output of a query from a MySQL database. I do not use borders, so the page is a little difficult to read sometimes. Is it possible, or how do I, alternate the background color of each row when I output it? My code is like this: while (query) { TR TD/TD /TR } I am not sure how to output two rows in the same while loop. Thanks for any help you can offer me. -- 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] Table from an array?
Hi there everyone Is it possible to create a database table from the first line of a CSV file? What I mean is, how would you create the table columns based on the CSV files columns? This would really help me out, as some times the table column counts change on data I have to import, so it would be nice to have a flexible DB structure rather than a static one. Chris -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.8.4 - Release Date: 2/1/2005
Re: [PHP-DB] Table from an array?
On Thursday 03 February 2005 05:41, Chris Payne wrote: Is it possible to create a database table from the first line of a CSV file? What I mean is, how would you create the table columns based on the CSV files columns? Parse the first line and extract the column names, construct a suitable SQL statement to create table? -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- New Year Resolution: Ignore top posted posts -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table from an array?
Sure you could, the trick would be indentifiying the column data types, but perhaps you could put those in column name definition. ie user_id int(10), username varchar(50), etc bastien From: Chris Payne [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Table from an array? Date: Wed, 2 Feb 2005 16:41:42 -0500 Hi there everyone Is it possible to create a database table from the first line of a CSV file? What I mean is, how would you create the table columns based on the CSV files columns? This would really help me out, as some times the table column counts change on data I have to import, so it would be nice to have a flexible DB structure rather than a static one. Chris -- No virus found in this outgoing message. Checked by AVG Anti-Virus. Version: 7.0.300 / Virus Database: 265.8.4 - Release Date: 2/1/2005 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table Info
I am having problems coming up with a way to do this. I highly appreciate any help what so ever. Problem: I need to extract data from the database, and display it on a table with 2 columns. It has to alternate columns automaticly, for each row. Like I said earlier, any help is highly appreciated!! Thanks in advance, Brad Ciszewski www.BradTechnologies.com Web Services -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table Info
how is the data to be presented? is it top to bottom left to right or left to right then top to bottom? bastien From: Brad Ciszewski [EMAIL PROTECTED] To: php-db@lists.php.net Subject: [PHP-DB] Table Info Date: Fri, 24 Dec 2004 10:29:58 -0600 I am having problems coming up with a way to do this. I highly appreciate any help what so ever. Problem: I need to extract data from the database, and display it on a table with 2 columns. It has to alternate columns automaticly, for each row. Like I said earlier, any help is highly appreciated!! Thanks in advance, Brad Ciszewski www.BradTechnologies.com Web Services -- 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
Re: [PHP-DB] Table Info
define 2 variables, $col1data and $col2data if it is to alternate based on the count of the row (regularly, every other row) use the modulus operator in an if statement and assign data to proper column. then just print both, the wrong one will be empty and the right one will have data if it is to alternate based on some other criteria (the data itself perhaps) then use that in the if statement instead. assign the variables the same way, print the same way. On Fri, Dec 24, 2004 at 10:29:58AM -0600, Brad Ciszewski wrote: I am having problems coming up with a way to do this. I highly appreciate any help what so ever. Problem: I need to extract data from the database, and display it on a table with 2 columns. It has to alternate columns automaticly, for each row. Like I said earlier, any help is highly appreciated!! Thanks in advance, Brad Ciszewski www.BradTechnologies.com Web Services -- 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
Re: Re[2]: [PHP-DB] Table locking
Hi... I want to say some words about the Table Locking problem. I had a problem something like this one, I find solution for this by locking only the item that will updated. I added two areas one that has a value 0 or 1 giving it is currently used by someone, and second time it is started to use, default 0. When someone trying to update the item, first area has the value 1 and the second has the current time. After update completes, ifrst has the value 0, and second also 0. So if someone tries to update the area first system will chack and if someone is updating the item it will not give permission for this. Also it will chack the time if update is out of time (ex:more than 15 minutes) it will reset the time section and will give permission to update this item. This will provide people to see all other table elements ather then the updated. It worked for me... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re[2]: [PHP-DB] Table locking
In article [EMAIL PROTECTED], Emre Erdogan wrote: Hi... I want to say some words about the Table Locking problem. I had a problem something like this one, I find solution for this by locking only the item that will updated. I added two areas one that has a value 0 or 1 giving it is currently used by someone, and second time it is started to use, default 0. When someone trying to update the item, first area has the value 1 and the second has the current time. After update completes, ifrst has the value 0, and second also 0. I think one row will satisfy, namele a timestamp last_update. If you generate a form for the user to update the values of the current record, just add the timestamp as a hidden value. If the user submits the updated values compare the submitted last_update with the value in the database. If they are equal, perform the update (and change the value for last_update). If they are not equal, somebody else has changed the values in the meantime and the update should not be executed. If you are looking for other synchronization techniques you should have a look at the algorithms by Dekker and Peterson etc... Every website on computer algorithms will know how they work... -- Tim Van Wassenhove http://home.mysth.be/~timvw -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
I need to be sure, thath nobody else will can write on some tables until I don't append obout 4-500 records in these tables. But until now I never used table locking in MySQL and I didn't found information about this ( like examples ). Is there a problem with locking if PHP uses same userpass for all users in database ? Thanks in advance ! Rosen John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Rosen wrote: And if I perform LOCK tables ... nobody can;t write on these tables, until I don't perform UNLOCK TABLES ? If something happens ( I mean if some my queryes fails) ? I have a feeling it would be very very good if you'd state why you feel you need to LOCK these tables. There are generally a couple ways to do things, so you may not need to worry about locking at all. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
I have an orders with one main record in table1 ( client, date, e.t.c. ) and detail description in table2 ( all materials with quant, price, e.t.c. ) and I save data in table1 for positions (range of id - autoinc field of records in table2) for detailed data of order . And I don't want someone else to insert data in table2, because will be a problem with orders. Now I insert data first in table2 and then insert main record in table1 with the range of id's of detail order data. Could be some solution for this ? Thanks in advance. Rosen John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Rosen wrote: I need to be sure, thath nobody else will can write on some tables until I don't append obout 4-500 records in these tables. But until now I never used table locking in MySQL and I didn't found information about this ( like examples ). You could try a multi insert syntax such as INSERT INTO yourtable (a,b,c) VALUES (1,2,3),(4,5,6),(7,8,9); which will insert three rows into the table. Couldn't confirm in the manual, but this INSERT should run completely before anything else does. I still have to question _why_ another INSERT in the middle of your insertion will mess things up. Sounds like the problem is there. Is there a problem with locking if PHP uses same userpass for all users in database ? No. The LOCK is on a per connection basis and is not tied to the username and/or password. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] table locking ... not required ?
John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Michael Gale wrote: For the UPDATES ... what would have it in theory two people hit the UPDATE button at the exact same time ? Would one just over write the other ... cause that is fine ? Hi Michael, is it really OK that the second update just overwrites the first one? Because the second update will overwrite the first one *without* knowing about the first update and therefore without knowing about the data resulting from the first update. Regards, Torsten Whatever UPDATE gets there first will execute and the other one will wait until it's finished to update. There won't be any contention. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] table locking ... not required ?
Yes .. it is ok - the data that I allow to get updated like this is not that important and when a update is made it would be two people entering the same data anyways. It is just for contact info for people in the db ... like there current phone or address if it changes. Michael. On Fri, 9 Jul 2004 15:31:07 +0200 Torsten Roehr [EMAIL PROTECTED] wrote: John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Michael Gale wrote: For the UPDATES ... what would have it in theory two people hit the UPDATE button at the exact same time ? Would one just over write the other ... cause that is fine ? Hi Michael, is it really OK that the second update just overwrites the first one? Because the second update will overwrite the first one *without* knowing about the first update and therefore without knowing about the data resulting from the first update. Regards, Torsten Whatever UPDATE gets there first will execute and the other one will wait until it's finished to update. There won't be any contention. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals _ www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Michael Gale Network Administrator Utilitran Corporation -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table locking
Hi, I have the following situation: I have to prevent users to write at the same time in one table in PHP script. Is there a way the PHP to understand, thath another user is filling table, and to wait before begin to fill data? Thanks in advance! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
Rosen wrote: I have the following situation: I have to prevent users to write at the same time in one table in PHP script. Is there a way the PHP to understand, thath another user is filling table, and to wait before begin to fill data? Most databases have a LOCK command that you can issue. The other scripts that end up running at the same time will wait until the lock is released. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
Is thath mean, thath, when one user is addind records to table, and lock it - when another user is trying to get the max field value for some field, the script will waiting the first user to unlock table and then to see the max value of some field in a table ? John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Rosen wrote: I have the following situation: I have to prevent users to write at the same time in one table in PHP script. Is there a way the PHP to understand, thath another user is filling table, and to wait before begin to fill data? Most databases have a LOCK command that you can issue. The other scripts that end up running at the same time will wait until the lock is released. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
On Friday 09 July 2004 07:09, Rosen wrote: Is thath mean, thath, when one user is addind records to table, and lock it - when another user is trying to get the max field value for some field, the script will waiting the first user to unlock table and then to see the max value of some field in a table ? Depends on what type of LOCK you specify. Refer to your DB docs for details. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* I'm so broke I can't even pay attention. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
Thanks, but can you give me a sample PHP script with MySQL database, whitch do this? Thanks Jason Wong [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Friday 09 July 2004 07:09, Rosen wrote: Is thath mean, thath, when one user is addind records to table, and lock it - when another user is trying to get the max field value for some field, the script will waiting the first user to unlock table and then to see the max value of some field in a table ? Depends on what type of LOCK you specify. Refer to your DB docs for details. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* I'm so broke I can't even pay attention. */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking
And if I perform LOCK tables ... nobody can;t write on these tables, until I don't perform UNLOCK TABLES ? If something happens ( I mean if some my queryes fails) ? Jason Wong [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On Friday 09 July 2004 07:24, Rosen wrote: Thanks, but can you give me a sample PHP script with MySQL database, whitch do this? Don't have any examples handy. Basically instead of performing your usual single query, you sandwich it between two extra queries: LOCK tables ... your usual query here UNLOCK TABLES -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* Nothing is impossible for the man who doesn't have to do it himself. -- A.H. Weiler */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table values
Hi, I am running a bouncing script for bounced emails that updated to a database. What I want to do is have 3 bounces before dis-allowing emails to be sent to that user. So I have the following tables in my db: - Username Username of the user - Email Users Email Address - email_setting If set to 2 (default) it will send an email to their inbox and one to the website internal website, if set to 1 it will send only to internal website, if set 0 it will send to inbox only. Any other values will not send to anything. - emailerror Counts the emails error that have bounced back. This is what I would like to do... If an email bounces it will grab the email in the inbox and match it to the database. If a match is there it will put +1 value in emailerror. (This has already been achieved, I have done this) What I want to do is once the value in emailerror reaches 3 I than want the email_setting set to -1 so no emails get sent out. So If user bob had 3 bounces I'd want to grab the 3 value and reset it to 0 and change email_setting to -1. How could I achieve this? I need this to apply to all Users when they reach emailerror = 3. I need it to be safe and work when it reaches 3+. I'm not familiar with grabbing a value from one table and putting a new value in another. So all help is mostly appreciated. What I have now is a bouncing script. It grabs the email addresses from the orginal body of an email, runs it in a loop than puts it in a query to do a match on my db. If one is found it makes the updates (emailerror = +1) ... If no match it does nothing. Now I need to grab values of 3 or higher in emailerror and reset to 0 and place a -1 value in email_setting but not sure how to do this. Thanks for your time. J http://greetings.yahoo.com.au - Yahoo! Greetings Send your love online with Yahoo! Greetings - FREE! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table structure question
Hi everyone, I would like to set up the following two tables inside a db for a soccer league, but wanted to run their structure by you guys first. Here it is: dbname: soccer_stats tables: teams, players teams -- name | captain | division | paid | pmnt_notes | win | loss | tie | goals_for | goals_against players -- lname | fname | team_name | dob | address | telephone | email | sex | yellow | red | disc_notes | goals_scored | own goals I've never split the info over multiple tables, but this way made sense to me for some reason. I've been thinking, and if, for example, I want to (using mysql) pull the captain of a specific player, how would I do that? Is this a good table design in the first place? Comments and criticisms are welcome! Thanks - Kirk -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] table structure question
I would do it a little bit different: 1. I would add ID's for each of the tables. 2. I would split teams in 2 tables; the captain stuff would be in a separate table (captain_team let's say), simply because I would have different players as captains in different games. If you keep the structure as it is now, you'll have a lot of duplication. So, I would do it like this: teams --- IDteam | name | ... teams_captain --- IDteam| IDplayer| Game (this could be date format) players IDplayer |... Then, if you want to see the players who were captains for a given team, you can write smth. like: select distinct p.lname from players p, teams_captain t, teams tt where p.IDplayer=t.IDplayer and t.IDteam=tt.IDteam and tt.name like 'Real Madrid' Check also the normalization forms of a database, which you can find in any database book, simply because you'll have complications if you record more than 1 season and some teams can move in different leagues. Hope this helps. Mihai On Mon, 29 Dec 2003, Kirk Babb wrote: Hi everyone, I would like to set up the following two tables inside a db for a soccer league, but wanted to run their structure by you guys first. Here it is: dbname: soccer_stats tables: teams, players teams -- name | captain | division | paid | pmnt_notes | win | loss | tie | goals_for | goals_against players -- lname | fname | team_name | dob | address | telephone | email | sex | yellow | red | disc_notes | goals_scored | own goals I've never split the info over multiple tables, but this way made sense to me for some reason. I've been thinking, and if, for example, I want to (using mysql) pull the captain of a specific player, how would I do that? Is this a good table design in the first place? Comments and criticisms are welcome! Thanks - Kirk -- 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
RE: [PHP-DB] table structure question
Hi Kirt, Your tables look ok to me... As for your question, if I were using your example, I would link the field teams.name to players.team_name. For example, I would set another column in the teams table to be auto incrementing. As you add the team information, the team will get a number automatically. Then when you add the players information you can use the value ID from the teams table as the value you enter in the players.team_name column. I do this with an html form that has a drop down list that is generated by pulling the team name and ID from the teams table. Something like this: $sql_teams = mysql_query(SELECT ID, name FROM teams ORDER BY name); Then I create a drop down list in my html form like this: select name=team ? // Creates the list of teams from the teams Table while ($LST = mysql_fetch_array($sql_teams)) { $TeamID = $LST[ID]; $team_name = htmlspecialchars($LST[Name]); echo(option value='$TeamID'$team_name/option\n); } ? /select Hope I did not gunk up your question with an answer you did not need... Anyway, hope this helps... Aleks -Original Message- From: Kirk Babb [mailto:[EMAIL PROTECTED] Sent: Monday, December 29, 2003 4:31 PM To: [EMAIL PROTECTED] Subject: [PHP-DB] table structure question Hi everyone, I would like to set up the following two tables inside a db for a soccer league, but wanted to run their structure by you guys first. Here it is: dbname: soccer_stats tables: teams, players teams -- name | captain | division | paid | pmnt_notes | win | loss | tie | goals_for | goals_against players -- lname | fname | team_name | dob | address | telephone | email | sex | yellow | red | disc_notes | goals_scored | own goals I've never split the info over multiple tables, but this way made sense to me for some reason. I've been thinking, and if, for example, I want to (using mysql) pull the captain of a specific player, how would I do that? Is this a good table design in the first place? Comments and criticisms are welcome! Thanks - Kirk -- 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] table match lookup!
Hi, If I have a table named quote and the field has 30 words in it is there a way to pin-point a certain word and match it with another query in PHP? So a quote may say: Tomorrow never comes And I wanted 'never' to be dragged out of all quotes and counted in another table to keep a track of how many words of each is listed in the entire database. So is there a query or a PHP code I can use to look for a particular matching word? J http://personals.yahoo.com.au - Yahoo! Personals New people, new possibilities. FREE for a limited time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table locking to prevent duplicate inserts?
John, Thanks much for the excellent tips, I guess I was trying to make it too difficult. We're working on the SQL and indexes to alleviate the slowdowns and I don't expect this to really be an issue in the future, it just concerned me that it was even possible... I thought I'd coded it better than that. The duplicates are an issue because this is a stats-gathering application for area high school sports, and duplicate stat entries resulted in doubled stat values. I guess we should also be looking at tightening up our reporting code using SELECT DISTINCT, perhaps, but really hadn't considered that we'd have any dupes to begin with. Adding a unique constraint isn't a bad idea either, but since it'd have to be unique across several fields I'd have to read up and figure out how to do that. Sorry about that; I hate to keep my employers waiting. BTW, I haven't received my paycheck this month. ;) I certainly didn't mean to imply that anyone on the list had an obligation to answer my post and hope no one took it that way. I was just apologizing for the duplicate post and trying to explain why I was trying again. Anyway, thanks again for the help. I'll be able to fix this app and will incorporate your suggestions into my work in the future. Chuck -Original Message- From: John W. Holmes [mailto:[EMAIL PROTECTED] Sent: Monday, October 20, 2003 11:32 AM To: Mayo, Chuck Cc: [EMAIL PROTECTED] Subject: Re: [PHP-DB] Table locking to prevent duplicate inserts? Mayo, Chuck wrote: Hi all, Hope you'll forgive the duplicate post but the list seems to be hopping today (unlike the friday afternoon I sent the original query)... since everyone seems to be awake today I thought I'd try it again: Sorry about that; I hate to keep my employers waiting. BTW, I haven't received my paycheck this month. ;) 1) A user submits a form containing about a hundred form fields which PHP needs to insert into a MySQL table. 2) MySQL is busy doing a lengthy SELECT for someone else, so the user's browser hangs until the SELECT is done. Okay, first of all, fix this lengthy select or whatever other slowdowns there are in your scripts. 3) The user gets tired of waiting and hits submit again while his browser is still hung. 4) When the long SELECT finishes, two PHP threads kick off (I'm assuming), the user's original submit and his second, resulting in duplicate INSERT's Easy way is to set a session variable when they submit a form flagging the form as submitted at time X. If it's been less than X seconds since the last time the form was submitted, then deny the re-submission. Other method would be to supply a unique id to the form in a hidden element. When the form is submitted, put that variable in the session. If the form is submitted, the value is already in the session, so you know this is a duplicate entry. What problems do the duplicate entries cause? You may be able to handle this at the database level with a UNIQUE restraint on your column. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table locking to prevent duplicate inserts?
Hi all, Hope you'll forgive the duplicate post but the list seems to be hopping today (unlike the friday afternoon I sent the original query)... since everyone seems to be awake today I thought I'd try it again: --- I'm working through an issue that I'm sure everyone else has already figured out, how to lock a table during a series of INSERTS to prevent duplicate entries: The scenario is this: OS Solaris 8 PHP 4.2.3 MySQL 3.23.53 Table type: MyISAM 1) A user submits a form containing about a hundred form fields which PHP needs to insert into a MySQL table. 2) MySQL is busy doing a lengthy SELECT for someone else, so the user's browser hangs until the SELECT is done. 3) The user gets tired of waiting and hits submit again while his browser is still hung. 4) When the long SELECT finishes, two PHP threads kick off (I'm assuming), the user's original submit and his second, resulting in duplicate INSERT's The first thing I tried was locking the tables at the top of the insert loop then unlocking at the bottom, i.e. ? // Pseudocode $thread_id = unique id generated with uniqid(); LOCK TABLES foreach($form_field as $db_field) { INSERT INTO $table VALUES ('$db_field','$thread_id) } UNLOCK TABLES ? What I thought would happen is that one PHP thread would have to wait for the other resulting in: INSERTED DATA, THREAD1 INSERTED DATA, THREAD1 INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 INSERTED DATA, THREAD2 INSERTED DATA, THREAD2 That wouldn't have solved my dupe issue but would have at least shown me that locking the tables was the way to go. Instead, the inserts from the two threads were still interleaved: INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 Seemed like locking the tables for the duration of the insert loops would do it but it didn't seem to. My next avenue of attack was a modification where the script would first check for an existing record and update it if one was found, inserting a new record only if there wasn't an existing record, but I got exactly the same results, it's like the two instances are executing exactly in unison. Anyone have a clue what's going on here, or better still... how the heck to make these threads play nice? Thanks Chuck Mayo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table locking to prevent duplicate inserts?
Mayo, Chuck wrote: Hi all, Hope you'll forgive the duplicate post but the list seems to be hopping today (unlike the friday afternoon I sent the original query)... since everyone seems to be awake today I thought I'd try it again: Sorry about that; I hate to keep my employers waiting. BTW, I haven't received my paycheck this month. ;) 1) A user submits a form containing about a hundred form fields which PHP needs to insert into a MySQL table. 2) MySQL is busy doing a lengthy SELECT for someone else, so the user's browser hangs until the SELECT is done. Okay, first of all, fix this lengthy select or whatever other slowdowns there are in your scripts. 3) The user gets tired of waiting and hits submit again while his browser is still hung. 4) When the long SELECT finishes, two PHP threads kick off (I'm assuming), the user's original submit and his second, resulting in duplicate INSERT's Easy way is to set a session variable when they submit a form flagging the form as submitted at time X. If it's been less than X seconds since the last time the form was submitted, then deny the re-submission. Other method would be to supply a unique id to the form in a hidden element. When the form is submitted, put that variable in the session. If the form is submitted, the value is already in the session, so you know this is a duplicate entry. What problems do the duplicate entries cause? You may be able to handle this at the database level with a UNIQUE restraint on your column. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table locking to prevent duplicate inserts?
Hi all, I'm working through an issue that I'm sure everyone else has already figured out, how to lock a table during a series of INSERTS to prevent duplicate entries: The scenario is this: OS Solaris 8 PHP 4.2.3 MySQL 3.23.53 Table type: MyISAM 1) A user submits a form containing about a hundred form fields which PHP needs to insert into a MySQL table. 2) MySQL is busy doing a lengthy SELECT for someone else, so the user's browser hangs until the SELECT is done. 3) The user gets tired of waiting and hits submit again while his browser is still hung. 4) When the long SELECT finishes, two PHP threads kick off (I'm assuming), the user's original submit and his second, resulting in duplicate INSERT's The first thing I tried was locking the tables at the top of the insert loop then unlocking at the bottom, i.e. ? // Pseudocode $thread_id = unique id generated with uniqid(); LOCK TABLES foreach($form_field as $db_field) { INSERT INTO $table VALUES ('$db_field','$thread_id) } UNLOCK TABLES ? What I thought would happen is that one PHP thread would have to wait for the other resulting in: INSERTED DATA, THREAD1 INSERTED DATA, THREAD1 INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 INSERTED DATA, THREAD2 INSERTED DATA, THREAD2 That wouldn't have solved my dupe issue but would have at least shown me that locking the tables was the way to go. Instead, the inserts from the two threads were still interleaved: INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 INSERTED DATA, THREAD1 INSERTED DATA, THREAD2 Seemed like locking the tables for the duration of the insert loops would do it but it didn't seem to. My next avenue of attack was a modification where the script would first check for an existing record and update it if one was found, inserting a new record only if there wasn't an existing record, but got exactly the same results. Anyone have a clue what's going on here, or better still... how the heck to make these threads play nice? Thanks Chuck Mayo -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table Field type
From: Michelle Whelan [EMAIL PROTECTED] Does anyone know what field type to use for inserting a webpage name into a database? Example pagename.html When I fill in the form information everything seems to insert fine, then I do a search to see the result and nothing is there, so I check the entry in the database and there is an empty space. Please help. Thanks. A CHAR or VARCHAR field will be fine. The reason it's not showing up is probably due to your code or PHP setup, rather than the database column (unless you had something like INTEGER?? :) ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table Field type
Does anyone know what field type to use for inserting a webpage name into a database? Example pagename.html When I fill in the form information everything seems to insert fine, then I do a search to see the result and nothing is there, so I check the entry in the database and there is an empty space. Please help. Thanks.
Re: [PHP-DB] Table locks
Tim Best wrote: Anyone know how you set a lock in a MySQL table using PHP? I tried: $select = LOCK TABLES t1 WRITE;; $select .= select * from t1;; $select .= UNLOCK tables;; When I run mysql_db_query(db,$select,$conn); it always returns nothing. Any insights would be appreciated! Run one query at a time. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ PHP|Architect: A magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table structure
Hi, I would be very grateful if someone could look at my table design for me please. The sytem will be used to allow users to log in to a web site and book staff. Here is my design so far. # -- MySQL dump -- # # Table structure for table 'WMS_Allocations' # CREATE TABLE WMS_Allocations ( Allocation_ID int(11) DEFAULT '' NOT NULL auto_increment, Project_ID int(11) DEFAULT '0' NOT NULL , User_ID int(11) DEFAULT '0' NOT NULL , PRIMARY KEY (Allocation_ID), KEY Project_ID (Project_ID,User_ID) ); # # Table structure for table 'WMS_Bookings' # CREATE TABLE WMS_Bookings ( Booking_ID int(11) DEFAULT '' NOT NULL auto_increment, Booking_Date date DEFAULT '-00-00' NOT NULL , PCT_address varchar(255), PCT_postcode varchar(255), PCT_telephone varchar(255), PCT_manager varchar(255), PCT_gp varchar(255), P_address varchar(255), P_postcode varchar(255), P_telephone varchar(255), P_manager varchar(255), P_gp varchar(255), Allocation_ID int(11), PRIMARY KEY (Booking_ID), KEY Allocation_ID (Allocation_ID) ); # # Table structure for table 'WMS_Projects' # CREATE TABLE WMS_Projects ( Project_ID int(11) DEFAULT '' NOT NULL auto_increment, Project_Name varchar(255), PRIMARY KEY (Project_ID) ); # # Table structure for table 'WMS_User' # CREATE TABLE WMS_User ( User_ID int(11) DEFAULT '' NOT NULL auto_increment, User_Username varchar(100) DEFAULT '' NOT NULL , User_Password varchar(100) DEFAULT '' NOT NULL , User_Name varchar(100) DEFAULT '' NOT NULL , User_Type int(11) DEFAULT '0' NOT NULL , User_Email varchar(100), PRIMARY KEY (User_ID), UNIQUE User_Username (User_Username) ); A user could be a client, a staff member, or an administrator. Clients can log in and book staff to their own projects. Administrators can log in, allocate staff to any project, add/edit/delete - projects/staff/clients, and book staff on a project they are allocated to. A staff member will be able to log in and complete a booking they have undertaken and add in data needed for the project. At the moment i have a single table to incorporate all three types of user but i think i need to change this as the relationship between a client and a project is different to a staff member/administrator and a project. A client can have many projects but a project will only belong to one client where as a staff member/administrator could be allocated to many projects and project could be allocated to many staff members/administrators. My MySQL installation doesnt support Foreign Keys which makes life a little difficult! Any thoughts comments on this would be greatly appreciated. Thanks for your time. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table name is variable
Hello. I am a begginer in PHP programming and I would appreciate any help. My problem is the following: I need to make the name of my table a variable. My thought was simple: $imprimir = mysql_query(SELECT id, data FROM $tabela,$db); but it doesnt work... how should i do it? Thank you in advance, Dani -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table name is variable
I am a begginer in PHP programming and I would appreciate any help. My problem is the following: I need to make the name of my table a variable. My thought was simple: $imprimir = mysql_query(SELECT id, data FROM $tabela,$db); but it doesnt work... how should i do it? Just like that. Make sure $tabela has a value. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table relationship
Hi, I am creating a web site which will have different types of users: Administrators, clients and staff. Is it possible/good practice to have 3 tables related to one table i.e. USER user_id (PK) | | | || | || AdministratorClient Staff admin_id(PK) client_id(PK) staff_id(PK) user_id(FK) user_id(FK)user_id(FK) Thanks in advance for any advice offered. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] table relationship
Yes. You have to use the subtype relational design: USER user_id (PK) | | | || | || AdministratorClient Staff user_id(PFK) user_id(PFK) user_id(PFK) admin_field1 user_field1 staff_field1 admin_field2 . With a 1-1 relationship from Administrator to User, 0-1 relationship from User to Administrator (PFK : PRIMARY KEY and FOREIGN KEY) This is particularly useful when the subtypes have different fields, so you don't want to have only one table with many blanks for fields that do not relate to the type at hand. HTH Ignatius - Original Message - From: shaun [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, March 10, 2003 10:35 AM Subject: [PHP-DB] table relationship Hi, I am creating a web site which will have different types of users: Administrators, clients and staff. Is it possible/good practice to have 3 tables related to one table i.e. USER user_id (PK) | | | || | || AdministratorClient Staff admin_id(PK) client_id(PK) staff_id(PK) user_id(FK) user_id(FK)user_id(FK) Thanks in advance for any advice offered. -- 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
Re: [PHP-DB] table relationship
Three tables seems wasteful, and could mean that you have to do three queries when looking for someone. Why not approach it this way. Users table - info on all users, regardless of category Levels table - sets different access levels, e.g. clients, staff, administrators User_levels table - assigns levels to user id's This would give you more long-term flexibility as you would only have to extend the levels table to add granularity of access or control levels. I'd also have a look at various network permission schemes, because there are subtleties that are not immediately apparent when working up an access scheme. Cheers - Miles Thompson At 09:35 AM 3/10/2003 +, shaun wrote: Hi, I am creating a web site which will have different types of users: Administrators, clients and staff. Is it possible/good practice to have 3 tables related to one table i.e. USER user_id (PK) | | | || | || AdministratorClient Staff admin_id(PK) client_id(PK) staff_id(PK) user_id(FK) user_id(FK)user_id(FK) Thanks in advance for any advice offered. -- 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
Re: [PHP-DB] -- table name prefix in result set after join --
It really depends on the DBMS you are using, but you can use aliases as a trick to solve this problem: select a.col1 as a_col1, b.col1 as b_col1 from a join b on a.id=b.id This will return the two columns a_col1 and b_col1 Cheers, Marco -- php|architect - The magazine for PHP Professionals The monthly worldwide magazine dedicated to PHP programmers Check us out on the web at http://www.phparch.com On Sat, 2002-11-23 at 10:18, Matt Friedman wrote: Is there a way in SQL to have the column names prefixed by the table name in a result set after a join? Table A has column col1 and table B has columns col2 and col3 After the join I want the result set to have columns named A.col1B.col2 B.col3 Such that I can tell from which table each column came from. Is this possible? Matt Friedman -- 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] Table question....
Hi people, is there a way to print a table with the background switching colors??? like one blue, the next black, blue, black... thanks in advance... Equipe Pratic Sistemas Rodrigo Corrêa Fone: (14) 441-1700 [EMAIL PROTECTED] [EMAIL PROTECTED]
Re: [PHP-DB] Table question....
if you mean the rows switching colors i use this. in this example i'm getting data from mysql $rs = 0; for($i = 0; $i count($rs); ) { while ($rs = mysql_fetch_array($result)) { $bgcolor = ($i % 2) ? 'blue' : 'black'; //do stuff $i++; } } then $bgcolor goes in each td bgcolor=$bgcolor ... hth jd Rodrigo rodrigo@praticsistem To: PHP [EMAIL PROTECTED] as.com.br cc: Subject: [PHP-DB] Table question 10/03/2002 08:59 AM Please respond to Rodrigo Hi people, is there a way to print a table with the background switching colors??? like one blue, the next black, blue, black... thanks in advance... Equipe Pratic Sistemas Rodrigo Corrêa Fone: (14) 441-1700 [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Table question....
you have to make it yourself... make a counter, for every row do $counter++; and the if ($counter%2==0){ blue }else{ red } the % is the difference math function... you got a rest-value or not... hope you get it :) -Original Message- From: Rodrigo [mailto:[EMAIL PROTECTED]] Sent: donderdag 3 oktober 2002 14:30 To: PHP Subject: [PHP-DB] Table question Hi people, is there a way to print a table with the background switching colors??? like one blue, the next black, blue, black... thanks in advance... Equipe Pratic Sistemas Rodrigo Corrêa Fone: (14) 441-1700 [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table question....
$bgcolor = ($count++ 1) ? blue : black; Then use $bgcolor in your tr ---John Holmes... - Original Message - From: Rodrigo [EMAIL PROTECTED] To: PHP [EMAIL PROTECTED] Sent: Thursday, October 03, 2002 8:29 AM Subject: [PHP-DB] Table question Hi people, is there a way to print a table with the background switching colors??? like one blue, the next black, blue, black... thanks in advance... Equipe Pratic Sistemas Rodrigo Corrêa Fone: (14) 441-1700 [EMAIL PROTECTED] [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table naming issues
Does anyone have any table-naming systems to keep tables grouped so that they will be more readily available in PhpMyAdmin's left column? maybe 001_contacts and 002_users for large databases supporting a CMS Russell Griechen htttp://sportsmenafield.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table formatting a link from a mysql query result
All, How can I display the results of a table so that the first field (column) is a link to another page that shows the details of that row? Issue #1, I have to wrap the cell contents in an a href. Issue #2, I need to pass a variable to the referenced page when the link is clicked. Anyone know of any good examples of this? Thanks, Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table formatting a link from a mysql query result
$variable_to_be_passed = 'some value'; echo tda href='some_page.php?variable=$variable_to_be_passed'I am a link/a/td; I think this should do it, not quite sure what you mean by wrappinga table cell in a anchor tag? Of course if you need to use the results of a database, this can be done too with the same method. HTH -Brad Aaron Merrick wrote: All, How can I display the results of a table so that the first field (column) is a link to another page that shows the details of that row? Issue #1, I have to wrap the cell contents in an a href. Issue #2, I need to pass a variable to the referenced page when the link is clicked. Anyone know of any good examples of this? Thanks, Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Table formatting a link from a mysql query result
Brad, Thanks a million! That does the trick. Aaron On 9/5/02 3:38 PM, Brad Bonkoski [EMAIL PROTECTED] wrote: $variable_to_be_passed = 'some value'; echo tda href='some_page.php?variable=$variable_to_be_passed'I am a link/a/td; I think this should do it, not quite sure what you mean by wrappinga table cell in a anchor tag? Of course if you need to use the results of a database, this can be done too with the same method. HTH -Brad Aaron Merrick wrote: All, How can I display the results of a table so that the first field (column) is a link to another page that shows the details of that row? Issue #1, I have to wrap the cell contents in an a href. Issue #2, I need to pass a variable to the referenced page when the link is clicked. Anyone know of any good examples of this? Thanks, Aaron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table structure and displaying certain thing
Hi all, I have a table called items here is a dump: CREATE TABLE items ( id int(10) NOT NULL auto_increment, name varchar(50) NOT NULL default '', item_type int(4) NOT NULL default '0', image varchar(100) NOT NULL default '', price int(10) NOT NULL default '0', quantity int(5) NOT NULL default '0', PRIMARY KEY (id) ) TYPE=MyISAM; Here is my code and I know there has to be an easier way to do this so any help would be appreciated. form action=buyitem.php method=post ?php // selects the image of the item from db $query = SELECT image FROM items where id = 1; $ret = mysql_query($query); while(list($image) = mysql_fetch_row($ret)) echo input type=image src=images/blueholo.gif name=\1\BR; //select the name of the item $query = SELECT name FROM items where id = 1; $ret = mysql_query($query); while(list($name) = mysql_fetch_row($ret)) echo B$name/B; //shows the quantity of the item $query = SELECT quantity FROM items where id = 1; $ret = mysql_query($query); while(list($quantity) = mysql_fetch_row($ret)) echo Quantity $quantityBR; //the price of the item $query = SELECT price FROM items where id = 1; $ret = mysql_query($query); while(list($price) = mysql_fetch_row($ret)) echo Cost: $price SC; ? /form What I am trying to do is make it so the user clicks on the image and is taken to buyitem.php through the form where it takes the item out of the items table and updates the user table with that item. Any ideas how I can accomplish this? TIA Jennifer -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Table Relationships
In databases, after creating a number of tables, one could usually set relationships (or some call it relations) between these tables, by tying some reference number in one table with the id (or index) in another table for example, or just making any other kinds of relationships between tables for any other reason. I used to do relationships between tables when I used Microsoft Access. My question is: Does MySQL enable you to create relationships between tables after you create the tables? If so, how (what are the commands from the command prompt?) -- Ashraf Al Shafaki ICQ me at 144936414 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] table overheading
hello anyone know why ooverhead happen? some of my table are overheading where a run delete and updates queries. --- Everton B Yoshitani [[EMAIL PROTECTED]] UF Communications, Inc. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Table to BIG to dump, how ?
I always got this error message when I tried to dump my structure and data table to a file. I think it's because the file table size it BIG (almost 10mb). Is there anyway to dump that table to file without getting browser time out ? Please help me here.. -Naga _ www.kaskus.com - Community Forum Free Email service -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Table Locking...
(PHP-DB folks, ignore this top question - unless you want to answer) Which type of DB/Table provides table locking while a process is altering data? I don't care for locking while using SELECTs, but I do need locking when something's being INSERTed or UPDATEd, so I won't get two processes trying to do the same darned thing at the same time. (MySQL folks, ignore this bottom question - unless you want to answer) I'm somewhat lost on how to do the following: I'm trying to go through a table and check for a particular information. If it doesn't exist, then go ahead and issue an INSERT with the relevant data. The next time another process comes along, it'll obviously find the information and issue an UPDATE instead. But, what happens if I get two processes running at the same time, trying to find information that does not exist yet? If both issue a SELECT and find the information not there, both will try to issue an INSERT, where really I want one of those processes to wait for the first one to finish doing whatever it needs to do, prior to continuing. (all of this is being done in PHP by the way). Does anyone have any suggestions for this scenario (or am I just blowing smoke out my arse and there's something else, internally, that I'm not aware of?) When (and how) to issue some sort of wait state for one process while the other's finishing what it needs to do, then restart the second process (which should re-check for existing information, and not blindly issue another INSERT right after the first one). -- W | I haven't lost my mind; it's backed up on tape somewhere. + Ashley M. Kirchner mailto:[EMAIL PROTECTED] . 303.442.6410 x130 IT Director / SysAdmin / WebSmith . 800.441.3873 x130 Photo Craft Laboratories, Inc.. 3550 Arapahoe Ave. #6 http://www.pcraft.com . . .. Boulder, CO 80303, U.S.A. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Table display Driving me Crazy!
I figured out what was wrong...and yes, the db call was from phplib...I am making modifications to existing code and so haven't figured out all the inns and outs...what I did was just create an array from the object that was being called by the query and then addressed those array elements individually here is a sample: ? for ($l = 1; $l = $numcols; ++$l) { if ($int_j = $int_i){ ? td width=139 class=ModNo bordercolor=#00?php echo $array_sku[$int_j]; ?/td ? } //endif $int_j++; } //endfor ...sorry if the code looks like crap but yahoo tends to truncate the width... thanks anyways! Luis --- Jason Wong [EMAIL PROTECTED] wrote: The whole block is wraped in a while ($db-next_record()) { ...} loop actually. Now, I'm not sure if the next_record() method is setting an internal member to the current record and returning TRUE/FALSE for success, or if it's actually supposed to be returning a row. It should be the former. But whatever it does, it doesn't change the fact that the code for displaying the 1st, 2nd and 3rd rows are in fact displaying a constant for each of the 5 columns. I'm guessing the class is simply being mis-used. The code is reasonably logical assuming next_record() is setting an internal member variable to the current row... doesn't look like it is though. If I'm not mistaken it looks to be using the phplib library. I believe it *is* being used correctly but he doesn't seem to be choosing the correct fields to display. I know with ASP/VBScript that there's a decent performance hit when you jump from HTML to VbScript and back again... I would imagine though not as severe the same also happens in PHP. Rather than stop the parser, print out something small like a /td and start the parser back up it's probably better performance wise to just use the 'echo' function (well, keyword, I guess echo isn't a real function, print is though). Plus, it makes your code more readable without all the ?php ? marks everywhere. In this case, yes, it's preferable to use echo. But if there are more than a few lines of html then using echo gets tedious pretty quickly (not mention having to escape all the s) :) regards -- Jason Wong Gremlins Associates www.gremlins.com.hk Tel: +852-2573-5033 Fax: +852-2573-5851 __ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Table display Driving me Crazy!
Hello * trying to output mysql content into a table, but the table is designed to use 3 Trows to display info for ONE product (table also has to have 5 columns): row1 sku1|sku2|sku3|sku4|sku5 row2 img1|img2|img3|img4|img5 row3 nam1|nam2|nam3|nam4|nam5 - row4 sku6|sku7|sku8|sku9|sku10 row5 img6|img7|img8|img9|img10 row6 nam6|nam7|nam8|nam9|nam10 - etc... I have code that is displaying the right #of columns but it is simply repeating the product across the table... table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#00 ?php $db-query($list); while ($db-next_record()) { ? tr bgcolor=#66 ?php $numcols = 5; for ($l = 1; $l = $numcols; ++$l) {? td width=139 class=ModNo bordercolor=#00?php echo $db-f(product_sku); ?/td ?php } ? /tr tr bgcolor=#ECEF7A ?php for ($l = 1; $l = $numcols; ++$l) { ? td height=80 bordercolor=#00 div align=centerA HREF=?php $sess-purl(URL . ?page=$flypageproduct_id= . $db-f(product_id) . category_id= . $db-f(category_id)); ? ?php $ps_product-show_image($db-f(product_thumb_image),); ?/A /div /td ?php } ? /tr tr bgcolor=#C9C62D bordercolor=#C9C62D ?php for ($l = 1; $l = $numcols; ++$l) { ? td class=prodName?php $db-p(product_name); ?/td ?php } ? /tr ?php } ? /table Anybody have any ideas how I can get this thing to work?! Thanks Luis __ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Table display Driving me Crazy!
What does you mysql table look like? What does your SELECT statements look like? What does function p() do? What does function f() do? Need more info -Original Message- From: Adv. Systems Design [mailto:[EMAIL PROTECTED]] Sent: Thursday, September 13, 2001 11:09 AM To: PHP List Subject: [PHP-DB] Table display Driving me Crazy! Hello * trying to output mysql content into a table, but the table is designed to use 3 Trows to display info for ONE product (table also has to have 5 columns): row1 sku1|sku2|sku3|sku4|sku5 row2 img1|img2|img3|img4|img5 row3 nam1|nam2|nam3|nam4|nam5 - row4 sku6|sku7|sku8|sku9|sku10 row5 img6|img7|img8|img9|img10 row6 nam6|nam7|nam8|nam9|nam10 - etc... I have code that is displaying the right #of columns but it is simply repeating the product across the table... table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#00 ?php $db-query($list); while ($db-next_record()) { ? tr bgcolor=#66 ?php $numcols = 5; for ($l = 1; $l = $numcols; ++$l) {? td width=139 class=ModNo bordercolor=#00?php echo $db-f(product_sku); ?/td ?php } ? /tr tr bgcolor=#ECEF7A ?php for ($l = 1; $l = $numcols; ++$l) { ? td height=80 bordercolor=#00 div align=centerA HREF=?php $sess-purl(URL . ?page=$flypageproduct_id= . $db-f(product_id) . category_id= . $db-f(category_id)); ? ?php $ps_product-show_image($db-f(product_thumb_image),); ?/A /div /td ?php } ? /tr tr bgcolor=#C9C62D bordercolor=#C9C62D ?php for ($l = 1; $l = $numcols; ++$l) { ? td class=prodName?php $db-p(product_name); ?/td ?php } ? /tr ?php } ? /table Anybody have any ideas how I can get this thing to work?! Thanks Luis __ Terrorist Attacks on U.S. - How can you help? Donate cash, emergency relief information http://dailynews.yahoo.com/fc/US/Emergency_Information/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Table display Driving me Crazy!
- Original Message - From: Adv. Systems Design [EMAIL PROTECTED] To: PHP List [EMAIL PROTECTED] Sent: Friday, September 14, 2001 12:09 AM Subject: [PHP-DB] Table display Driving me Crazy! Hello * trying to output mysql content into a table, but the table is designed to use 3 Trows to display info for ONE product (table also has to have 5 columns): row1 sku1|sku2|sku3|sku4|sku5 row2 img1|img2|img3|img4|img5 row3 nam1|nam2|nam3|nam4|nam5 - row4 sku6|sku7|sku8|sku9|sku10 row5 img6|img7|img8|img9|img10 row6 nam6|nam7|nam8|nam9|nam10 - etc... I have code that is displaying the right #of columns but it is simply repeating the product across the table... table width=100% border=1 cellspacing=0 cellpadding=0 bgcolor=#00 ?php $db-query($list); while ($db-next_record()) { ? tr bgcolor=#66 ?php $numcols = 5; for ($l = 1; $l = $numcols; ++$l) {? td width=139 class=ModNo bordercolor=#00?php echo $db-f(product_sku); ?/td ?php } ? /tr tr bgcolor=#ECEF7A ?php for ($l = 1; $l = $numcols; ++$l) { ? td height=80 bordercolor=#00 div align=centerA HREF=?php $sess-purl(URL . ?page=$flypageproduct_id= . $db-f(product_id) . category_id= . $db-f(category_id)); ? ?php $ps_product-show_image($db-f(product_thumb_image),); ?/A /div /td ?php } ? /tr tr bgcolor=#C9C62D bordercolor=#C9C62D ?php for ($l = 1; $l = $numcols; ++$l) { ? td class=prodName?php $db-p(product_name); ?/td ?php } ? /tr ?php } ? /table Anybody have any ideas how I can get this thing to work?! Looking at your code for the first row (I've cleaned it up a bit to make it readable!): ?php $numcols = 5; for ($l = 1; $l = $numcols; ++$l) { ? td width=139 class=ModNo bordercolor=#00 ?php echo $db-f(product_sku); ? /td ?php } ? It should be pretty clear why you're getting the product just repeated 5 times across the row. Your statement: echo $db-f(product_sku); does not contain any reference to variables thus it's essentially a constant. As far as I can make out (your style of coding gives me a headache :)) the other loops suffer from the same problem. If you find yourself often mixing php with html then using the alternative syntax for constructing loops makes the code simpler and clearer (see http://www.php.net/manual/en/control-structures.for.php). Also if your particular php setup allows using ? ? instead of ?php ? to enclose php code looks cleaner. For example the above can be rewritten as: ? $numcols = 5; ? ? for ($l = 1; $l = $numcols; ++$l): ? td width=139 class=ModNo bordercolor=#00 ? echo $db-f(product_sku); ? /td ? endfor; ? hth -- Jason Wong Gremlins Associates www.gremlins.com.hk Tel: +852-2573-5033 Fax: +852-2573-5851 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Table display Driving me Crazy!
Looking at your code for the first row (I've cleaned it up a bit to make it readable!): ?php $numcols = 5; for ($l = 1; $l = $numcols; ++$l) { ? td width=139 class=ModNo bordercolor=#00 ?php echo $db-f(product_sku); ? /td ?php } ? It should be pretty clear why you're getting the product just repeated 5 times across the row. Your statement: echo $db-f(product_sku); does not contain any reference to variables thus it's essentially a constant. As far as I can make out (your style of coding gives me a headache :)) the other loops suffer from the same problem. The whole block is wraped in a while ($db-next_record()) { ...} loop actually. Now, I'm not sure if the next_record() method is setting an internal member to the current record and returning TRUE/FALSE for success, or if it's actually supposed to be returning a row. I'm guessing the class is simply being mis-used. The code is reasonably logical assuming next_record() is setting an internal member variable to the current row... doesn't look like it is though. I know with ASP/VBScript that there's a decent performance hit when you jump from HTML to VbScript and back again... I would imagine though not as severe the same also happens in PHP. Rather than stop the parser, print out something small like a /td and start the parser back up it's probably better performance wise to just use the 'echo' function (well, keyword, I guess echo isn't a real function, print is though). Plus, it makes your code more readable without all the ?php ? marks everywhere. Justin Buist Trident Technology, Inc. 4700 60th St. SW, Suite 102 Grand Rapids, MI 49512 Ph. 616.554.2700 Fx. 616.554.3331 Mo. 616.291.2612 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Table display Driving me Crazy!
The whole block is wraped in a while ($db-next_record()) { ...} loop actually. Now, I'm not sure if the next_record() method is setting an internal member to the current record and returning TRUE/FALSE for success, or if it's actually supposed to be returning a row. It should be the former. But whatever it does, it doesn't change the fact that the code for displaying the 1st, 2nd and 3rd rows are in fact displaying a constant for each of the 5 columns. I'm guessing the class is simply being mis-used. The code is reasonably logical assuming next_record() is setting an internal member variable to the current row... doesn't look like it is though. If I'm not mistaken it looks to be using the phplib library. I believe it *is* being used correctly but he doesn't seem to be choosing the correct fields to display. I know with ASP/VBScript that there's a decent performance hit when you jump from HTML to VbScript and back again... I would imagine though not as severe the same also happens in PHP. Rather than stop the parser, print out something small like a /td and start the parser back up it's probably better performance wise to just use the 'echo' function (well, keyword, I guess echo isn't a real function, print is though). Plus, it makes your code more readable without all the ?php ? marks everywhere. In this case, yes, it's preferable to use echo. But if there are more than a few lines of html then using echo gets tedious pretty quickly (not mention having to escape all the s) :) regards -- Jason Wong Gremlins Associates www.gremlins.com.hk Tel: +852-2573-5033 Fax: +852-2573-5851 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Table creation problems...
- Original Message - From: Jonathan Halterman [EMAIL PROTECTED] To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Sunday, September 09, 2001 5:37 PM Subject: [PHP-DB] Table creation problems... $result = mysql_db_query($db, CREATE TABLE $groupid (`topicid` INT NOT NULL, `parentid` INT NOT NULL, `topic` TINYINT NOT NULL, `text` TEXT NOT NULL, `user` VARCHAR(20) NOT NULL, `lastactive` DATETIME NOT NULL, `created` DATETIME NOT NULL, `posts` INT NOT NULL , PRIMARY KEY (`topicid`), UNIQUE (`topicid`))); Could someone please tell me how I can use a long type, such as a table ID as the name of another table? try CREATE TABLE '$groupid' ... hth -- Jason Wong Gremlins Associates www.gremlins.com.hk Tel: +852-2573-5033 Fax: +852-2573-5851 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Table columns
Some does know ho to get column list using ODBC_COLUMNS functions? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Table Search ... HELP
Below is an example of my code which searches a table and prints the result, the problem is that it only displays the TechContact where I want it to display all the fields that associated with it in that row off the colum eg. Mobile, AdminContact etc etc Any suggestions? if ($TechContact == ) {$TechContact = '%';} $result = mysql_query (SELECT * FROM enet WHERE TechContact LIKE '$TechContact%'); print $row[TechContact]; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Table Search ... HELP
All the info you want should be in $result after the query. But to get it out of $result you need to access one row at a time with mysql_fetch_array($result), which returns a numerically keyed array (if I remember correctly), or mysql_fetch_assoc($result), which returns a string keyed array or hash. So, like this (more or less)... if ($TechContact == ){ $TechContact = '%'; } $result = mysql_query (SELECT * FROM enet WHERE TechContact LIKE '$TechContact%'); // this part added... while($row = mysql_fetch_assoc($result)){ print $row[TechContact]; print $row[SomeOtherColumnName]; print $row[YetAnotherColumnName]; print br\n; } On 2001.09.06 19:41:55 -0500 Devon wrote: Below is an example of my code which searches a table and prints the result, the problem is that it only displays the TechContact where I want it to display all the fields that associated with it in that row off the colum eg. Mobile, AdminContact etc etc Any suggestions? if ($TechContact == ) {$TechContact = '%';} $result = mysql_query (SELECT * FROM enet WHERE TechContact LIKE '$TechContact%'); print $row[TechContact]; -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Table results returning 2 sets of the same row
I used the code from this page http://php.net/manual/en/ref.mysql.php And my table results are shown 2 times per row. http://www.chizeledlight.com/test.php I also don't know how to specify the column I want the result from. Like $columnName. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] table 1 to table 2
I was thinking that MySQL doesn't support subselects ?! Or is there a new MySQL-Version which does support them ? Greetinx, Mike Michael Rudel - Web-Development, Systemadministration - ___ Suchtreffer AG Bleicherstrae 20 D-78467 Konstanz Germany fon: +49-(0)7531-89207-17 fax: +49-(0)7531-89207-13 e-mail: mailto:[EMAIL PROTECTED] internet: http://www.suchtreffer.de ___ -Original Message- From: Cal Evans [mailto:[EMAIL PROTECTED]] Sent: Monday, March 26, 2001 9:53 PM To: [EMAIL PROTECTED]; PHP-DB Subject: RE: [PHP-DB] table 1 to table 2 insert into table2 Select * from table1 where myConditionIsMet; Cal http://www.calevans.com -Original Message- From: Tobe Johnson [mailto:[EMAIL PROTECTED]] Sent: Monday, March 26, 2001 1:41 PM To: PHP-DB Subject: [PHP-DB] table 1 to table 2 Using PHP, I need to run a query against one MySQL database table (table1) and transfer the results into another identical MySQL database table (table2). Am I simply overlooking something simple on how to do this? Can someone give me input or direction on the best way to do this? Thanks in advance Tobe -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] table 1 to table 2
Using PHP, I need to run a query against one MySQL database table (table1) and transfer the results into another identical MySQL database table (table2). Am I simply overlooking something simple on how to do this? Can someone give me input or direction on the best way to do this? Thanks in advance Tobe -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] table 1 to table 2
insert into table2 Select * from table1 where myConditionIsMet; Cal http://www.calevans.com -Original Message- From: Tobe Johnson [mailto:[EMAIL PROTECTED]] Sent: Monday, March 26, 2001 1:41 PM To: PHP-DB Subject: [PHP-DB] table 1 to table 2 Using PHP, I need to run a query against one MySQL database table (table1) and transfer the results into another identical MySQL database table (table2). Am I simply overlooking something simple on how to do this? Can someone give me input or direction on the best way to do this? Thanks in advance Tobe -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]