Re: [PHP-DB] problem with mysql_query
On Monday 10 Jun 2002 12:14 pm, Rene Schoenmakers wrote: Hi, I've a problem with the following script. Sometimes it does write the data into the database, sometimes it doesn't. When it doesn't $result is completely blank, otherwise it is 1. $sql always returns the propper values even though $result is blank. Can anybody tell me what I'm doing wrong? $result = mysql_query($sql); Try changing this to (for example) if(!$result = mysql_query($sql)) { echo MySQL error . mysql_errno() . - . mysql_error(); die(); } and see what you get. There's probably some problem with the database connection. Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] problem with mysql_query
On Monday 10 Jun 2002 2:15 pm, Rene Schoenmakers wrote: Hi, I know what's causing the problem. In $newsText sometimes single quotes are entered. There the error occurs. How can I escape these singel quotes? with $newsText = addslashes($newsText); http://www.php.net/manual/en/function.addslashes.php Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] problem with mysql_query
On Monday 10 Jun 2002 2:37 pm, Markus Lervik wrote: On Monday 10 Jun 2002 2:15 pm, Rene Schoenmakers wrote: Hi, I know what's causing the problem. In $newsText sometimes single quotes are entered. There the error occurs. How can I escape these singel quotes? with $newsText = addslashes($newsText); http://www.php.net/manual/en/function.addslashes.php Oh yea, forgot to mention, when pulling the field back from the database, use the stripslashes -function in the same manner. Cheers, Markus -- Markus Lervik Linux-administrator Vaasa City Library - Regional Library, Finland [EMAIL PROTECTED] +358-6-325 3589/+358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] PHP date calculations and db (slightly OT)
Hello list, I have a database where people can reserve our computer class. The columns are time_from, time_to, name_id, res_date, confirmed. I have a table (HTML, not db *g*) that's supposed to print out a=20 month, starting from day 1 to num_days_in_month, and print the numbers in the right spot as so: May, 2002 +-+-+-+-+-+-+-+ | Mon | Tue | Wed | Thu | Fri | Sat | Sun | +-+-+-+-+-+-+-+ | 29 | 30 | 1 | 2 | 3 =A6 4 | 5 | +-+-+-+-+-+-+-+ |...etc...| +-+-+-+-+-+-+-+ where 29 and 30 will be grayed out, and if there's a reservation on, say, Friday, it'll show friday the 3rd bold (and as a link). I've got a function that returns a $dates array where I've saved the name of the first day of the month, number of days in month, name of the month and number of the month. Now I'm confused as to how I would=20 parse the information when printing out the (HTML-)table. What I've got so far is for($w=3D1;$w=3D5;$w++) { // max. 5 weeks in a month echo(tr); // table row for($d=3D1;$d=3D7;$d++) { // days in week for($res=3D0;$res=3D$num_rows;$res++) { // counter for array from db now the problem is, that if I work further on this, I end up with about four-five for-loops, which doesn't seem to be such a good idea. The other problem is that I really don't have a clue as to where I'd smack in a counter for the number of days in the month. However much I ponder this I can't reach a sensible conclusion. It seems that putting the loop just about anywhere would be a performance loss ;) Anyone ever done anything like this? Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Email Validation
On Fri, 2002-03-08 at 04:10, CrossWalkCentral wrote: How would I go about doing the DNS look up part? with checkdnsrr() I'd assume: checkdnsrr($host) Searches DNS for records of type type corresponding to host. Returns TRUE if any records are found; returns FALSE if no records were found or if an error occurred. the default type is MX. http://www.php.net/manual/en/function.checkdnsrr.php On Tuesday 12 February 2002 06:19, CrossWalkCentral wrote: I am working on a form that I have in php and am looking for some advise on form validation or specifically email address validation so i can insure that some one has put in a properly formatted email address Well. something like if (!eregi(^[A-Za-z0-9\_-]+@[A-Za-z0-9\_-]+.[A-Za-z0-9\_-]+.*, $email)) { echo $email doesn't seem to be a valid e-mail address!; } would do the job. Of course, that doesn't stop people from entering a false email address. You could do a DNS-lookup to see if the domain-part of the address really exists, too. -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Tutorial?
On Sun, 2002-03-03 at 08:18, Jennifer Downey wrote: Can anyone point me to a good tutorial on how to disable a submit button once clicked? preferably in php. If I understood the question; wouldn't this produce the desired result? INPUT TYPE=submit NAME=submit ?php if (isset($disabled)) { echo DISABLED; }? VALUE=whatever If $disabled is set, the button is rendered grayed out, but still visible. -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Parse error (a bit OT)
Hello, Can anyone tell me what's wrong with line 68? I get a parse error on line 68 trying to run this. The strange thing is that it doesn't complain about line 54. Either I'm blind, stupid, or there's somehing very wrong here. I've checked above line 67 too, but there doesn't seem to be any missing brackets or semicolons... Cheers, Markus 53: if ($prev_week) { 54:while(date(W,mktime(0,0,0,$m,$d,$Y))==$week) { ...blababla... } 67: if ($next_week) { 68:while(date(W,mktime(0,0,0,$m,$d,$Y))==$week) { ...blablabla... } -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Re: Parse error (a bit OT)
On Thu, 2002-02-21 at 14:36, Lerp wrote: Hi there :) I think you just might be missing two curly braces. Like below. if ($next_week) { while(date(W,mktime(0,0,0,$m,$d,$Y))==$week) { ...blablabla... } } Well, I intentionally left a few lines and curly brackets and stuff off the mail, so that wasn't the problem. I've solved it though (sort of). Turns out I was blind, after all. See, I use a Finnish layout on my keyboard. I get curly brackets by pressing AltGr+7/AltGr+0. I seem to have accidentally held down AltGR and pressed space after a curly bracket, which results in some sort of empty character, but a character nevertheless. ;) I have the same problem in my gnome terminal too, typing, for example 'ps -aux | grep whatever'. I get, every now and then, complaints about bash not being able to find ' grep'. ;) Cheers, Markus Can anyone tell me what's wrong with line 68? I get a parse error on line 68 trying to run this. The strange thing is that it doesn't complain about line 54. Either I'm blind, stupid, or there's somehing very wrong here. I've checked above line 67 too, but there doesn't seem to be any missing brackets or semicolons... Cheers, Markus 53: if ($prev_week) { 54:while(date(W,mktime(0,0,0,$m,$d,$Y))==$week) { ...blababla... } 67: if ($next_week) { 68:while(date(W,mktime(0,0,0,$m,$d,$Y))==$week) { ...blablabla... } -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] MySQL problem
On Fri, 2002-02-22 at 09:37, Caleb Walker wrote: I keep on getting this error statement: Warning: Supplied argument is not a valid MySQL result resource in /usr/local/www/data/phone/insert2.php on line 10 2 Can someone tell me what is wrong with the code below, I just cannot figure it out... Thank you very much in advance. I am using php4. html ? session_start(); include(info.inc.php); mysql_connect($host,$user,$pass) || die(mysql_error()); mysql_select_db($db) || die(mysql_error()); $q = mysql_query(SELECT FName, LName FROM user_info WHERE (FName='$FName' LName='$LName')) || die(1); Try this out: $q = mysql_query(SELECT FName, LName FROM user_info WHERE (FName='$FName' LName='$LName'),$db) || die(1); ^^^ It might help. Or it might not :) Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] MySQL/PHP date functions
Hello, all! Can anyone tell me how to easily calculate which days are on which week? ie, week 8 : 18. Feb - 24. Feb? I retrieve information from a database on a weekly basis, and I'd like print out what range of dates are on a specific week. I know about date(W...), but I really don't want to loop through all dates possible just to find if they are on that particular week.. (my explanation might be a bit confusing, I'm dead tired :) Cheers, markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] MySQL/PHP date functions
On Wed, 2002-02-20 at 13:16, Sven Jacobs wrote: You can do it like this calculate the current day and extract 7 days of it ehm? extract 7 days of it? from what?-) I'm not quite following... then with an array the current day until the calculated day :-) ehm, call me stupid, but I didn't get it. ;) You wouldn't mind posting a snippet? might be easier for poor retarded me to understand. :) May not 100 % what you are looking for but it works What I just came up with, teasing my (few) little gray ones, is calculate backwards until date(W) gives 8, add one, and we have monday the whateverth, right?-) Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] selecting question
On Wed, 2002-02-20 at 15:03, ACEAlex wrote: Hi i have trouble with this mysql query. OK, i have 3 different tables. Tabel 1: building_info id name price and other table 2:queue id building_id table 3:buildings_built building_id Ok, now i want to make a query that gets the data from building_info where it is not pressent in the queue and the buildings_built table. I have managed to get this to work with only 2 tables. So that i can get the things that are not present in the building_queue or in the buildings_built Anyony have a nice solution for this? If I understood right, something like SELECT A.id,A.name,A.price FROM building_info AS A, queue AS B, buildings_built AS C WHERE (A.id != B.id AND B.building_id = C.building_id) should do it. I tested it on a simple db building_info(1,foo,200) building_info(2,bar,200) queue(1,1) buildings_built(1) This is what I got: mysql SELECT A.id,A.name,A.price FROM building_info AS A, queue AS B, buildings_built AS C WHERE (A.id != B.id AND B.building_id = C.building_id)\G *** 1. row *** id: 2 name: bar price: 200 1 row in set (0.00 sec) mysql Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] PHP + SQL Books
On Tuesday 05 February 2002 02:45, William Fong wrote: I'm looking for some recommendations on PHP + SQL 'cook books'. I've had some for other apps, like PERL, and have found them very useful for learning techniques. I already have a number of PHP and SQL books, but they usually don't help each other. Any recommendations would be great. MySQL/PHP Database Applications Jay Greenspan, Brad Bulger MT Books ISBN 0-7645-3537-4 -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Email Validation
On Tuesday 12 February 2002 06:19, CrossWalkCentral wrote: I am working on a form that I have in php and am looking for some advise on form validation or specifically email address validation so i can insure that some one has put in a properly formatted email address Well. something like if (!eregi(^[A-Za-z0-9\_-]+@[A-Za-z0-9\_-]+.[A-Za-z0-9\_-]+.*, $email)) { echo $email doesn't seem to be a valid e-mail address!; } would do the job. Of course, that doesn't stop people from entering a false email address. You could do a DNS-lookup to see if the domain-part of the address really exists, too. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] session_registered variable problem
On Monday 28 January 2002 18:42, Jason Wong wrote: $page behaves just fine : page: 2 - yup, it's incrementing, all right... nr_pages: 230 Whack! Doesn't work any more... It's starting to drive me mad. Me too. Post the full code so we can all revel in this madness! All rightey. Here it goes in it's (almost) full glory! // The nav-function that's responsible for updateing the query if($nav) { if($go==next) { if($page $nr_pages $page = 0) { $page++; $milla= (($page) * 20).,;// replace with echo millä: . $milla; // echo out debug info $mita = (($page-1) * 20).,; // replace what echo mitä: .$mita; // echo out more debug info $query=ereg_replace($mita,$milla,$query); } } if($go==prev) { if($page=1 $page = $nr_pages) { $page--; $milla = (($page) * 20).,; echo millä: . $milla; $mita = (($page+1) * 20).,; echo mitä: . $mita; $query=ereg_replace($mita,$milla,$query); } } echo query from nav(): .$query; $result=mysql_query($query,$database) or die(BEATCH,WHINE AND MOAN!); // hehe. just a debug output. print_taulukko(); } function print_taulukko() { ? FORM ACTION=page.php METHOD=POST ? //debug echo query: . $query; echo BRBR; echo page: . $page; echo BR; echo nr_pages: .$nr_pages; //endof debug while($row=mysql_fetch_row($result)) { [snip away stuff that doesn't really matter] } ? TR TD COLSPAN=5 WIDTH=50% ALIGN=CENTERINPUT ?php if($page == 0) {echo DISABLED;} ? TYPE=button VALUE=Edellinen sivu onclick=parent.location='page.php?nav=truego=prev';/TD TD COLSPAN=4 WIDTH=50% ALIGN=CENTERINPUT ?php if($page = ($nr_pages-1)) { echo DISABLED; }? TYPE=button VALUE=Seuraava sivu onclick=parent.location='page.php?nav=truego=next';/TD /TR ? } And that's basically it. There's a function responsible for reading user input and constructing the sql-query, and it places the sql in $query, stuffs it down MySQL and throws it over to print_taulukko(), and it seems to be working right, since the first result always is the correct one. It also session_registers $query. (yes, I use session_register(query), not session_register($query).) I checked the sess_whatever file step by step when testing again just to see exactly what is put in it, but it seems to be a well-behaved little textfile. Make any sense out of the code? Cheers mate, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] session_registered variable problem
On Monday 28 January 2002 18:42, Jason Wong wrote: $page behaves just fine : [snip] page: 2 - yup, it's incrementing, all right... nr_pages: 230 Whack! Doesn't work any more... It's starting to drive me mad. Me too. Post the full code so we can all revel in this madness! Well, problem solved, sort of. It suddenly started working. Wicked. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] session_registered variable problem
Hello! I have a problem with session_registered variables. It seems that my sessions behave quite erratic. Well, actually just one variable, $query. Somehow when I print the value of $query, it looks fine. Then, when I change $query a bit and print it again, it looks fine. Change it a third time, and it suddenly gets the value it had in the beginning. Ideas as to how one would go about solving this little problem? Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] session_registered variable problem
On Monday 28 January 2002 14:57, Jason Wong wrote: Somehow when I print the value of $query, it looks fine. Then, when I change $query a bit and print it again, it looks fine. Change it a third time, and it suddenly gets the value it had in the beginning. Could you post some code please? Well, for instance, this screws up the $query. It works if one clicks once on the next-button, but clicking another time resets the query to SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE (L.Nimi_id=N.id AND N.Nimi LIKE asdf) LIMIT 0,20 if($go==next) { if($page $nr_pages $page = 0) { $page++; $replace_with= (($page) * 20).,; echo replace_with: . $replace_with; $replace = (($page-1) * 20).,; echo replace: .$replace; $query=ereg_replace($replace,$replace_with,$query); } } It's the LIMIT 0,20 - LIMIT 20,20 - LIMIT 40,20 that doesn't work. Strange thing is, that it worked about a week ago. : \ I can't really recall changing that part of the code at all at that point. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] session_registered variable problem
On Monday 28 January 2002 17:34, Jason Wong wrote: Crikey, it looks terribly complicated for what looks like something to page through a set of results. Wouldn't it be easier to do away with the ereg_replace()? if($go==next) { if($page $nr_pages $page = 0) { $page++; $start = $page * 20; } } $qry = SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huom autuksia FROM uusi_lehtitaulu L, nimet N WHERE (L.Nimi_id=N.id AND N.Nimi LIKE asdf) LIMIT $start,20 Even it this doesn't work, at least it's easier to understand :) Well, in this particular case it won't work at all, because the SQL-query is dynamically created based on what the user wants to search for. It doesn't nessecary include all columns. The only static bit of the query is FROM uusi_lehtitaulu L, nimet N and WHERE (L.Nimi_id=N.id : ) It would be just as big a mess with a truckload of concatenations, like $query = SELECT . $tables . FROM uusi_lehtitaulu L, nimet N WHERE (L.nimi_id=N.id . $search . ) LIMIT $start,20; Besides, I have a strange fetisch to do everything the hard way. : ) Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] session_registered variable problem
On Monday 28 January 2002 18:06, Jason Wong wrote: Besides, I have a strange fetisch to do everything the hard way. : ) Masochist :) :D Anyway, as per the subject, how are you getting $page? I assume it is stored in the session. Is $page behaving correctly when you go from one page to the next? Could you post the relevant code? $page behaves just fine : first time around (haven't got to the nav() -function yet..) : query from nav(): SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE L.Nimi_id=N.id LIMIT 0,20 //this is from the print_table -function query: SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE L.Nimi_id=N.id LIMIT 0,20 page: 0 - note! bells! whistles! nr_pages: 230 We hit the next-button, and we get... replace_with: 20, replace: 0, query from nav(): SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE L.Nimi_id=N.id LIMIT 20,20 query: SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE L.Nimi_id=N.id LIMIT 20,20 page: 1 - bells 'n' whistles again! nr_pages: 230 Looks quite good. We hit the next-button again : with: 40, what: 20, query from nav(): SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE L.Nimi_id=N.id LIMIT 0,20 query: SELECT L.Tunnus,N.Nimi,L.ISSN,L.Vuosi,L.Lisätietoja,L.Vuosikerta,L.Numerot,L.Huomautuksia FROM uusi_lehtitaulu L, nimet N WHERE L.Nimi_id=N.id LIMIT 0,20 page: 2 - yup, it's incrementing, all right... nr_pages: 230 Whack! Doesn't work any more... It's starting to drive me mad. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] Combining INSERT...SELECT and INSERT INTO
On Tuesday 15 January 2002 16:04, you wrote: On 1/14/2002 12:54 PM +0200 Markus Lervik wrote: Is there any way to combine INSERT...SELECT and INSERT INTO so one could insert a new row with a few values inserted by hand and others from another table? something like INSERT INTO mag_table (mag_id,issn,year,info,volume,numbers,remarks) VALUES ( (SELECT id FROM mag_names WHERE mag_names.name=Asdf), 1234-5678,2001,foobar,1-4,1-52,foobar); Try doing something like: INSERT INTO mag_table (mag_id,issn,year,info,volume,numbers,remarks) SELECT mag_names.id as mag_id, '1234-5678' as issn, '2001' as year, 'foobar' as info, '1-4' as volume, '1-52' as numbers, 'foobar' as remarks, FROM mag_names WHERE mag_names.name='Asdf'; I don't know if that will work as-is, but something along those lines should give you what you need. Well, here's how I ended up doing it before I red your mail: $concat_string = SELECT CONCAT_WS(\,\,\; if(isset($inputName)) { if(!$result=mysql_query(SELECT id FROM mag_names WHERE mag_names.name=$inputName)) { die(error); } if(!$row=mysql_fetch_assoc($result)) { if(!$result=mysql_query(INSERT INTO mag_nimes (name) VALUES \$inputName\)) { die(error); } elseif(!$result=mysql_query(SELECT id FROM mag_names WHERE mag_names.name=$inputName)) { die(error); } } $row=mysql_fetch_assoc($result); $concat_string .= Name=\\\ . $row[id] . ,\; } Then concatenate Name, ISSN and everything else to construct the end of my nice little UPDATE mag_table SET ... -sentence, pass it through mysql and concatenate the UPDATE sentece and the result from the previous mysql query, stick a little duct tape here, a bit of super glue there and a few five-inch nails and stuff the whole thing down mysql. : ) Well, it works. : ) Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Replacing * with %
Hello all! I can't for the love of god get neither ereg_replace nor str_replace to work. I wan't to replace * with % so I can use SELECT ... WHERE whatever LIKE string% in MySQL. I've tried ereg_replace(*,%,$search_name). Didn't work. I tried escaping the asterisk. I tried double-escaping the asterisk. I tried str_replace(*,%,$search_name), and that didn't work either. I tried just about everything I could think of, escaping, double- escaping and triple-escaping ad nauseum, but it just wont work. Oh, yes, I also tried $search_name=ereg_replace(blablabla); What a surprise. It didn't work. Yes, I've RTFM, RTMFM, read from my PHP Blackbook to phpbuilder.net and just about everything in between. Pretty soon I'll start bashing away on that Solaris 8 box over there. Markus - frustrated -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] Including a file using php //
On Tuesday 15 January 2002 12:35, you wrote: Yes it work's on local / but how about when the file comes from a remote server? ### works ?php $file = one.php; include($file); ? ### ### did not work at all ?php $file = http://192.168.129.103/noc/chikkaps.txt;; include($file); ? ### There are two possible reasons for this as I see it: a) You're on a Windows platform From the manual: Note: You can't use remote files in include() and require() statements on Windows. or b) You've compiled PHP with the option --disable-url-fopen-wrapper or set allow_url_fopen to off in php.ini If the answer to option a is yes, then sorry, Harry, it wont work. -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Combining INSERT...SELECT and INSERT INTO
Hello! It's me again, with the magazine database : ) Is there any way to combine INSERT...SELECT and INSERT INTO so one could insert a new row with a few values inserted by hand and others from another table? something like INSERT INTO mag_table (mag_id,issn,year,info,volume,numbers,remarks) VALUES ( (SELECT id FROM mag_names WHERE mag_names.name=Asdf), 1234-5678,2001,foobar,1-4,1-52,foobar); I'm trying to construct myself a nice clever INSERT statement to my web-frontend. Haven't got it to work, though. Is this even possible? The other option would be to use three(?) mysql_query calls from my PHP-code, but I'd like to keep it as simple as possible. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] Updating table with data from another table in the same database
On Wednesday 09 January 2002 19:49, you wrote: =A daunting task indeed, however it's a move for the better, so more power to your right arm/kung-fu grip... However let's not jump to quickly to PHP, and keep it all within MySQL if we can... I was hoping we could ;-) =So you started with one table: mag_table which contains the columns id, name, issn, year, info, volume, numbers and remarks. Right. That was the one I got dumped out of Access97 and then modified it a bit with ALTER TABLE. I probably should have included the output from DESCRIBE mag_table and DESCRIBE names, but I forgot.. : ) =Then you created a table called names (which was too nebulous for me, so I created table MagNames with columns MagId (auto_increment) and MagName). At which point we arrive at your question. =UPDATE only works on a single table - but you are right on the other criteria: that the row already exists. So a good first try, but sorry that one ain't going to get off the ground, Wilbur! That's stupid and quite illogic. One would think that UPDATE would update a column if one tells it to update a column and if one tells it to, it should use data from another table. Why can't it work the way -I- want it to?-) =I always think that it would be logical to use a REPLACE here, but no REPLACE doesn't like a table REPLACING data within itself, unless the whole row is replaced - and even then it cannot refer to (copy values from) itself. So again, close but no coconut! Yes, I figured that one out while reading the manual. Bummer. That's also a bit stupid. Doesn't quite make any sense. =So we are pushed into the waiting arms of the INSERT command. Which requires an existing table and will cheerfully add new records. INSERT-ing data from another table/tables requires the INSERT...SELECT option (see manual 6.4.3 INSERT Syntax) Yes, I know, I used it to populate the names (or, if you prefer, mag_names) table. INSERT INTO names (name) SELECT DISTINCT blablabla. =Accordingly I recommend CREATE-ing a new table, eg the prosaically named new_mag_table with the columns Id, MagId, ISSN, Year, Info, Volume, Numbers, Remarks - in other words, exactly the same as mag_table but with MagId instead of the (mag)name. Then work out how to join the two 'source' tables to create each record in turn (write the SELECT clause). Then construct the INSERT clause, slap the SELECT on its end, and the retrieved data will be inserted into the new_mag_table, eg: [snip] Yes, I remember that I had an idea like that a while back, but then I forgot it :-) One tends to forget things after working for 11-12 hours/day three days in a row... : ) I did just that now, and it works like a charm! [/snip] =Ok? Very much so! Thanks a million! Now we're (or rather, I'm) a bit wiser again, and I increased the grasp of my kung-foo grip just a bit more!-) Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] PHP/MySQL Library Catalog System
On Thursday 10 January 2002 22:26, you wrote: Hi all, I've noted that a least a couple of people on this list work with library catalog systems - I'm interested in finding out whether any of these systems are open-source or are available for a nominal fee. I'm familiar enough with PHP/MySQL to make one, but I'd also like to avoid re-inventing the wheel if possible, particularly since I'm not a librarian :-). The non-profit that I work for has a significant biological science library that we would like to create a/use an existing web-based catalog system for. Also, I'm aware that there is specific funding available for doing this @ non-profits... I was wondering if anyone else had endeavored along these lines. Well, as soon as I get my database over magazines that we have in our storage, i'll release it under GPL, most probably on the http://lib.vaasa.fi server. Not that I know if anyone has got any use of it whatsoever, but... Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Updating table with data from another table in the same database
Hello, all! I have the daunting task of porting an Access database to MySQL. It's unbeliveably poorly designed, and columns id, name, issn, year, info, volume, numbers and remarks. I made another table, names, that's got columns id and name. I used INSERT INTO names (name) SELECT DISTINCT mag_table.name FROM mag_table to get, as one would expect, the distinct magazine names into the names- table. Now, what I'd want to do, is to replace the names in mag_table with the id-numbers from the names table, but I can't figure out how to do it. I tried UPDATE mag_table SET name=names.id WHERE name=names.name but MySQL tells me the following : ERROR 1109: Unknown table 'names' in where clause I haven't go perror to work at all, it just says Unknown error. Has anyone ever done anything like this, and, if so, how? I was thinking about a PHP-script, but if someone has got a query that would take care of this I wouldn't have to get into that. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] Formated Results
On Monday 07 January 2002 14:32, you wrote: Yes thank you that was the answer. While I'm asking questions , I've got one good one : Whats the best book to buy on php mysql ? I can recommend PHP Blackbook by Peter Moulding (Coriolis, ISBN 1-58880-053-9), 845 pages. It concentrates mostly on PHP, but there is a pretty good chapter on MySQL and PostgreSQL, very informative chapters on Sessions and Arrays and just about anything you'd ever want to know about PHP : ) That's the one book I use most at work. Then there's also MySQL by Michael Kofler (Apress, ISBN 1893115577), 659 pages, which seems to be quite a good book, and we can't forget the classical MySQL by Paul DuBois and Laurie Petrycki (New Riders, ISBN 0735709211) 850 pages. Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] Sending variables between PHP pages
On Friday 04 January 2002 14:26, Bjarte Husebø wrote: Another way of doing this, is including a file at the beginning of each script: Example: ?php # Include the file containing general variables/constants/funstions require (general.inc); # Open a connection to MySQL using variables from general.inc $link = mysql_connect ($host, $username, $password); ? Yes, but then we come across the other problem, namely, if you click a submit button that has a ACTION=?php echo $PHP_SELF?, technically the script ends when it reloads the page, and therefore also forgets $host, $username and $password, so I'd probably still have to somehow register the variables, ie. using session_register, no? -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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]
Fwd: Re: [PHP-DB] How to querry two db in a single statement?
Didn't notice that this didn't get cc:d to the list, so here it hoes. -- Forwarded Message -- Subject: Re: [PHP-DB] How to querry two db in a single statement? Date: Fri, 4 Jan 2002 15:58:35 +0200 From: markus|lervik [EMAIL PROTECTED] To: Andy [EMAIL PROTECTED] On Friday 04 January 2002 15:50, you wrote: Hi there, I would like to make a querry on 2 db. There is info in tables I would like to compare. As I know, there has first to be a conect on the db before the querry. But how to do this on 2 db?? As far as I know there aren't any relational databases that support querying multiple databases in one query. I guess you'd be best off querying the first database, save the result, query the second database, save the result and then compare the two results. Please do correct me if I'm wrong, people. Cheers, Markus --- -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Problem with buttons
Hello everyone! Does anyone know what the problem might be with the following little php-snippet? print(TR TD COLSPAN=\4\ ALIGN=\CENTER\INPUT TYPE=button VALUE=\Previous page\ onclink=\parent.location='index.php?nav=truego=prev';\/TD); print( TD COLSPAN=\4\ ALIGN=\CENTER\INPUT TYPE=button VALUE=\Next page\ onclick=\parent.location='index.php?nav=truego=next';\/TD/TR); The next button works perfectly, but for some strange reason nothing happens when one hits the previous button. *sigh* I don't want to be coding today.. I want to be at home listening to the BBC 13 CD Lord of the Rings dramatization. *grin* Cheers, Markus -- 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] parse error
On Thu, 2001-12-13 at 23:49, Rob Day wrote: As far as I can see, you're missing '; in line 360, unless it continues further down and terminates the $message string there. Here is the offending code: 353 if ($moderation == no){ 354 $message .= checked; 355 } 356 357$message .= ' 358nobr 359pAnswer yes if you want all postings to the list to be sent to 360 a moderator for approval before distribution to the list./p Any help would be greatly appreciated. Thanks! -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] Problem with MySQL and array loop
Hello, I've got a really strange problem. When looping through a result given by mysql_fetch_row(), the code for some reason ignores the last column in the database. The code snippet I'm using now is while($row=mysql_fetch_row($result)) { print(TR); for($i=0;$i7;$i++) { print(TD); if($row[$i]==) { print(P ALIGN=\CENTER\BN/A/B/P); } else { printf(P ALIGN=\CENTER\%s/P, $row[$i]); } print(/TD); } print(/TR); } The database has got eight columns, and I can't for the world figure out why it doesn't work. I have exactly the same problem with another PHP-app that I'm developing, too, so if someone has got a solution to my problem, I'd probably get the other app working too. What is it I'm missing, or am I just stupid? I opt for the second choice. :) Cheers, Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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] Problem with MySQL and array loop
On Thu, 2001-12-13 at 11:42, matt stewart wrote: you're only printing stuff while i=0, i=1,i=6. therefore only 7 things come out. either make the loop for($i=0;$i=7;$i++), or for($i=0;$i8;$i++). Oh! Thanks a million! It works like a charm now. So I guess the second alternative was right, after all. Isn't it funny, how one can become code-blind regarding one own's code? -Markus -- Markus Lervik Linux-administrator with a kungfoo grip Vaasa City Library - Regional Library [EMAIL PROTECTED] +358-6-325 3589 / +358-40-832 6709 -- 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]