Re: [PHP-DB] Joinging two different mySQL result?
Hehe, I ended up with a mile long sql query since I had to do some smart setup to make all tables work in the UNION. To distinquish between from where the data came from I did this Example (Look at the fromtable) (SELECT id, name, 0 as fromtable FROM table1 where blabla) UNION (SELECT id, company as name, 1 as fromtable FROM blabla) UNION (SELECT id, name, 2 as fromtable FROM blabla) Its not an optimal query thats for sure, but it makes the PHP code 10 times easier and the result is just marvelous. To think that I forgot all abou the UNION command, a shame, :D -- Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Joinging two different mySQL result?
Im wondering how It would be possible to join two different mySQL results into one set? To clear it up a little bit, say we have two different databases which are completely different but they both share fields name and email. I want to select all the emails and names from both databases and show them in table on the webpage. The first thing that comes to mind is : ALTERNATIVE 1 1. Select the results from table 1 (Which accually is a join select from 2 tables) 2. Select the results from table 2 (Which is a single table) 3. Spin through set one, and spin through set two. This creates a problem since we are talking about eg. 1000 records and I only show 20 a time on the screen with a nice next page in the bottom to browse the results. Another sollution could be : ALTERNATIVE 2 1. Select the results from table 1 (Which accually is a join select from 2 tables) 2. Select the results from table 2 (Which is a single table) 3. Create new array with needed fields, 4. Pump in results 1 5. Pump in results 2 6. Show and browse the array as if it was the accual query. This sounds practical, on the other hand a large set would be wasted bandwidth from the SQL engine and large arrays. Then again, theese queries arnt done often so I shouldnt care to much about the hardware, there shouldnt be more than 10.000 records either at max. (Sure, you never know but statistically there shouldnt). Finally, another sollution, cache the result set : ALTERNATIVE 3 1. Check to see if we have a fresh cache? We dont so we go to point two 2. Select the results from table 1 (Which accually is a join select from 2 tables) 3. Select the results from table 2 (Which is a single table) 4. Create new cache table, punp in results set 1 and 2 5. Do the queries from cache table Anyone have some points on this? I would maby think alternative 3 would be best, or maby alternative 2? Maby you have some other alternatives? -- Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Joinging two different mySQL result?
Here are some tables to reflect the accual problem : So if you can select the two records in one query I would be very happy, :D What I want is this : users.id = users_info.cid I would like to select from users, usr (which is the email ) as email, aktiv, newsletter, emailblock, htmlmode, none_registered and * from users_info where users.id = users_info.cid At the same time from unregistered_users I would like epost, newsletter, htmlmode, newsletter, emailblock Theese two should be merged together, if at all possible. It would also be nessersary to include a new field which tells from what table the result came from, meaning did it come from users or from unregistered_users. Well, I might stick to ALTERNATIVE 3 it seems. DATABASE TABLES WITH 2 ENTRIES : -- CREATE TABLE `users` ( `id` int(11) NOT NULL auto_increment, `usr` varchar(100) NOT NULL default '', `pas` varchar(32) NOT NULL default '', `aktiv` tinyint(1) NOT NULL default '0', `aktivcode` varchar(10) NOT NULL default '', `level` tinyint(1) unsigned NOT NULL default '0', `price_group` tinyint(1) unsigned NOT NULL default '1', `shipping` tinyint(1) unsigned NOT NULL default '0', `suspend` tinyint(1) unsigned NOT NULL default '0', `newsletter` tinyint(1) unsigned NOT NULL default '0', `emailblock` tinyint(1) unsigned NOT NULL default '0', `emailstatus` tinyint(1) unsigned NOT NULL default '0', `emailcount` int(5) unsigned NOT NULL default '0', `htmlmode` tinyint(1) unsigned NOT NULL default '1', `timecreate` int(10) unsigned NOT NULL default '1071245466', `none_registered` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`id`), KEY `i_id` (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; INSERT INTO `users` VALUES (1, '[EMAIL PROTECTED]', 'testing', 1, '123', 1, 2, 1, 0, 1, 1, 0, 126, 1, 0, 0); CREATE TABLE `users_info` ( `id` int(11) NOT NULL auto_increment, `cid` int(11) NOT NULL default '0', `cstatus` tinyint(1) unsigned NOT NULL default '0', `navn` varchar(50) NOT NULL default '', `etternavn` varchar(50) NOT NULL default '', `adresse` varchar(100) NOT NULL default '', `postnummer` varchar(10) NOT NULL default '', `poststed` varchar(30) NOT NULL default '', `telefon` varchar(13) NOT NULL default '', `mobil` varchar(13) NOT NULL default '', `epost` varchar(100) NOT NULL default '', `brukernavn` varchar(100) NOT NULL default '', `passord` varchar(32) NOT NULL default '', `fdatod` int(2) NOT NULL default '0', `fdatom` int(2) NOT NULL default '0', `fdatoy` int(4) NOT NULL default '0', `extraa` varchar(50) NOT NULL default '', `extrab` varchar(50) NOT NULL default '', `extrac` varchar(50) NOT NULL default '', `extraba` varchar(255) NOT NULL default '', `extrabb` varchar(255) NOT NULL default '', `orgnr` varchar(15) NOT NULL default '', `fnavn` varchar(50) NOT NULL default '', `fadresse` varchar(100) NOT NULL default '', `fpbox` varchar(100) NOT NULL default '', `fpostnummer` varchar(10) NOT NULL default '', `fpoststed` varchar(30) NOT NULL default '', `lnavn` varchar(50) NOT NULL default '', `ladresse` varchar(100) NOT NULL default '', `lpbox` varchar(100) NOT NULL default '', `lpostnummer` varchar(10) NOT NULL default '', `lpoststed` varchar(30) NOT NULL default '', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), KEY `id_2` (`id`), KEY `i_cid` (`cid`), FULLTEXT KEY `all_fields` (`navn`,`etternavn`,`adresse`,`postnummer`,`poststed`,`telefon`,`mobil`,`epo st`,`orgnr`,`fnavn`,`fadresse`,`fpbox`,`fpostnummer`,`fpoststed`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; INSERT INTO `users_info` VALUES (1, 1, 1, 'Kim', 'Steinhaug', 'PB 8149 Vaagsbygd', '4622', 'Kristiansand', '8800945', '', '[EMAIL PROTECTED]', '', '', 0, 0, 0, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); CREATE TABLE `unregistered_users` ( `id` int(11) NOT NULL auto_increment, `navn` varchar(100) NOT NULL default '', `epost` varchar(50) NOT NULL default '', `htmlmode` tinyint(1) unsigned NOT NULL default '0', `aktivcode` varchar(15) NOT NULL default '', `newsletter` tinyint(1) unsigned NOT NULL default '1', `emailblock` tinyint(1) unsigned NOT NULL default '0', PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), KEY `id_2` (`id`) ) TYPE=MyISAM AUTO_INCREMENT=2 ; INSERT INTO `unregistered_users` VALUES (1, 'Steinhaug Webdesign', '[EMAIL PROTECTED]', 1, 'kozexyimoc', 1, 0); -- Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http
Re: [PHP-DB] Joinging two different mySQL result?
* John Holmes wrote : If you're using MySQL 4.0+ you can use UNION: Perfect! Unioin is my friend, our software is installed on several servers but I just checked them and 4/5 had 4 on mySQL, I can live with that. I need to do some smart quering to make them both identical in the resultsset but this will work like a charm, :D Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Mysql and rollbacks
I was about to suggest the same, the latest builds of MySQL have theese functions from what I knew... I think youll find what you need there. -- Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Peter Westergaard wrote: I'm developing a site where I anticipate the need to make several updates to several forms, and I'll want to commit them all at once (i.e. if there's a failure with any of the transactions, I'd like to be able to back out to before I started). Is there a decent way to do this with PHP and Mysql? Use InnoDB tables which have transaction support. Or use a database abstraction layer that simulates transactions such as ADOdb: http://phplens.com/adodb/tutorial.smart.transactions.html -- ---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] Re: addslashes replacement?
Take a look at the php website on the function addslashes. You will find an example with the functions reslash and reslash. You might have some problems regarding magic_quotes. Ive been using the reslash and deslash for some time now without any problems. It might solve your problems. -- Kim Steinhaug - There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. - www.steinhaug.com - www.easywebshop.no - www.easycms.no www.webkitpro.com - Ed Lazor [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm using php addslashes to store data into MySQL and php stripslashes when pulling it back out, but I'm running into trouble when people enter HTML code. Do you have any recommendations? Here's an example of what I'm talking about: input name=Title value=?php echo stripslashes($Entry[Title]);? An error occurs if the entry has a value of: this is a font color=redbtest/b/font. Are we having FUN yet? Any ideas or recommendations? Thanks, -Ed -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: problem....
Well, your query looked confusing to me, but break it up like this First : select Then, name your coloumns, seperate with commas, or use wildcard for all * Define from what table you need to select FROM database_table Add some select statements with WHERE WHERE and the statements itself 1=1 What did I just write now? Looking at your example I guess : 1. you need the coloumns : Rune, username 2. your table : RuneRunner 3. your select criteria : UserID=3 I would then write your SQL query as this : $sql = SELECT Rune, username FROM RuneRunner WHERE UserID=3; Then you could do your code, $pic = mysql_query($sql,$connection); $pic = mysql_fetch_array($pic); You would also want to add a database abstraction layer, as for debugging purposes this will make your life much easier. Your original code looks to correct if you rewrite it abit, like this : SELECT RuneRunner_1.Rune, RuneRunner_1.username FROM RuneRunner RuneRunner_1 WHERE (RuneRunner_1.User_ID=3); Not tested but it should work fine. On the other hand, the referencename after the table name should be a short one to make the statement much easier to read, somthing like : SELECT rr.Rune, rr.username FROM RuneRunner rr WHERE (rr.User_ID=3); Then again, since you only have one table in your statement there is no need for the reference name, and since your WHERE clause is a single statement there is no need for the paranthese either. So you are still back to : SELECT Rune, username FROM RuneRunner WHERE User_ID=3; -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Water_foul [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] why doesn't this work: $pic=mysql_query('SELECT Rune, username FROM RuneRunner RuneRunner_1 WHERE (User_ID = 3)',$connection); $pic=mysql_fetch_array($pic); -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Multiple Inserts
A simple way to debug your scripts would be like this : FROM : $result_timesheet=mysql_query(INSERT INTO tblTimesheet (TimesheetID, WorkerID, ClientID, TimesheetDate, ProspectiveOrRetrospective) VALUES ('$TimeSheetID','$WorkerID','$ClientID','$TimesheetDate','$ProspectiveOrRetr ospective'))or die(Insert Error: .mysql_error()); TO $sql = (INSERT INTO tblTimesheet (TimesheetID, WorkerID, ClientID, TimesheetDate, ProspectiveOrRetrospective) VALUES ('$TimeSheetID','$WorkerID','$ClientID','$TimesheetDate','$ProspectiveOrRetr ospective'); echo 'Query : ' . $sql . \nbr; $result_timesheet=mysql_query($sql)or die(Insert Error: .mysql_error()); It would atleast give you a good feeling on the data getting passed to mySQL if youre not getting any error message. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Achieve It [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello, I am using a form to Insert data into 2 tables in the same database. $TimesheetID needs to be in each table. However, it is not being inserted into the second table, tblTimesheetDetails . Any advise? $result_timesheet=mysql_query(INSERT INTO tblTimesheet (TimesheetID, WorkerID, ClientID, TimesheetDate, ProspectiveOrRetrospective) VALUES ('$TimeSheetID','$WorkerID','$ClientID','$TimesheetDate','$ProspectiveOrRetr ospective'))or die(Insert Error: .mysql_error()); $result_timesheetdetails=mysql_query(INSERT INTO tblTimesheetDetails (TimesheetID, ActivityTypeID, TimeSpentHours, TimeSpentMinutes) VALUES ('$TimeSheetID','$ActivityTypeID','$TimeSpentHours','$TimeSpentMinutes'))or die(Insert Error: .mysql_error()); Thanks, Declan. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mysql and indexes
use the EXPLAIN infront of your select query to see what indexes are in use. If you have a double index it wont hurt you, except that you are wasting twice as much space in your DB. This would also make your DB slower since the database needs to index both indexes all the time. Duplicate indexes should be avoided since there are no reason to have them. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Michael Gale [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello, I know this question is more mysql related then PHP with mysql .. but If I do a SHOW INDEX from table_name I see what appears to be two index for the same column ? table_name 0 PRIMARY 1 columnname A NULL NULL NULL table_name 0 columnname1 columnname A 6623 NULL NULL Could the multiple index cause a problem ? I am trying to speed up a DB query ? Michael. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] content managment systems
I love that site, really the best way to get familiar with the common systems out there. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Kenny [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi lisi, Have a look at www.opensourcecms.com They have all the popular CMS systems loaded on a server in one place so you can see them in action, once you find the one you like you can d/l it from there site as well Kenny -Original Message- From: Lisi [mailto:[EMAIL PROTECTED] Sent: 16 June 2004 10:11 To: PHP-DB Subject: [PHP-DB] content managment systems I am looking for open source CMSs that: 1) use PHP/Mysql 2) are relatively easy to install, for someone familiar with both PHP and MySQL 3) also easily allow you to change the layout/template from the default For instance, if I want to hire a graphic designer to create a static page for me with a unique design for my site, I want to be able to create a template file from that (possibly one template for the home page and a second one for inside pages) and then plug in a CMS into that layout (or plug the template into a CMS) so the client can then make any changes to any pages without having to go through me. I've heard PHP-Nuke is a very good portal system - would it work for this? Any other recommendations? The CMS must be open source, the budget is very limited right now. Thanks! -Lisi -- 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] value error in PHP form
Or $_GET[action]; $_GET[Name]; Do yourself a HUGE favour and start using _GET and _POST right away on all queries. Also look into the well known problems with addslashes with globals on while your at it. On php.net there are good explernations and examples, look into the reslash() and deslash() example. One of theese days youll wake up and globals are off by default. (Well, isnt PHP5 off?) The problem is, your are used to program with globals on... If you have like 50 clients who wakes up with globals off you are inn for a bad day (or week... ) When I first started with PHP I loved the globals, but the last year they have really pissed me off mostly. The best thing you can do is be sure your software works with globals off, and then take it for a test drive with globals on. It may sound trivial and annoying to read, but this is one of the major buggers of programming PHP - so do it now, :) You wont regret it I promise you. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Kenny [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] This could be due to register globals on/off Use print $_POST['action']; print $_POST['Name']; Kenny -Original Message- From: Rinku [mailto:[EMAIL PROTECTED] Sent: 20 June 2004 12:23 To: [EMAIL PROTECTED] Subject: [PHP-DB] value error in PHP form Dear All, I have installed PHP on WinXp. I am using MySql as Backend on Apache server. Now the problem is.. I am writing this code : html head title /head /title head body form name=frmname input type=text name=Name value=Rinku input type=submit name=action value=Login ? print $action; print $Name; ? /form /body /html Here I should get output as LoginRinku But I am getting nothing. Can any of you guide me on this? Regards, Rinku - Do you Yahoo!? New and Improved Yahoo! Mail - Send 10MB messages! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: HTTP header information
Another little nift thing ive learned to always do regarding headers, is to always - ALWAYS - after a location have an exit; Example : header(location: somewhere.php); exit; Ive learned that sometimes someting odd happens to the server and PHP delivers notices and errors to the browser. Sometimes something in your code could go wrong leading to a header not working the way intended. Point is, having the exit atleast stops the user from getting alot of stuff which he didnt accually want on the screen. I remember one of my earlier login systems, and if the login wasnt valid the user was sendt to the login page, pretty old fashioned. Problem was I didnt have an exit behind, and the webserver got a hickup. There happened someting wrong with the /tmp folder on the server so PHP issued an error on all pages that there was errors with the sessions, meaning something was printed out before my validation of the login, and the user accually got the content he wasnt allowed to see, :) This is abit off topic, but you never know. Headers are headers, and small things are small things... Good luck. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- James Harrell [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Make sure that NO output is done before session_start() is called. Can you post some of your code? See, that's the case. Because I'm essentially just changing the content within the page, it never leaves the page 'viewer.php' - it just changes the content by tacking on '?type=login, submitproblem, etc'. Look for an errant space or CR after your original closing PHP tag. Also check the file CR/LF/EOF spec is the same as that of your server. For example, if your server is unix and your dev machine in Win32, dos2unix the file to make certain there are no extra characters after the closing php tag. Any output- even a space or extra CR/LF will cause PHP to send the headers. James -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Count unique visits in PHP/MySQL
Whatabout creating a table containing online users, where you log every activity with IP, BrowserSession and Timestamp. You also create a table to track the accual unique visits. So my logic to solve it : Update the online table like this (Some rough coding below, not tested at all, read the logic). 30 minutes = 60sec*30 = 1800 1delete from online where timestamp . (time() - 1800); // Delete inactive users / uniqe ghosts or whatever 2Update online set timestamp = ' . time() . ' where ip=' . $ip . ' and browsersession = ' . $browsersession . '; 3If (!mysql_affected_rows()){ // Update the Unique visitor table // Insert new entry with IP, Browsersession and time() into the online database } As far as my midnight brain would see it this would work nicely. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] ast.net... I am making a PHP/MySQL traffic report page from a table that records some user activity using PHP referrer information. I have a table with three rows: IP, page_name, and timestamp. The IP row records the user's IP address, page_name records the name of the page that the user loaded, and the timestamp row records in Unix timestamp format the time of day that the user requested the page. I want to be able to count unique visits per IP according to Internet Advertising Bureau standards, which count a Unique Visit as a log in by the same IP once every thirty minutes. IAB verbatim definition: Visit - One or more text and/or graphics downloads from a site qualifying as at least one page, without 30 consecutive minutes of inactivity, which can be reasonably attributed to a single browser for a single session. A browser must pull text or graphics content to be considered a visit. So I need to make a MySQL query that will count how many times an IP logged a timestamp within a given time period. For example, the publisher checking traffic could request a date between May 1 and May 31, and I'd like to be able to return a page that counted unique users (count distinct IP), pages viewed (list distinct pages) and how many times they visited in that period. I have the first two down, but not the unique visits. Any ideas? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Combining 2 queries into 1?
I have theese two queries : select count(*) as online from online where uid=''; select count(*) as online from online where uid!=''; Each online user has a uid (UserID), so if their logged inn this field will represent their unique uid. If not logged in its set to nothing. To detect how many online users the first query tells me all the anonymous users and the second gives members. Since theese two queries are fired on every page hit, I would assume that if I could join theese queries into one I would atleast save the mysql for a 50% of the queries. Ive veeb experimenting on the count(expression) without any luck, probably since the server is running v4.0.17-standard So I wonder - is there any way I could join the above queries into one single query? Ofcourse I could easily add another field for the database, something like temp which is NULL for anonymous and 1 for user if this makes is easier to group the the query in some wmart way I havnt figured out at the moment. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Combining 2 queries into 1?
And ofcourse, one part I didnt take into the equation, one complex query doesnt always execute faster than two fast queries. So I might as well be sure that the environment is optimized for the two queries im already having... I still however would like to know if its possible to join the two into one. Thanks in advance. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Kim Steinhaug [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have theese two queries : select count(*) as online from online where uid=''; select count(*) as online from online where uid!=''; Each online user has a uid (UserID), so if their logged inn this field will represent their unique uid. If not logged in its set to nothing. To detect how many online users the first query tells me all the anonymous users and the second gives members. Since theese two queries are fired on every page hit, I would assume that if I could join theese queries into one I would atleast save the mysql for a 50% of the queries. Ive veeb experimenting on the count(expression) without any luck, probably since the server is running v4.0.17-standard So I wonder - is there any way I could join the above queries into one single query? Ofcourse I could easily add another field for the database, something like temp which is NULL for anonymous and 1 for user if this makes is easier to group the the query in some wmart way I havnt figured out at the moment. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Combining 2 queries into 1?
After crawling through the MySql reference I finally found the function I was looking for, the sollution for combining theese two queries would be : SELECT count( * ) AS online_anonymous, sum( sign( uid ) ) AS online_members FROM `database` I also benchmarked this and the performance went just as I hoped, I run a series of x200 and x500 queries within a loop and took the time. Tests are done at the live system on the production server som Im pleased with the result, 200x Test 1 in 0.2965 sekunder, 2x queries. 200x Test 2 in 0.1633 sekunder, combo query. 500x Test 1 in 0.8041 sekunder, 2x queries. 500x Test 2 in 0.3949 sekunder, combo query. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Kim Steinhaug [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] And ofcourse, one part I didnt take into the equation, one complex query doesnt always execute faster than two fast queries. So I might as well be sure that the environment is optimized for the two queries im already having... I still however would like to know if its possible to join the two into one. Thanks in advance. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Kim Steinhaug [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have theese two queries : select count(*) as online from online where uid=''; select count(*) as online from online where uid!=''; Each online user has a uid (UserID), so if their logged inn this field will represent their unique uid. If not logged in its set to nothing. To detect how many online users the first query tells me all the anonymous users and the second gives members. Since theese two queries are fired on every page hit, I would assume that if I could join theese queries into one I would atleast save the mysql for a 50% of the queries. Ive veeb experimenting on the count(expression) without any luck, probably since the server is running v4.0.17-standard So I wonder - is there any way I could join the above queries into one single query? Ofcourse I could easily add another field for the database, something like temp which is NULL for anonymous and 1 for user if this makes is easier to group the the query in some wmart way I havnt figured out at the moment. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Combining 2 queries into 1?
Thanks for your response, however you missunderstood my question. I just posted the sollution in this thread over. I was looking for a query that gave me the total amount on users which had a userID and the total without a userID. Selecting (*) would give me both the anonymous and logged users. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Jonathan Hadddad [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] How about select count(*) from online Jon On May 30, 2004, at 1:23 PM, Kim Steinhaug wrote: I have theese two queries : select count(*) as online from online where uid=''; select count(*) as online from online where uid!=''; Each online user has a uid (UserID), so if their logged inn this field will represent their unique uid. If not logged in its set to nothing. To detect how many online users the first query tells me all the anonymous users and the second gives members. Since theese two queries are fired on every page hit, I would assume that if I could join theese queries into one I would atleast save the mysql for a 50% of the queries. Ive veeb experimenting on the count(expression) without any luck, probably since the server is running v4.0.17-standard So I wonder - is there any way I could join the above queries into one single query? Ofcourse I could easily add another field for the database, something like temp which is NULL for anonymous and 1 for user if this makes is easier to group the the query in some wmart way I havnt figured out at the moment. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- 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] Re: merging a table from multiple servers
Well, I would do the following, lets assume some servers here : Server1 - Your server Server2 - Someone you want data from Server3 - Another one you want data from I would create a script which must be installed on every server you need data from, call it generate.php for example. This script would pull out all the data your would want to use on your site, format the the data however youd like it, as a CSV file, MySQL queries or whatever. Each generate script will write back to the file : batch.txt for example. (Or it could spit out the results as you trigger the scrupt, but incase there are many servers you would encounter the 30second limit on PHP scripts). For the case of argument we say that the generate.php script spits out the results the way you want them. What your server would need to do then would be the following : You could use fopen to trigger each generate.php file like this from your site : --- function fetchpage($page){ $fd=fopen($page,r); while ($line=fgets($fd,1000)) { $text.=$line; } fclose ($fd); return $text; } $data2 = fetchpage('http://server2/generate.php'); $data3 = fetchpage('http://server3/generate.php'); --- You now have all you need in $data and $data2, you would then pull your own stats into $data1 and do whatever you like with this. You could pump all the results into a new table for statistics, or do it at once and present the result as a HTML. You should also create a trigger or something for this script so that it doesnt run on every pageload, maby once an hour or something. I hope you got the the hang of it. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Seth Bembeneck [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] How would I generate the file? Make each record 1 line in the file? After the file is created, how do I download it? Thanks, Seth Kim Steinhaug [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I would imagine the best way would be a system that triggers a script on the different serveres. This script creates a datafile which you import with fopen and then you create the database set you need to generate nice stats from. Else you would need the different servers to accept incoming connections on their MySQL from your host, which I would think would be alot of work to accomplish. Preparing datasets on the different servers with a script sounds much more simple in my opinion, after all this script will only be updated at given intervals. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Seth Bembeneck [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm trying to work on a project that gathers info from different servers, then combines them and displays it. Is it possble to merge the tables from the different servers into 1 table using php? My one solution to this was to have a php script on each server, then have my website call each php script, retrieve the info then insert it into my database. For a glimps of the amount of data I'm trying to merge: http://cwhq.net/index.php?action=statsmod=kill_stats_totals Now imagine 10 different servers with similer data. I'm trying to provide a way for Deltaforce Gamers to see their stat from all the game servers that collect the stats in 1 location. Thanks, Seth -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Procedure for submitting an order via email
You dont want an example, you are looking for a finnished piece of code to glue into your site. Your asking for a given example of a not given system? Different stores uses different ways of collecting data. Some databases, some cookies, some even stores the basket in sessions. Throwing a form fields into the mix doesnt make the question easier to answer. What you are asking in car repair terms would be something like : How do I repaird the engine? Either come with more information, and accuall code you are using, then some people here might be able to supply you with the answers you are looking for. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Ruprecht Helms [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] On 1 May 2004 at 22:47, Ignatius Reilly wrote: With the PHP IMAP functions you can process your mail box programmatically as a data repository. nice to know. What I want is an scriptexample for a checkoutprocedure of a online-store. I want submit via email the content of a basket, that is stored in a databasetable, some formfields and the mailreceiver taken from another databasetable. Regards, Ruprecht Ruprecht Helms IT-Service Softwareentwicklung Tel./Fax +49[0]7621 16 99 16 Web: http://www.rheyn.de email:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: another strange MYSQL problem
What I suggest you do, run phpMyAdmin (Or whatever you use) and dump the table structure for your table. Also give us a few lines of typical data from your table. Your queries looks correct to me. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hello, First, I use this, and all is ok: SELECT * FROM modele WHERE marca='Aprilia' ORDER BY tip ASC. Then, I use this: SELECT * FROM modele WHERE marca='Cagiva' ORDER BY tip ASC and the records are not ordered ascending by the field tip. In the first case, the records were ordered. Anyone knows what is wrong? Thank you! Best regards, Marius Panaitescu -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Optimize Tables
Another question... Why is it that you feel you need to optimize this? There really isnt any need as far as I can see. The overhead is really small, and will probably go up and down by itself since you have people adding and deleting from the table all the time. If we were talking many MB I could understand you, but a few hundred KB is really silly spending so much time avoiding since it will appear in 5 minutes again when people delete something from your table. Another way to completely remove the overhead is to not let people delete from the table, instead you flag the data as deleted. Gives you larger tables, but no overhead. I guess you have made indexes for your database if you have a lot of select in it, thats far more important than optimizing at the moment. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Ng Hwee Hwee [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, Is there a way to create a schedule to optimise my MySQL tables automatically? The overhead of some of my tables can reach 355,548 bytes over 3 working days! Please help me! Thanks. Hwee -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: merging a table from multiple servers
I would imagine the best way would be a system that triggers a script on the different serveres. This script creates a datafile which you import with fopen and then you create the database set you need to generate nice stats from. Else you would need the different servers to accept incoming connections on their MySQL from your host, which I would think would be alot of work to accomplish. Preparing datasets on the different servers with a script sounds much more simple in my opinion, after all this script will only be updated at given intervals. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Seth Bembeneck [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I'm trying to work on a project that gathers info from different servers, then combines them and displays it. Is it possble to merge the tables from the different servers into 1 table using php? My one solution to this was to have a php script on each server, then have my website call each php script, retrieve the info then insert it into my database. For a glimps of the amount of data I'm trying to merge: http://cwhq.net/index.php?action=statsmod=kill_stats_totals Now imagine 10 different servers with similer data. I'm trying to provide a way for Deltaforce Gamers to see their stat from all the game servers that collect the stats in 1 location. Thanks, Seth -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How to get only 2nd row in result set ???
DOH! - A private message arrived read below When you mention it, ofcourse this is the correct (and sane sollution). I guess I was giving more flesh to the bone that the previous poster posted. Looping through when limit is there is plain and simple stupid... Shame on me! :) Kim Steinhaug - Original Message - From: Ross Honniball ross at bookshop dot jcu dot edu dot au To: Kim Steinhaug [EMAIL PROTECTED] Sent: Monday, April 05, 2004 4:18 AM Subject: Re: [PHP-DB] How to get only 2nd row in result set ??? If you specify LIMIT 2,1 then this will only return 1 record (ie. the second parameter is the number of results to return) At 06:17 AM 5/04/2004, you wrote: I would say the same, do the query and then a loop through the results. Skip the first one and output the second, eg. $levels = mysql_query(SELECT levelID from hf_levels ORDER BY levelorder RB DESC LIMIT 2) or die('Unable to get levelsbr'.mysql_error()); for($i=0;$imysql_num_rows($levels);$i++){ $item = mysql_fetch_object($levels); if($i){ // Do the output with the new object, $item break; } } -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Mikhail U. Petrov [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi! But what's the problem? You can use mysql_fetch_array() 2 times. But may be I understood question not correctly... Friday, April 2, 2004, 10:06:05 PM, -{ wrote: RB I couldn't find anything like this from my archive searches ... so here goes: RB I've got this query: RB $levels = mysql_query(SELECT levelID from hf_levels ORDER BY levelorder RB DESC LIMIT 2) or die('Unable to get levelsbr'.mysql_error()); RB but I can't figure out how to write the rest of the code ... I need to skip RB the first row and get the data from the 2nd row... but because there's an RB optional up to 255 possible rows in this table, and the order of these are RB determined by a user customizable field called levelorder ... so I can't RB just pick the specific numrows - 1 ... :-/ RB I know this is a kludge to do it this way ... but it's what I need for now RB ... later I'll get to do it a more brilliant way... RB TIA RB Rene RB -- RB Rene Brehmer RB aka Metalbunny RB ~ If you don't like what I have to say ... don't read it ~ RB http://metalbunny.net/ RB References, tools, and other useful stuff... RB Check out the new Metalbunny forums @ http://forums.metalbunny.net/ -- Best regards, Mikhail U. Petrov mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php . Ross Honniball JCU Bookshop Cairns Supervisor . James Cook Uni, McGreggor Rd, Smithfield, Qld. 4878, Australia . Ph:07.4042.1157 Fx:07.4042.1158 Em:[EMAIL PROTECTED] . There are no problems. Only solutions. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] How to get only 2nd row in result set ???
I would say the same, do the query and then a loop through the results. Skip the first one and output the second, eg. $levels = mysql_query(SELECT levelID from hf_levels ORDER BY levelorder RB DESC LIMIT 2) or die('Unable to get levelsbr'.mysql_error()); for($i=0;$imysql_num_rows($levels);$i++){ $item = mysql_fetch_object($levels); if($i){ // Do the output with the new object, $item break; } } -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- Mikhail U. Petrov [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi! But what's the problem? You can use mysql_fetch_array() 2 times. But may be I understood question not correctly... Friday, April 2, 2004, 10:06:05 PM, -{ wrote: RB I couldn't find anything like this from my archive searches ... so here goes: RB I've got this query: RB $levels = mysql_query(SELECT levelID from hf_levels ORDER BY levelorder RB DESC LIMIT 2) or die('Unable to get levelsbr'.mysql_error()); RB but I can't figure out how to write the rest of the code ... I need to skip RB the first row and get the data from the 2nd row... but because there's an RB optional up to 255 possible rows in this table, and the order of these are RB determined by a user customizable field called levelorder ... so I can't RB just pick the specific numrows - 1 ... :-/ RB I know this is a kludge to do it this way ... but it's what I need for now RB ... later I'll get to do it a more brilliant way... RB TIA RB Rene RB -- RB Rene Brehmer RB aka Metalbunny RB ~ If you don't like what I have to say ... don't read it ~ RB http://metalbunny.net/ RB References, tools, and other useful stuff... RB Check out the new Metalbunny forums @ http://forums.metalbunny.net/ -- Best regards, Mikhail U. Petrov mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Tree structure - how to show only current branch ??
Well, I did a similar system for my CMS sollution. If I understand you correct you want to sort the main branch, keeping the subs. The sorting was in my case the part that I spent most of the time coding. The other part, selecting the subs I did really simple. As a main rule, I only select the main branch and order them, as a sub query I check if there are pages assigned to this branch. If so - present an icon to open the branch with a link link ?branch=999 Lets loop over this again with some more logic, if the $_GET[branch] corresponds with the branch currently in the result set im looping through ill print out the results, we also include a branch close icon with reverse effect, why this is explained below. Else, I skip this and continue with the next branch. Whats bad with this? Only 1 branch can be opened at a time, so what you do is assign the branch variable to the session. Push the variable into an array, and if the branch from the current result set is in the array open it. This way we can keep track of unlimited branches, opened and closed. Together with the close function they get wiped from the array and therefore closes. Hope this helps, maby its was just swada.. :) -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Newbie question
Well, Could be some sort of debugging mode on the PHP running on the server. On the other hand your script is depending on the fact that GLOBALS are turned on, which - you shouldnt. 1) Anywho - you form is using POST, so you should use this syntax : $_POST[variable], if using GET the equivilant is : $_GET[variable] 2) You should try to avoid putting variables inside quotes, unless you have a good reason for is. Meaning Hello $variable; should be written as : Hello . $variable; So the answer to your question would be, on the second page, and I also prefer echo instead of print. echo Hello . $_POST[name] . !; or echo 'Hello ' . $_POST[name] . '!'; -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] MySQL MaxDB mode
Hello! Ive been studying some of the new features from mySQL and I noticed that the timestamp autoupdate feature doesnt work in MaxDB mode of mySQL. ref : http://www.mysqlfreaks.com/mysql/manual_Reference.html What I wonder is, whats the difference (in short words) of running in MaxDB mode versus default installation? If MaxDB could be a fedault installation later there should be no reason for me to let mySQL autoupdate, rather hardcode as normal. I always hardocde theese features, but it feels comfortable using auto thingies, .) But only if theire not a problem in near future. -- -- Kim Steinhaug -- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- www.steinhaug.com - www.easywebshop.no - www.webkitpro.com -- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Selecting between using letters
Im on my way to bed so short do it yourself answer, but you should look up the regex part of mySQL. I think you can match the beginning and end of a coloumns entry. And using the power of the regex function you could make a WHERE statement for somethink like [a-e] if it was a-e you were looking for. Remember ofcourse that you wuld need to use the regex syntax. The page on mySQL covering the topic has a lot of examples. -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Doug Parker [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] How would I create a select statement in MySQL that would return a range of records from the LastName field where the value starts with a designated letter - for example, returning the range where the first letter of LastName is between A and E... Any help would be greatly appreciated. http://www.phreshdesign.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Downloading PHP source from a PHP filename, possible?
What you do is, if my logic is correct... Read the entire file in to a variable and send it back to the browser with another header information, typicall TEXT. Just like the force download method for a PDF file, or other files. This should work very well. -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Jerry [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I am not sure if this is at all possible but here goes. If a file is called blah.php and is only tailored to PHP code is it possible to make it downloadable either as a file-download or appear as plain text in a browser window? So if you visit blah.php it would show the PHP page normally and work it's functions. However is it possible to include a button on the page and or link that will actually download the PHP code to your computer? Keeping the filename as blah.php to save as. So it uses 1 file not 2, and somehow PHP functions to download when a button or link is clicked. Does that make sense? If not please reply and I'll try and explain better. Thanks for your time. Jerry 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: AW: [PHP-DB] image resizing
Imagemagick is THE preferred sollution, since downsizing images makes them blurry. With imagemagick you can sharpen then afterwards, and they are brand new shiny funky thumbs! There is a tutorial on phpbuilder.com which describes and shows a live example on how to incorporate the ImageMagick power into your scripts. You do however need to install the ImageMagick module on the server (windows is easy, hust depack the files and point to migrify.exe, no need to install it its just a bunch of DLLs). If your hosting provider doesnt want to install ImageMagick, you have to use GD. Nice class for GD just released on phpclasses.org by the way. You need however to reprogram some og the scaling functions, as they are a bit unfinnished. I use GD as a backup, in case ImageMagick isnt present on the server. But then I get those blurry ones I dont like... -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Christopher Ostmo [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Stefan Siefert pressed the little lettered thingies in this order... There are several possibilities to do this... first PHP has the possibility to use the GD - Libs (which doesn't support Gif's because of licence problems). The second (and in my opinion better) posibility is ImageMagick which are some programs to modify pictures (you have to call them externaly from your php - scripts) (www.imagemagick.org). I think, I have seen several Tutorials to do so (PHP/ImageMagick) but on the fly.. I don't find them in my bookmarks now... Hope this helps, Stefan Siefert -Ursprungliche Nachricht- Von: Adv. Systems Design [mailto:[EMAIL PROTECTED] Gesendet: Montag, 9. Juli 2001 16:04 An: [EMAIL PROTECTED] Betreff: [PHP-DB] image resizing Is there a way of sizing image resolution on the fly? TIA If you have ImageMagick, you only need to use the mogrify command: exec(/usr/local/bin/mogrify -geometry 300x300 image.jpg); This isn't built in to PHP, but it works very well if you have access to it. Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Innovative Application Ideas Meeting cutting edge dynamic web site needs since the dawn of Internet time (1995) For a good time, http://www.AppIdeas.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Validating a Session value
First you need to alter you else if statements, you write : If $session_ValueA $100 and $499 set $session_fee=$20 I would write : if(($session_ValueA =100) and ($session_ValueA =499)){ $session_fee=20; } And as you see, you cant evaluate $20 since PHP doesnt know that $20 is 20 dollars. It assumes its a variable with name of 20. The $ (dollarsign), in your case, is just for show. Same goes for the fee. You will need to work with the numbers only, knowing their currency, then when you print it out you can typically : echo '$' . $session_fee; Have another go! -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Aleks Kalynovych [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi all, I am trying to figure out a way to calculate a value based on another value and then set that value in a session variable. So, if $session_ValueA = $100 set $session_fee = $10 Or If $session_ValueA $100 and $499 set $session_fee=$20 Or If $session_VAlueA $499 and $999 set $session_fee=$50 Or something like this., I have to evaluate $session_ValueA to 6 possible values. Once this is done, I also would like to be able to calculate a % of Session_ValueA As commission. I tried to use If, Else but can't seem to get it right.. Any suggestions?? Thanks Aleks = -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: send email
Well this shouldnt be any problem. I suspect you dont know how to set up the email routine since your asking. All you need to do is insert a sendmail script together with the update of the mySQL database. You could use PHPs internal functions for this, but Ill recommend you using PHPmailer which is heavily documentet with tons of examples on how to use. The PHPmailer is located at sourceforge and you should find it right away. It has to be the most elegant way I know of sending emails from PHP scripts. And as a bonus, the PHPmailer is under active development so you will most likely never run into problems using it, :) -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Redhat [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] I have created a simple form that dumps input information into a mysql database. The person that I created it for said it would be nice if it would also notify him by email that an entry was added to the database. I have no idea where to begin with that - any ideas? thanks, DF -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Quering the mySQL DB for statistics results - best way of doing this
Hello, Im about to write a script that will generate several reports from a database which loggs all visits. I see that my script will need alot of queries against the database whenever a report is generated, and I would love to get some input from you if my way of solving this is bad. Example, I have a database filled with informations stored from each visit, I will only focus on the IP data just here. What I want to do is, pull out the visits ald present theese on the screen. This is 1 query, and the result gives me a mile long page. To make it a little better I want to group all the IP, this will give me a much shorter list. From what Ive understood the group by statement will solve this, but then I wont know the exact number of each IP. I therefore need to do an extra database query for each and every IP, right? Look at this code : function query(){ // DB Abstraction layer } $allrecords = query(select * from stats group by ip); for ($i = 0; $i mysql_num_rows($allrecords) ; $i++) { $record=mysql_fetch_object($allrecords); $temp = mysql_fetch_object(query(select count(*) as count from stats where ip='.$record-ip.')); $ipcount = $temp-count; echo 'Echo out needed $record data, this ip has ' . $ipcount . ' entries.br'; } echo $i . Records totalbr; This code will generate a heck of a lot of queries againt the mySQL database, but is it possible to do this another way? This is just one problem, other reports may dig further into the database and require more queries if using the above method. By the way, if you know of any recourses for report making and such I would love to see them, :) -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Quering the mySQL DB for statistics results - best way of doing
Thanks for your ideas, im sitting here drinking beer and drinks, so Im having a little difficulty grasping the whole idea with this new SQl statement, but it works! Thanks a lot. To help the other people reading this who might not get it I did some benchmarking, my method (mentioned in the beginning in the thread) : Time - 0.3663 I altered the routine, from 114 nested queries (my dataset) into 1 single query from Justin Patrin like this : $sql = select ip, count(*) as ipcount FROM stats Group By ip; $allrecords = query($sql); for ($i = 0; $i mysql_num_rows($allrecords) ; $i++) { $record=mysql_fetch_object($allrecords); echo $record-ipcount . '-'; } Time - 0.0101 Remarkable difference indeed! Im just happy that I just made 1 single report script at the moment using my rather terrible queries... :) Thanks for the help Justin! -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Justin Patrin [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Whoops, forgot the rest of the fields. SELECT COUNT(*) AS count, * FROM stats GROUP BY ip Note that this will not work on Oracle and some other DBs. It will work in MySQL. Oracle will only let you do: SELECT COUNT(*) count, ip, FROM stats GROUP BY ip Justin Patrin wrote: You can do it all in one query, just as you're already doing it: SELECT COUNT(*) AS count FROM stats GROUP BY ip Kim Steinhaug wrote: Hello, Im about to write a script that will generate several reports from a database which loggs all visits. I see that my script will need alot of queries against the database whenever a report is generated, and I would love to get some input from you if my way of solving this is bad. Example, I have a database filled with informations stored from each visit, I will only focus on the IP data just here. What I want to do is, pull out the visits ald present theese on the screen. This is 1 query, and the result gives me a mile long page. To make it a little better I want to group all the IP, this will give me a much shorter list. From what Ive understood the group by statement will solve this, but then I wont know the exact number of each IP. I therefore need to do an extra database query for each and every IP, right? Look at this code : function query(){ // DB Abstraction layer } $allrecords = query(select * from stats group by ip); for ($i = 0; $i mysql_num_rows($allrecords) ; $i++) { $record=mysql_fetch_object($allrecords); $temp = mysql_fetch_object(query(select count(*) as count from stats where ip='.$record-ip.')); $ipcount = $temp-count; echo 'Echo out needed $record data, this ip has ' . $ipcount . ' entries.br'; } echo $i . Records totalbr; This code will generate a heck of a lot of queries againt the mySQL database, but is it possible to do this another way? This is just one problem, other reports may dig further into the database and require more queries if using the above method. By the way, if you know of any recourses for report making and such I would love to see them, :) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: sendmail
You should check out phpmailer at sourceforge. It solved all my problems, and will probably solve all yours to. As a bonus, you get a mailer that has a lot of more functions, like attachements and HTML mail and such. -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Unknown Sender [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi Sorry to be off topic but I have problem with sendmail If anyone know sth about sendmail please e-mail priv. Sorry once more [EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Mail problem
Well, i've developed such a system, MarketMAX. And ill just give you a little tip here : 1. Dont use BCC field, it look bad and your not able to populate the emails from your database, eg. Dear %username% Ofcourse if your bulksend the same message, always, then BCC could spare your from headache. 2. THE TIMEOUTS! Be aware, very aware, not only do you need to account for php timeout, you also should be very aware of standard sendmail configuration regarding spam. Most installations ive encountered does not like say. 500 emails dumped at them during a few seconds. They will probably detect you as spam, and all the mails are deleted. The best part, all cases Ive encountered, you dont get an error so you think everyuthing is swell - It isnt! What you need to do is a) create a cron job that bulk sends. eg. 50 emails each 10 second or such. My sollutions was to create a batch system that pulls the 50 last entries from the batch list, prints out the html page with a 5sec meta refresh. This keeps looping till there is no emails left. You might be lucky to be on a system that doesnt care how many emails sendmail spews out, but this is in fact bad. If this is happening, you probably will experience someone taking advantage of the system resulting in the server IP getting blacklisted - and this is very bad for all users. But if you do it right, and also create a lot of what if scenarios, you should be just fine. Happy programming! -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Craig Roberts [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] It might be a good idea to set a cron job to send say, 100 at a time over the space of a few hours, to avoild killing the mail server or the server blocking connections from you. Also - use the BCC field to send the mail, this means only one connection will need to be made to the mail server per batch of addresses, as opposed to a connection per address (saves bandwidth and mail server!). The mail server will then send the messages where they need to go and hide all the other recipents. Craig Roberts Mak [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Beware though...if there are too many addresses in the db, you may encounter timeouts, or your browser may crash (very likely). Increase the timeout before you do such a mass-mail job. Also, my comment: If you do not want your receivers to find out who else you sent the mail to, don't use the CC method. Just: for(until max. users reached){ send out new mail to current user } Yours sincerely, Mak Jj Harrison\ [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] maybe use a for loop and mail command. should work Or put all the addresses in a CC/BCC field maybe sending every 100 emails to prevent a mail overload/blockage due to to many recipients etc. Hint: look here: http://www.php.net/manual/en/language.variables.php and you can find a way to append more to an existing variable. Very useful in your case. -- JJ Harrison [EMAIL PROTECTED] www.tececo.com Unknown Sender [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Sorry to be a little bit off topic. I need a tool or script in PHP, that will automaticaly send e-mails to receipients taken from database. For example 1 the same e-mail to 1000 receipients. B Mail server is on different machine. Thanks in advance -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP problem
4 words! i dont believe you! -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Unknown Sender [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Unfortunately, it doesn't work, the same situation Sorry to be a little bit off topic i have code that generates: OPTION LABEL=1LONG TEXT 1 use: option value=1long text 1/option mvgr, Joffrey van Wageningen -- .-[ Joffrey van Wageningen | WoLFjuh | [EMAIL PROTECTED] ]-- | Networking Event 2000 - www.ne2000.nl - IRCnet:#ne2000, Undernet:#clue | PGP:1024D/C6BA5863 - 3B93 52D3 CB91 9CB7 C50D FA79 865F 628A C6BA 5863 | * We demand guaranteed rigidly defined areas of doubt and uncertainty. | -- Douglas Adams -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- Okresl Swoje potrzeby - my znajdziemy oferte za Ciebie! [ http://oferty.onet.pl ] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: debugging / help required urgently.
Not exactly your answer, but I remember having same problems one time. I switched and started using phpmailer, http://phpmailer.sourceforge.net/ This has in the past never given me problems, 1 time I had problems on the server using the php functions, but phpmailer even has SMTP support. Just alter 1 line and everything is online again. mail() function may be more than good enough, but you might want to check out the phpmailer which is quite awesome! -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Jerry [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi, I have a MAJOR problem with PHP mail() function, one that is odd and very frustrating as I have no idea what is causing it. I have used the one script to send emails out in the past and they have been sucessfully sent out, but as of a few days ago and now they are bouncing, some are actually being sent and some just simply won't go out. So let me explain. I have an admin area of my site where I have all users in a mysql database. Their email address, names, address, etc. The admin side allows me to do many tasks like send out text-based emails via PHP mail() function and HTML emails. What it does is I type in the field boxes and saves to a mysql table, than I run a cronjob to grab the email data and email addresses and send out using PHP mail(). The script worked fine in the past, no problems but now I get the following message when I attempt to send emails: --- This message was created automatically by mail delivery software. A message that you sent could not be delivered to one or more of its recipients. This is a permanent error. The following address(es) failed: [EMAIL PROTECTED] unrouteable mail domain cashgrace.com --- But that's not all, it comes up as that for all domains, like yahoo.com, hotmail.com, bigpond.com etc... All of them, even though they are reachable via webmail. I can go into webmail via CPANEL and send emails and they actually go to the person, so does not seem like a mail server problem or does it? I beleive, but could be wrong, it is somewhere in the mail() function on the root part of the server. But of course I don't have access to it. But the weird thing is this... Some emails 1/10 do actually get sent and delivered, do not bounce, but the other 9 fail. Why? Well I did some more investigating... Well for what I have access to. The Server Load for the Server was flashing RED in the Server Status area. So I persume this is bad? Maybe due to this maybe it's attempting to send emails but looping and not got enough resources to actually do the job and in the end gives up and produces the bounced email? As I said before I could be way off track but worth suggesting and trying to figure it out. Is there a way to DEBUG my mail() function I call in the cronjob? The joy of the CRONJOB is that it's written in PHP also, so I can view it on a webpage. So if there is a way to DEBUG it I should see where the error is? Or won't I? Any suggestions? I've looked long and hard, emailed my admin and they are optimistic with the problem also so thought I'd post here and see what can be done and if we can get some outside help. As I said before the script for the mail() has NEVER been changed. So it can't be my code as it has worked in the past. Must be server side somewhere... Unless my admin has done an update and something has gone wrong. But I thought someone on here would know what could cause the error, at least we can investigate it instead of having no idea what is causing the problem. All the help is needed here if people can provide it. Thanks in advance, and sorry for the long email. But this problem is really giving me the 'you know what' now. Jerry 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] Optimal mySQL query for next prev page system
Thanks for the replies. Its time for me to start do some patching for my SQL statement, :) -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- John W. Holmes [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Adam i Agnieszka Gasiorowski FNORD wrote: Kim Steinhaug wrote: Then I query the mySQL database again to get the final result set, which I return together with the buildt prev/next htmlkode Instead of querying twice, use the SQL_CALC_FOUND_ROWS parameter of SELECT statement and then do a quick SELECT HIGH_PRIORITY FOUND_ROWS(); , to get the number of found rows (full number, ignoring LIMIT clause). You could also just do a SELECT COUNT(id) ... as your first query to just get the number of rows. Then do your query with limit. This is going to be more effecient than what you're currently doing. It'll also be more portable than the CALC_FOUND_ROWS method (although that's a perfectly valid method if you're sticking with MySQL). I'd have to run some benchmarks to see which is faster... -- ---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] Optimal mySQL query for next prev page system
Ive been using the same way of creating queries for the mySQL database the last years now, but as my databases keep growing Its time to start thinking of performance. My question however, is more if the way im doing this is the best way, or if I should reprogram all my queries in a more optimal way. The thing Im wondering about is the way I create my prev page 1 2 3 4 next page scripts. I will show the way I do it, and if you know a way that is more optimal or better, or you see any really dumb stuff here talking prosessing power please let me know. (And im using some abstraction layers for the accual queries, but they should not need to be optimized any further) 1. I build the query, and assign it to $sql $sql = select * from mydatabase; 2. I perform the query against the mySQL database $result = query($sql); 3. I check to see if I have any results at all, to verify if I will show content at all $num=mysql_num_rows($result); if(!$num){ // tough luck buster page! } else { // continue with the prev/next page routine } 4. Then I feed my prev/next routine with things as page, limit and such. $pn_putput=showNavigation($sql,$limit,$page); The showNavigation then, based on the page, limit and mysql_num_rows() then calculates out the correct mySQL limit statement to add to the existing SQL statement, for example we have : page=2, limit=10, mysql_num_rows=50, after computed the $sql is like this : $sql = select * from mydatabase limit 20,10; Then I query the mySQL database again to get the final result set, which I return together with the buildt prev/next htmlkode 5. I for($i=0... loop thought the result set... for($i=0;$imysql_num_rows($result);$i++){ $unit=mysql_fetch_object($result); // blablabla } 6. If there were any output from the navigation routine, I enter this at the bottom. That would be my process of doing this. I do have some questions, and remember that im referring to working with large mySQL tables 10.000 records. a) In point 2 I query out the whole database, and with a wildcard. I would guess if I compact this abit, say like select id from..., pulling only 1 field from the result set. This would spare alot of processing power for both mySQL and PHP? b) Maby I could just do a mySQL query that would result the total amount of entries, just the accuall number - since all I need is the max number to compute the final sql. c) Point 5, I preferr using objects compared with arrays, atleast for database work. I find it much more portable, since altering the datbabase structure means I dont have to enter all my code aswell $unit-name; will always work even if I insert a new field infront of it, $unit[3]; however will fail dramatically since the array has become larger. Is it just the same what U use, Object or Array, or are there particular reasons to use them for surtain work other than what you preferr yourself? Why repair things that already work is the thing I say all day long, but I do think however its time to start optimizing my work before my machinery are all buildt upon old rusty cogs, :) -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: Applications using multiple databases
Hello! In my opinion what your conclusion is sounds correct. I would not have a system that creates a new database for each and every client. Why? If the sollution is hosted on a random ISP, most of theese does not allow the creation of new databases. However, surtain ISP have packages where you can have multiple databases, but often not more than 5 in total. This would in most circumstances result in you only having 5 customers in each installation. If you are running the system on your own server, there are no problems with this, as you controll the system and can create as many databases as you would want. On the other hand you could solve this by instead of creating unique databases for each client, prefix the tables inside the database with the clients username. This would result in alot of tables, but again would give you access to every server in the world that has mySQL database available - And it would be easy to backup since you only have just 1 database to backup. It is however, in my opinion, smart to have seperate tables and such for each end every customer. Should there be a corruption somewhere, atleast it wont effect all the clients, but only 1 client. (Aslong as its not the main software that destroys/deletes everything in a faulty SQL statement. My applications are done a little different, as I have solved this by installing a seperate installation for each customer. To protect my code I have purchased IonCube Encoder, which encrypts the code and renders it useless for reverse engineering. :) You might want to do the same. Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] using code for multiple sites
Well, on the webservers I am using this would mean that the current user has read access to this folder aswell. E.g. /home/users/james /home/users/matt /home/users/patrick /home/users/shared Im used to that *james* only have read access in .../james/* Matt has only in .../matt/* and such, which would make it impossible to include anything in the .../shared/* folder. Unless you have root privilegies and can set up special rights. This would also only work as all the files are on the same server, as PHP cant include PHP code via HTTP (atleast in my knowledge). I have another sollution, which isnt quite as good, but I program all my PHP in classess and have a standard class file, that is identical for all customers. Difference is only what classes each client are using. As I develop my classess I see to that they are always backwards compatibel, this way I only have 1 (or more, but same directory) that I have to update. This makes it easy in my opinion, just connect with FTP - Update the files and Im down. -- Kim Steinhaug --- There are 10 types of people when it comes to binary numbers: those who understand them, and those who don't. --- Peter Lovatt [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Hi I do exactly this on servers running several hundred sites. each site has a single file in the root, with any local config and a variable $inc_root set. eg ?php $config_var1 = 'xyz'; $config_var2 = 'xyz'; $inc_root = '/home/sites/shared_stuff/'; //must be an absulute not relative address ? all files are then referenced as include($inc_root.'directory/sub_directory/file_i_want.php') If you move things a lot you could link each site to a single file which sets the $inc_root, so you only change one file. HTH Peter -Original Message- From: mike [mailto:[EMAIL PROTECTED] Sent: 13 November 2003 14:42 To: [EMAIL PROTECTED] Subject: [PHP-DB] using code for multiple sites I currently manage several websites that share the same code. This code is included into many of the pages on every site. I have duplicate copies of the code set up in each virtual host directory. Obviously this wastes space on my server and wastes my time having to update them all. I was looking for suggestions on the best way to be able to access these php files through includes for each site. A couple of the options that I have already looked into were- I could put the code all into one directory for site A and when I want to include these files I would have to include the full path to the files I really don't want to have to do this because I frequently move things and I would have to change the path on each file. either put these files into .:/usr/local/lib/php or create a directory called inc in /usr/local/apache and then add the following line to php.ini include_path = .:/usr/local/apache/inc I hope I made it clear what I want to accomplish. If you could give your recommendations I would greatly appreciate it. Thanks in advance, Mike Mike Calvelage Webmaster / Sales Associate Viper Systems _.·´¯`·.¸¸-vipersystems.biz http://www.vipersystems.biz/ -¸¸.·´¯`·._ [EMAIL PROTECTED] 419-224-8344 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php