Re: [PHP-DB] Short Names
IMHO, no -- it makes the code more readable. I'd also recommend making sure that variable names match their purpose (so, for instance, if you have a variable that contains a mailing address, use $mailing_addr, or if you have a variable that contains an array of recipes, use $arr_recipes). The more you can make your code readable, the better. Always keep in mind the other people that may read your code -- this, in general, means commenting and using good sense in variable names. It'll help you later for when you haven't touched the code in a year or two and need to know what you wrote and why... Hope this helps. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Sat, 2004-09-25 at 14:23 -0700, Cole S. Ashcraft wrote: Is it considered bad / sloppy to define the short names of varibales at the beginning of your code so you don't have to type out $_REQUEST[variable] or $HTTP_REQUEST_VARS[variable]? Cole -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Please help
What are the variables $sql and $sql_ext set to? The query format is fine. It's probably in your variables. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Wed, 2004-09-08 at 12:29 -0700, Stuart Felenstein wrote: I'm using a product called dbqwiksite pro. PHP generator for PHP - MySQL The code seems to be working fine except in my search page where I receive an invalid query $result = mysql_query($sql . . $sql_ext . limit 0,1) or die(Invalid query); This is the place I where the code is taking the die path. I'm guessing something belongs between the quotation marks , just not sure. Anyone ? Thank you Stuart -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] error of check box form
In addition, please send your messages once and only once. I have two copies of the same e-mail, both sent to the list successfully with two different replies to both messages. You're more likely to get help if you post and wait for a reply to your original message. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Wed, 2004-09-08 at 05:53 -0400, [EMAIL PROTECTED] wrote: Dear friends, Any guidance to the error , please. Resubmitting, -- --- Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\HOME\doctorbush\check.php on line 11 Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\HOME\doctorbush\check.php on line 73 -- script code - ?php // example code for checkbox.txt // confirmed working: Friday, March 07, 2003 // Configuration information for connecting to database // Contains $db_name, $db_user, $db_pass, $db_host // for connection. // Enter your database host name here. $db_host = \localhost\; // Enter your database password here. $db_pass = \\; // Enter your database user name here. $db_user = \\; // Enter the name of your database here. $db_name = \\; // Connect to database $db_conn = @mysql_pconnect($db_host, $db_user, $db_pass); // Check for database unavailable if (!$db_conn) { print \ERROR - failed to create connection: \ . mysql_error(); } function make_item_control($value,$title) { $content = 'tr class=\tabletext\tdinput type=\checkbox\ name=\item[]\ value=\'.$value.'\ /'.$title.'/td'; return $content; } if($p_delete_checked) { // Process items // We substract one from the count because a for loop executes once // before incrementing. $n = count($item)-1; for($i = 0; $i = $n; $i++) { $sql = \DELETE FROM note WHERE note_id = $item[$i];\; $result = mysql_db_query($db_name,$sql); if (!$result) { print ' ERROR - Delete note query failed: ' .mysql_error(); } } } else { // list items // database query here $sql = \SELECT note_id,film_id,LEFT(text,32) AS item_name FROM note ORDER BY film_id ASC;\; $result = mysql_db_query($db_name,$sql); if (!$result || mysql_num_rows($result) 1) { print ' ERROR - Select note query failed: ' .mysql_error(); } print 'form action='. $_SERVER['PHP_SELF'] .''; print 'table'; while($row = mysql_fetch_array($result)) { print make_item_control($row[note_id],$row[item_name]); } print 'tr class=\tabletext\ td input type=\Submit\ name=p_delete_checked value=\Delete Checked\ / /tr'; print '/table'; print '/form'; } ? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] error on count()
You need to pass the functions a variable to work with because you've specified parameters. Try: $okuan = orderquantity($una); Ditto for the other function call. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Tue, 2004-09-07 at 13:09 +0200, Sancerni Veronica wrote: hello, this is problably newbie question, but I can not understand why my count() function doesn't work. I need to count how many items has a determinated customer ordered ever. 1. I tired to get the array like this: $una = $check[uname]; function orderquantity ($una) { $pss = mysql_query(SELECT OID FROM orders WHERE una = '.trim($una).') or die (mysql_error(Query error on Order search)); while($pisao=mysql_fetch_array($pss)) { return count($pisao); } } $okuan = orderquantity(); 2. and like this: $una = $check[uname]; function orderquantity ($una) { $pss = mysql_query(SELECT OID FROM orders WHERE una = '.trim($una).') or die (mysql_error(Query error on Order search)); return count($pss); } okuan = orderquantity(); None of them gave me a valid value, is it because the OID is an int value? - Crez gratuitement votre Yahoo! Mail avec 100 Mo de stockage ! Crez votre Yahoo! Mail Le nouveau Yahoo! Messenger est arriv ! Dcouvrez toutes les nouveauts pour dialoguer instantanment avec vos amis.Tlchargez GRATUITEMENT ici ! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Building A Web Site Search Engine Using PHP / mySQL
Well, this is from the why reinvent the wheel department -- have you looked at htdig://? http://www.htdig.org/ Might save you some work. Just a thought :) More constructive replies regarding actual code are forthcoming, I'm sure. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Tue, 2004-09-07 at 21:10 -0400, Ron Piggott wrote: I wanted to also ask about how you would build a web site search engine with php and mySQL. I had thought of setting up a table with a few columns --- one for the URL of the specific page (This could become a link when a match is found for that page) second with the page title --- used in displaying the search results third with the plain text from the page --- for searching purposes and then having one line of the table per web page on the site Then setting up a PHP form that would search the text from the page and make some type of matching results page for each entry that found the words the user typed in. Any other thoughts? There is no compression this way,. but maybe there doesn't need to be. I don't know how to automate populating a table, but I could use the cut / paste feature. Any other thoughts? I know how to do the above and the PHP commands to use --- I wanted to ask before I got started for any tips instead of re-starting. Ron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] php Form Validation help
See below for point-by-point. ... CODE $state = $_POST['state']; if ($state = 0) { = is an assignment operator. This will always test true, because $state is set to 0 every time this is called. You want ==, which is a comparison operator. print 'pPlease select your State/p'; } /CODE CODE $phone = $_POST['p-areacode'] . - . $_POST['p-prefix']. - . $_POST['p-suffix']; /CODE More like: $phone = $_[PST[area] . - .. You get the idea -- dashes need to be surrounded by quotes. The next question id for both phone number and area code. If I want to validate the zip code and ensure a minimum of X characters in the field, numbers only how would I do this? You can check the string length and see if it's within the bounds you want. Look at the Strings section of the PHP manual for the proper function (str_len, I think). Would this be somewhat on the right track? CODE If ($zip str 5) { print 'pPlease enter your Zip Code (EX. 77662)/p'; } /CODE Nope. If someone entered 98115, then this would be 5, since there's a difference of 98110 integers :) And for the phone number I would assume I could use: CODE If ($_POST['p-areacode'] str 3 ) { print 'pPlease enter your Area Code (EX. 77662)/p'; } /CODE See comment on string length above. I am still new with PHP, any help would be appreciated. Below is the code I have sofar: Hope this helps. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re Displaying Text From A Data File
If it were a database, this would make sense. He's asking about a text- based file. This isn't really a database issue -- there's a lot of what are called fortune scripts out there that do exactly what you want. Do a search on Google. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Sat, 2004-09-04 at 19:59 +0100, Neil Smith [MVP, Digital media] wrote: It's actually very simple : Just use SELECT * FROM tbl_name ORDER BY RAND() LIMIT 1 Cheers - Neil At 17:35 04/09/2004 +, you wrote: Message-ID: [EMAIL PROTECTED] From: Ron Piggott [EMAIL PROTECTED] To: PHP DB [EMAIL PROTECTED] Date: Sat, 4 Sep 2004 14:00:56 -0400 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 7bit Subject: Displaying Text From A Data File I am still new to PHP and I wanted to ask a question. I am wanting to create a PHP script to randomly display one of many greeting messages on my web site. I was going to store them in a text based file. I wanted PHP to randomly select one of them and display it each time the script was loaded. I am still new at PHP and I am not sure where to get started. But I was thinking about this and I am sure this has already been done many times ... I am not sure where to look on the web. Can any of you help me get started? Ron CaptionKit http://www.captionkit.com : Production tools for accessible subtitled internet media, transcripts and searchable video. Supports Real Player, Quicktime and Windows Media Player. VideoChat with friends online, get Freshly Toasted every day at http://www.fresh-toast.net : NetMeeting solutions for a connected world. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Clicking on the Picture
Yes. It's called image mapping. Do a Google search. This isn't PHP related. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Tue, 2004-08-31 at 15:07 +1200, Feroz wrote: Hi, I have a Diagram that I need to upload to web page. The diagram contains 3 pictures but as one diagram. Now is it possible to code the pictures in the diagram so its clickable, that is when picture one is clicked then it opens a new page. Regards, Feroz - IT Developer / Systems Maxumise (Fiji) Limited Level 4, FNPF Place Suva, Fiji Islands. Tel : (679) 330 3137 Mobile : (679) 995 4250 ~~ This communication contains information which is confidential and may also be privileged. It is for the exclusive use of the intended recipient(s). If you are not the intended recipient(s), please note that any distribution, copying or use of this communication or the information in it is strictly prohibited. If you have received this communication in error, please notify the sender immediately and then destroy any copies of it. ~ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Text area
I suspect your return result looks something like input type=textarea rows= rather than the full string, as you were expecting. You do need to escape quotes, as they are special characters. Try: function write_textarea() { return input type=textarea rows=\5\ cols=\70\ name=\\; } I'm aware of the other replies to this message, but I'm being literal and assuming you want that exact string returned, regardless of other alternatives. HTH. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Tue, 2004-08-24 at 16:43 +0800, Hafidz Abdullah wrote: Hi again, everyone. I also have a problem creating my text area. I meant to do a text area (measuring 5 rows by 70 columns) which accompanies the words: First 50 words are free. Subsequent 50 words or part thereof, $50 will be charged: function write_textarea() { return input type=textarea rows=5 cols=70 name=; } Doesn't work. How can I make it work? Thanks regards, Hafidz -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Fwd: [PHP-DB] Q
Try using 0 and 1 in place of 'id' and 'email', depending on the order in which these are presented in the database. If the database presents id first, then id is 0. If email is first, email is 0. You should really read the PHP manuals on mysql_fetch_array() before assuming a particular behavior from that function. By default, mysql_fetch_array gives you an array with *numerical* indices, not indices with field names. If you're having trouble outputting an array, you can (and should) always do a print_r($array) to see what the index and actual values are. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Sun, 2004-08-22 at 11:10 -0400, [EMAIL PROTECTED] wrote: Dear friends, Php query modification, guidance, please.not mysql alteration table.So that Query displays data in tabular form with Onclick link to web site in another column of table. Guidance, please. Email message/mailbox attachment On Sun, 2004-08-22 at 11:10 -0400, [EMAIL PROTECTED] wrote: [EMAIL PROTECTED] wrote: Dear Friends, Data in the table is displayed by php query. .Say column A, in which name of company will be stored. Now i want to add another column B to table in which web addresse will be stored against each name in Column B.and same should be displayed in an html table, when seen in browser with link to each web address in table. The php query I am using now, is posted below. What additional code should I add so that data in column A in table1 is displayed in tabular form, with a link on click, to web address in column B. Guidance to further Query, please. Present Query ?php // open the connection $conn = mysql_connect(localhost, , ); // pick the database to use mysql_select_db(b,$conn); // create the SQL statement $sql = SELECT * FROM subscribers ORDER BY email; // execute the SQL statement $result = mysql_query($sql, $conn) or die(mysql_error()); //go through each row in the result set and display data while ($newArray = mysql_fetch_array($result)) { // give a name to the fields $id = $newArray['id']; $email = $newArray['email']; //echo the results onscreen between can also //type$id is and email is echo $email br; } ?center -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Global Peace output
What errors are you getting? We can't help if we don't know what's wrong in the first place. Turn your PHP error reporting on (assuming it's a PHP error). -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Sun, 2004-08-22 at 18:01 -0400, [EMAIL PROTECTED] wrote: Dear friends, The html solution suggested by our friend, doesn't work.Try to understand question, please. The script should print company name its web address with onclick link to the web address. onclick link to the web address, html solution suggested by our friend doesn't work. Any guidance, please. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Help! WINXP/Apache2.0/PHP4.3.8 - Can't run PHP
This isn't really a database question, so I'm not sure why it went to a database-related list. Have you checked your Apache configuration to make sure it's set to handle the PHP extensions? Check the PHP manual on how to set this (I believe relevant instructions are under Installation). -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Fri, 2004-08-20 at 11:50 -0400, [EMAIL PROTECTED] wrote: When I have a html page with an embedded php method behind a button, when I click the button I can't run the PHP, instead my browser pops up a dialog box with a request a file download of my PHP script. Also, when I run a php in my browser either nothing happens or I get the file load. -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL denying access to...everything
This is a MySQL error on the server side - you need to make sure that whatever user you're signing into MySQL with has access to modify the database/table you're using. I believe the GRANT keyword in MySQL is what you need -- look at the MySQL reference manual: http://dev.mysql.com/doc/ Good luck! -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Tue, 2004-08-17 at 23:03 -0400, [EMAIL PROTECTED] wrote: I finally got my PHP5 installation to support MySQL and now this. When I try to edit anything on mysqlgui.exe, it just gives me this error: error in database function: access denied for user @localhost... I don't know if this has to do with my php installation or what. If not, flame me for all I care. I'm too sick of all this mess to care. ...somebody help... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL denying access to everything...Part 2
This isn't the appropriate list to direct this question to. I suggest one of the MySQL help lists or a careful reading of the documentation, which tells you exactly what you need to know. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Wed, 2004-08-18 at 14:43 -0400, [EMAIL PROTECTED] wrote: Ok, thanks to many people's help, I have managed to install MySQL right and login as root with no password. However, MySQL will not allow to log in to my databases as root. Is this normal, because when I try it brings back the old access denies: [EMAIL PROTECTED] thing. So I thought maybe I just have to figure out how to create accounts, and then configure them to be all access. I have read the manual on creating accounts, but for some reason it doesn't work. Here is how it goes: I access mysql.exe and put in this: mysql GRANT ALL PRIVILEGES ON *.* TO 'user'@'localhost' Then I hit enter. It starts me off with an indented down arrow and I finish the GRANT command. - IDENTIFIED BY 'password' WITH GRANT OPTION; Then I hit enter. IT gives me another down arrow. I hit enter again and again and again and all it does is give me more indented down arrows... What now? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] No Cookies file created on Client
Sounds like it could be permissions -- more code would help, but general comments: 1) make sure you have access to the database 2) make sure the server you're using has write access to wherever that file is being written 3) you might consider putting setcookies close to the top of the file, as it needs to be sent with headers and putting it too far down (in my experience) can cause problems with setting the cookies. 4) is the browser configured to accept cookies from that site? You can block some sites and not others. 5) this isn't really a database question :) -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Wed, 2004-08-18 at 15:20 -0400, Larry Sandwick wrote: After connecting to a database I execute the following code. I never get a file created on the computer that is logging in. At the top of the code I do have ob_start(); and ob_end_flush(); If I go to other web sites I get there cookies file. code setcookie(logged_in, 1, time()+300, /); setcookie(username, $username, time()+300, /); setcookie(password, $password, time()+300, /); setcookie(line, $line, time()+300, /); setcookie(type, $type, time()+300, /); setcookie(account, $account, time()+300, /); setcookie(dealer, $dealer, time()+300, /); /code Any comments or suggestions would be appreciated ! Larry Sandwick Sarreid, Ltd. Network/System Administrator phone: (252) 291-1414 x223 fax : (252) 237-1592 _ My Inbox is protected by SPAMfighter 4020 spam mails have been blocked so far. Download free SPAMfighter http://www.spamfighter.com/ today! -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Tricky MySQL / php Script
I assume you mean the 1052367746 portion of that URL? Am I right? If so: $id = basename($photoid, .jpg); That would work, I think, if you just wanted the numeric portion of the path. Not sure if this is what you want. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Wed, 2004-08-18 at 19:55 -0400, Vern wrote: I have a bunch of thumbnails that are pulled from a recordset based on a user profile. Each thumbnail opens the picture into another page so that the picture is larger and I want to now have that user's pictures accessible by clicking a previous and/or next arrow. The first recordset of thumbnails is retrieved by a URL link ($HTTP_GET_VARS['id']) which is the user's ID number. Click on one of the thumbnails a new page is open that display the larger photo, but only that photo. I can of course pass along the user's ID as well mypage.php?photoID=uploads/1052367746.jpguserID=215 which of course will allow me to create a new recordset based on the user's id SELECT * FROM penpals_photos WHERE penpals_photos.filename = $photoID but how do I point the database first record at the photoID so that I can use the next and previous options to see the next/previous picture? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Tricky MySQL / php Script
Ach, and the light bulb goes on. Sorry, wasn't really thinking about it completely earlier. Here's a less dimbrained suggestion: could you encode the user ID as part of the filename itself? Like, for instance, write the script so that it would read something like: blah.jpg.215 and strip off the .215, converting it into a user ID and stripping it from the file name before displaying the file? Hopefully, that's much closer to an actual coherent suggestion :) - P On Wed, 2004-08-18 at 21:23 -0400, Vern wrote: That's not what I mean at all. I actually have no idea where you got that from. :) Basically what I'm trying to say is this. The following is my url: mypage.php?photoID=uploads/1052367746.jpguserID=215 photoID = uploads/1052367746.jpg userID = 215 I want to point to a record in a recordset. That records id is uploads/1052367746.jpg However, I want to return all records for the userID 215. How do I point my recordset at that file in the recordset so that the user can go to the next and previous records in that recordset based on the user's id? -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] I'm not getting any mailing list messages
nothing's been sent to it? This is not a heavy traffic list. I get maybe 4-5 messages a day from this one. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Thu, 2004-08-12 at 12:02 -0700, Chip Wiegand wrote: I just subscribed to the list yesterday and have yet to receive any messages from the list. Any ideas? -- Chip Wiegand Computer Services Simrad, Inc 425-778-8821 425-771-7211 (FAX) -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Exporting Data From MySQL Using PHP
It has been my experience that you sometimes need to do backquotes (`) in MySQL queries when cutting/pasting into PHP -- it's the same key as the tilde (~) on my keyboard. Try: $result = mysql_query(SELECT e_mail FROM subscriptionsdatabase WHERE `discipleship_mailing_list_e_mail_subscription` LIKE 'on'); That should work. I've always used the equal sign instead of LIKE, but that seems to be a matter of preference. Regarding the second part, with the fopen() and fwrite() commands, that's certainly doable. For example, you could do something like: $handle = fopen(/home/blah/blah.txt, w); $result = mysql_query(...); if($result) { while($somevar = do mysql fetch from $result) { fwrite($handle, $somevar); } ... } fclose($result); Now, I realize that code is sort of a hack, but since I'm doing it mostly on the fly, you'll forgive me my coding errors. Take a look at the Filesystem section of the PHP manual for information on the fopen/fwrite() commands, and the MySQL section for more information on MySQL commands in PHP. Hope this helps a little more in solving the puzzle. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Mon, 2004-08-09 at 22:44 -0400, Ron Piggott wrote: It is a problem having write access to the file. This is what the online mySQL manual says ... The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. The file cannot already exist, which among other things prevents files such as `/etc/passwd' and database tables from being destroyed. The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table on the server machine. If you want to create the resulting file on some client host other than the server host, you can't use SELECT ... INTO OUTFILE. In that case, you should instead use some command like mysql -e SELECT ... file_name on the client host to generate the file. I need to go with another option. Another person wrote me and suggested using the fopen(), fwrite() and fclose() commands. I haven't investigated this option yet. You know when you first learn to walk you do so by example ... I am still needing to know which commands to look up and try to apply to my situation. I have got some PHP code to work ... I am far from done the project I am working on. I was able to get the command: SELECT e_mail FROM subscriptionsdatabase WHERE discipleship_mailing_list_e_mail_subscription LIKE 'on' to work in the mySQL command prompt but when I put it into a .PHP file I get a parse error. I get that parse error by simply coping and pasting the command into the PHP file. In more detail what I am trying to do and why I e-mailed out the question is to wipe clean a mailing list data file and re-create the e-mail subscriptions data file based on which people joined the list during the week. I am still learning mySQL ... The things you wrote helped me play ... I didn't get too far in creating code, but I am learning at the same time. Thanks for the advice. Ron - Original Message - From: Guus der Kinderen [EMAIL PROTECTED] Newsgroups: php.db To: Ron Piggott [EMAIL PROTECTED] Sent: Monday, August 09, 2004 7:22 PM Subject: Re: Exporting Data From MySQL Using PHP Hello Ron, If I understand correctly, you're asking what query to execute (and how to put the result in a textfile) to get the results you want? The first part is described thorougly in the mysql-manual (chapter 14.1.7 for example, search for the SELECT syntax or examples. You'll find it at http://dev.mysql.com/doc/mysql/en/ ). You probably need a query that looks like this: SELECT e_mail FROM your_table_name WHERE discipleship_mailing_list_e_mail_subscription = on; This will return all the requested e-mail adresses. Having this information printed to a file could be reached by using the INTO OUTFILE form of SELECT. Again, check the mysql-manual. for the exact syntax, but you'll probably end up with somthing like: SELECT e_mail INTO OUTFILE '/some/filename.text' FROM your_table_name WHERE discipleship_mailing_list_e_mail_subscription = on; There are a bunch of other options and solutions, though this seems the easiest one to me. Mind that if you try to do this in PHP (and trough a webserver), the webserver should have write-access to the file you specify with 'OUTFILE' - that might be a problem. Personally, I'd run this as some sort of batch script (using the mysql command line interface with the -e option, for example). Hope this helps you along a bit. Regards, Guus der Kinderen Ron Piggott wrote: I have created a MySQL database. The table I am creating is a subscriptions database. I want to be able to export all e-mail addresses stored
Re: [PHP-DB] Re: Exporting Data From MySQL Using PHP
Whoops -- the fclose() statement refers to $result when it should refer to $handle. My bad for not at least spot checking the message before hitting send! -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Mon, 2004-08-09 at 20:34 -0700, Peter Ellis wrote: It has been my experience that you sometimes need to do backquotes (`) in MySQL queries when cutting/pasting into PHP -- it's the same key as the tilde (~) on my keyboard. Try: $result = mysql_query(SELECT e_mail FROM subscriptionsdatabase WHERE `discipleship_mailing_list_e_mail_subscription` LIKE 'on'); That should work. I've always used the equal sign instead of LIKE, but that seems to be a matter of preference. Regarding the second part, with the fopen() and fwrite() commands, that's certainly doable. For example, you could do something like: $handle = fopen(/home/blah/blah.txt, w); $result = mysql_query(...); if($result) { while($somevar = do mysql fetch from $result) { fwrite($handle, $somevar); } ... } fclose($result); Now, I realize that code is sort of a hack, but since I'm doing it mostly on the fly, you'll forgive me my coding errors. Take a look at the Filesystem section of the PHP manual for information on the fopen/fwrite() commands, and the MySQL section for more information on MySQL commands in PHP. Hope this helps a little more in solving the puzzle. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Mon, 2004-08-09 at 22:44 -0400, Ron Piggott wrote: It is a problem having write access to the file. This is what the online mySQL manual says ... The SELECT ... INTO OUTFILE 'file_name' form of SELECT writes the selected rows to a file. The file is created on the server host, so you must have the FILE privilege to use this syntax. The file cannot already exist, which among other things prevents files such as `/etc/passwd' and database tables from being destroyed. The SELECT ... INTO OUTFILE statement is intended primarily to let you very quickly dump a table on the server machine. If you want to create the resulting file on some client host other than the server host, you can't use SELECT ... INTO OUTFILE. In that case, you should instead use some command like mysql -e SELECT ... file_name on the client host to generate the file. I need to go with another option. Another person wrote me and suggested using the fopen(), fwrite() and fclose() commands. I haven't investigated this option yet. You know when you first learn to walk you do so by example ... I am still needing to know which commands to look up and try to apply to my situation. I have got some PHP code to work ... I am far from done the project I am working on. I was able to get the command: SELECT e_mail FROM subscriptionsdatabase WHERE discipleship_mailing_list_e_mail_subscription LIKE 'on' to work in the mySQL command prompt but when I put it into a .PHP file I get a parse error. I get that parse error by simply coping and pasting the command into the PHP file. In more detail what I am trying to do and why I e-mailed out the question is to wipe clean a mailing list data file and re-create the e-mail subscriptions data file based on which people joined the list during the week. I am still learning mySQL ... The things you wrote helped me play ... I didn't get too far in creating code, but I am learning at the same time. Thanks for the advice. Ron -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Exporting Data From MySQL Using PHP
It seems to me that, at least in terms of consistency, using backticks isn't a bad idea. After all, if you look at any current version of phpMyAdmin that generates PHP selection code, it uses backticks constantly. I take your point, but it seems to me like it's a good habit no matter what. Perhaps that's more a matter of semantics than PHP programming itself :) As for the difference between = and LIKE, you are correct -- I just don't typically use LIKE for any of my database work, so I forget there's a difference every once in a while :) Thank you for the reminder. -- Peter Ellis - [EMAIL PROTECTED] Web Design and Development Consultant naturalaxis | http://www.naturalaxis.com/ On Tue, 2004-08-10 at 12:33 +0800, Jason Wong wrote: On Tuesday 10 August 2004 11:34, Peter Ellis wrote: It has been my experience that you sometimes need to do backquotes (`) in MySQL queries when cutting/pasting into PHP -- it's the same key as the tilde (~) on my keyboard. Try: $result = mysql_query(SELECT e_mail FROM subscriptionsdatabase WHERE `discipleship_mailing_list_e_mail_subscription` LIKE 'on'); The backticks (`) are only needed if: (a) your column names uses (MySQL) reserved words (eg names of the builtin functions etc) (b) you have spaces in your column names Both (a) and (b) are rather bad and shouldn't really be used. Just use 'friendly' column names and backticks will not be necessary. That should work. I've always used the equal sign instead of LIKE, but that seems to be a matter of preference. It is not a matter of preference, = and LIKE have different purposes. Refer to manual and/or some SQL tutorial for details. -- Jason Wong - Gremlins Associates - www.gremlins.biz Open Source Software Systems Integrators * Web Design Hosting * Internet Intranet Applications Development * -- Search the list archives before you post http://marc.theaimsgroup.com/?l=php-db -- /* Why won't you let me kiss you goodnight? Is it something I said? -- Tom Ryan */ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php