Re: [PHP-DB] Help!!! Can anybody help me with my script?
Tony pressed the little lettered thingies in this order... I am trying to figure out how to read data base(Mysql) with rows of item number (item) and quantity, so that when item number was given, it searched for the quantity of the item number. If the quantity number is 0 or less, it will show Out of Stock, else will show In Stock on my web page. Here is part of language that I wrote and didn't work. Please help me what to do, There are two common methods. One uses PHP and the other uses MySQL. The one that is most efficient depends largely on the design and size of the table and the desired output. See below... $result = mysql_query(SELECT * FROM inventory,$link); Here are the two queries that will work. The first with PHP: $result = mysql_query(SELECT * FROM inventory WHERE item = '$itemx',$link); $num = mysql_num_rows($result); if ($num 1) { echo Out of stock; } else { echo In stock; } This would be very inneficient because it requires MySQL to do a full retrieval from the table. The only reason you would want to do it this way is if you wanted to relace the In stock above with actual results from the query. If you just wanted to say In stock it would be more efficient to use MySQL's built-in COUNT(*) function: $result = mysql_query(SELECT COUNT(*) FROM inventory WHERE item = '$itemx',$link); while ($row = mysql_fetch_row($result)) { $num = $row[0]; } if ($num 1) { echo Out of stock; } else { echo In stock; } Note that if you use mysql_num_rows() on the second query, you will always get a result of one (1) because the number of rows that MySQL returns with this query will always be one (it returns how many records matched your query as its one row return), assuming that there are no errors. In either case, you can echo $num to display the number of records returned. Good luck... 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) Business Applications: http://www.AppIdeas.com/ Open Source Applications: http://open.AppIdeas.com/ -- 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] Unexplained MySQL Error..
Mike Gifford pressed the little lettered thingies in this order... Hi Chris, I think you are onto something here.. However, this has produced another problem. Boget, Chris wrote: UPDATE WLPbib, WLPpublisher,WLPprofile,WLPbib2profile I think you can only update one table at a time... I could be wrong, though... I seperated this out into 3 update commands. However, the WHERE statement is hanging now: Database error: Invalid SQL: UPDATE WLPpublisher SET WLPpublisher.publisherID = '' WHERE WLPbib.bibID = '32' AND WLPbib.publisherID = WLPpublisher.publisherID MySQL Error: 1109 (Unknown table 'WLPbib' in where clause) Please contact the webmaster and report the exact error message. Session halted. I can understand that MySQL is getting a bit upset because I am referring to fields like WLPbib.bibID when the table hasn't been specifically referenced in the query. If you do not list a table in the UPDATE parameter, you cannot reference that table from anywhere else within your query. The same is true of SELECT statements - you cannot reference a table that is not listed in the FROM clause. The same is true of UPDATE and many other commands. There's a table selection parameter for most SQL queries (at least those that actually query), and you cannot point to tables later in your query that are not listed. In other words, you cannot tell it to update table1 where table2 = ... If you haven't told it to do an action (update in this case) on table2, it's going to wonder what the heck those tables have to do with each other and exit with an error. This is an oversimplification of what really happens, but this message is way too short to go into that in any detail. You should either pour through the documentation section at mysql.com or get the book MySQL by Paul DuBois. The docs may be difficult to get through for newbies, but they are precise and contain a lot of info. The book on the otherhand starts at the beginning and holds your hand into the more difficult aspects. The book even goes into details about how MySQL works that makes it so that you can't do what you are attempting above. 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) Business Applications: http://www.AppIdeas.com/ Open Source Applications: http://open.AppIdeas.com/ -- 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] Help!!! Can anybody help me with my script?
Tony pressed the little lettered thingies in this order... Thanks for your quick respond and your help. This is great. I have one more favor to ask you. As you know I am a beginner of PHP Mysql, do I put that language on all my product pages? It seems to be too much work. Is there way that I can save main language that you wrote in to one file as stock.php3, and point a link from product html page with known item number for itemx? And, print the result back to product html page with Out of Stock or In Stock. I will appreciate your help. Thanks again for your help. Tony Take a look at function() http://php.he.net/manual/en/functions.php and require: http://php.he.net/manual/en/function.require.php Define the code in the file you are requiring: function inStock($itemx) { ...do query here... ...echo result here... } And in your regular pages: require(file_with_functions.php); inStock($itemx); That's about it. Good luck... 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, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] How to drop a table when user leaves prematurely?
BD pressed the little lettered thingies in this order... Ugh! I'm sure this is fairly simple, but I have yet to come up with a way to do it... In a nutshell, our application creates, uses and drops a table while the user is working on the site. Unfortunately, because of other considerations, we can't use a defined temp table - it has to be created as a regular table. We have a routine in the app that will drop the table once the user is done with their work, but if they leave for some reason before they're done, the table is left hanging out there. This wasn't a problem at first, but we're building up quite a collection of useless tables right now. Is there any way to drop the table automagically when the user leaves prematurely, either by closing their browser or jumping to another site? I tried using register_shutdown_function(), but it didn't seem to have any effect... I think, and I know I may be way off base, is that there are a lot of pages involved in this application, and I'm not sure how to tell the app that the user is just going from one page to the next or is actually going bye-bye... HTTP is stateless (there is no persistent connection between the server and browser), so there is no way for you to tell the difference on the server side whether the user has gone to get coffee, has closed his or her browser or has been abducted by aliens. You can do two things that are rather unreliable: 1) Have a Log Out button. This is unreliable because many (most?) people will simply not use it. 2) Use a javascript to detect when the user has gone away. This is unreliable because many people disable javascript or use non-compliant browsers. The only sure way to keep your temp tables at a minimum is to store a creation date or datetime field in the temp table and destroy the table when it has reached a reasonable age. I prefer to run perl scripts from cron to do this and typically choose 48 hours as the time at which I feel that it is safe to assume that the user has abandoned his or her data. Good luck... 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) Business Applications: http://www.AppIdeas.com/ Open Source Applications: http://open.AppIdeas.com/ -- 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: AW: [PHP-DB] image resizing
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, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Storing Code in a db?
Mark @ 10base-t pressed the little lettered thingies in this order... Hey there, Is it possible to store code like a function, for example, in a mysql database and pull it into a php dynamicallly so you can use the function if needed? Yes, it is possible, but you need to run the code through eval() for it to do anything useful. ie while ($row = mysql_fetch_row($result)) { echo eval($row[0]); } Good luck... Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Meeting cutting edge dynamic web site needs For a good time, http://www.AppIdeas.com/ -- 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] changing field size
Adv. Systems Design pressed the little lettered thingies in this order... hello *: I have initially set a field named title to be varchar(50)...I am finding that it is not long enough...can I change the size without adversely affecting existing data? ALTER TABLE table_name CHANGE field_name field_name new_attributes. For a table called tbl and a field called fld use: ALTER TABLE tbl CHANGE fld fld VARCHAR(100) Increasing the length of the field has no adverse affect. Have fun... Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Meeting cutting edge dynamic web site needs For a good time, http://www.AppIdeas.com/ -- 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] passing db persistent connections through different pages
[EMAIL PROTECTED] pressed the little lettered thingies in this order... hello, I've this silly question: how can I pass a db persistent connection from a script to another? (it seems there's no way: but what's the use then of them?) eg, I tryed this 2 scripts (with Oracle 8.1.6) ?php set_time_limit(0); $conn = ociplogon('user','pass','testdb'); echo Server Version: . OCIServerVersion($conn); echo brbr $conn; ? ?php echo brbr $conn; OCILogOff($conn); ? this works if both are on the same page, but I see no way to pass $conn (with the associated info) to another one; I've read on http://marc.theaimsgroup.com/?l=php-dbm=97024385511984w=2 __ I'd like to know if it is possible to create a session variable for a database to get a persistent database connection. I've got lots of updates If you think passing persistent connection between pages as other vars, answer is no. __ there's really no way to do this? The persistence of the DB connection follows the child process that serves your individual web page request. The first time a child process requests a persistent DB connection, it will maintain that connection until the child process dies. The problem is that when you are on a web site, when you request a page, the page is served and you disconnect from the child process. The next request to the same site will use one of the other open child processes - not necessarily (and probably not usually) the same one. The default configuration of Apache is to keep 10 spare child processes running at all times. On busy and semi-busy servers, child processes are created and destroyed regularly. Once the child process is destroyed, the database connection is destroyed with it. The bright side is that the connections are actually persistent, which means that you will in fact benefit. The down side is that you are not going to always get the same persistent connection for each request. Doing so would probably not be possible over a stateless connection (as HTTP connections are). http://www.php.net/manual/en/features.persistent-connections.php Expalins this in pretty good detail. have fun... Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Meeting cutting edge dynamic web site needs For a good time, http://www.AppIdeas.com/ -- 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] Connecting to MySQL
Keith Whyman pressed the little lettered thingies in this order... Can anyone help with this problem ! user name should just be keith but the @localhost gets added and then I can't connect ??? Warning: MySQL Connection Failed: Access denied for user: 'keith@localhost' (Using password: YES) in /usr/var/www/www.happy.de/html/cms/test.php on line 23 Problem connecting to DataBase A copy of the code you are trying to use to connect top the DB would be helpful. Basically, @localhost gets added to your username whenever you haven't specified a host name. Did you use mysql_connect() or mysql_pconnect() before attempting to run the query? mysql_connect(host_name,user,password); $result = mysql(db_name,query); Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Meeting cutting edge dynamic web site needs For a good time, http://www.AppIdeas.com/ -- 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] MySQL connection: Change on syntaxis?
Tomás García Ferrari pressed the little lettered thingies in this order... Hello, I updated php to version 4.0.5 and MySQL to version 2.32.39, had errors on lines like this: $rows = mysql_num_rows($result); and noticed that this is a solution: $rows = @mysql_num_rows($result); Is this a new use of the function mysql_num_rows? The only thing that the @ does is to supress errors. http://www.php.net/manual/en/language.operators.errorcontrol.php What's your code and the error(s) you're getting? mysql_num_rows still has identical syntax as it did in PHP3. Christopher Ostmo a.k.a. [EMAIL PROTECTED] AppIdeas.com Meeting cutting edge dynamic web site needs For a good time, http://www.AppIdeas.com/ -- 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]