solution-digest (big :)

From: Date: Thu, 23 Nov 2000 11:14:38 +0000
Subject: solution-digest (big :)
Groups: php.db 
Request: Send a blank email to php-db+get-4687@lists.php.net to get a copy of this message
From: "Trond Erling Hundal" <webmaster@port-industry.com> Date: Mon, 20 Nov 2000 12:58:12 +0100 Subject: An SQL-query puzzle... SELECT max 2 rows from tables having id 'a' or id ' b' or id 'c'... >Hey hey hey... >I`ve stumbled across a little SQL puzzle here... maybe some of you can >help... >I am building a "main page" for many "sub main pages" >The idea is to have several pages displaying newsflashes for their specific >subject... >Example: >Main page 1 only contains news about a place called Grewin >Main page 2 only contains news about a place called Orklan >Main page 3 only contains news about a place called Lillo >Main page 4 only contains news about a place called Dogmax >The news for these sites have already been stored in a MySQL table called >article. >The relation between the article and the specific site is stored in a table >calles newsportal. If I see it clear, then... as long as you have a limited number of these places, and also this number is low like now, just write four rutins, one for each place, and do the followings in each: - select the two IDs you will need from the newsportal table, like "select uid from newsportal where place="Grewin" order by doa desc limit 2" - this supposes that column uid reflects the correspinding id num of row in article and also that you have a column "doa" which stands for "date of add". If you have an ID column in the table newsportal but no doa, then you may use it, however, if deleting articles etc, you may get in trouble. - fetch the two results of the result into an array (for e.g. $ids[]) - now do a cycle which runs from 0 to 1, selects the corresponding article from the article table, and displays the content. Do this rutin for all 4 places. If you cannot walk this way, then I think your db is not properly designed. - o - Date: Mon, 20 Nov 2000 08:58:02 -0800 (PST) From: "Adv. Systems Design" <asd_2000@yahoo.com> Subject: RE: [PHP-DB] opening webpage >Actually, I digress... the header() did not work >because: > >Warning: Cannot add header information - headers >already sent by (output started at >templates/header.php:3) in >/home/httpd/html/lesson/admin/add_lessons.php on line >41 > >Line 41 is the header() call... > >Anyone have any other ideas as to how to jump to >another page programatically from within a >switch...case setup? All I am trying to do is submit a >form (on add_lessons.php) and goto a listing on >lessons.php within the same dir) >thanks RTFM man RTFM, where have you been when we learned about headers ? :) You must not output anything on your page before sending any headers. Headers must be the first data the client receives, so, your redirect program should not send back anything else to the client but a redirect header. If you want to display a "if you do not get transported to blah then click here" then send the redirect, send the <html> etc. and then this content. - o - Date: Tue, 21 Nov 2000 09:01:31 +0100 From: Daniel Rezny <dr@photo.digitallaut.at> Subject: Attempt to special parser >Hello all, > I have a litle problem. I want to parse a xml file with. Yes I know > it is not so hard. But. In this file is only 4 tags, every tag has a > id, and I want to give values of ids to db to column called > "name_of_id". > I tried to make it with define open tags and close tags. Crashing on > close tags because this is almost the same. > Thank you in advance for help. > Daniel without understanding your problem in depth, here are two ideas to use for writing a parsing thing. - have your text in one string, with newlines eliminated - run through your text char by char, and check for a "<" character. If current character is not "<" simply do a continue; - if "<" found then read the characters into a string until ">" is found - now you have the tag in a string, and can process it. You can look if there is a / in the end, if there is, then do not bother with it. - look for a "=" sign after the "ID" string piece, and after the = parse the string for a useable variable. - o - From: "Bob Irwin" <bobirwin@pnc.com.au> Date: Tue, 21 Nov 2000 23:25:35 +1100 Subject: PostgreSQL and PHP >G'day, >This is working great, but what I would like to do is set up an login = >ini file, so that my username and password aren't as easily accessable. = >I've been experimenting with my MYSQL ini file, but lack the experience = >with PHP to get it going. Can anyone supply me with a URL to a website = >that details this proccess? Or sample code if it isn't too much = >trouble? > >Also - if anyone has URLs to sites that have decent documentation on = >getting PHP to work with PostgreSQL - I'd be most appreciative! > >Thanks in advance, >Bob if you set up default login and pass for your sql, then anyone who can put a php program on your system will be able to access to your database without even he or she would know your login/password... But, you may protect your php source - via the web server, it properly configured, php source will not be available, and you can permit other users from seeing your php codes, just set up your file permissions so that only you can read and write, and the user of the web server read the document. Read about users, groups, and file access modes (chown, chmod, etc) if you are running a *nix server. However, with this method, if others can also run cgi and/or php, they can parse your files. This is the main problem with freeweb servers also, no way to protect your data (the web server user must be able to read the php source, since the php will be run under it's id. now, as others' php scripts will run under the same user id, and this a php script will be able to open another one and dump its source as output)... - o - Date: Tue, 21 Nov 2000 08:46:00 -0700 From: bryan <bryan@concept-factory.com> Subject: $HTTP_GET_VARS >Here is what I have..... >How do I pass what I receive in $HTTP_GET_VARS to another page, called >delete.php? I am using this as a pop-up window to delete the current >record. I guess I could do it by id, too, but each "rq" is unique. >Thanks >Bryan Fitch- Use <input type=hidden name="rq" value="$rq"> for passing your variable named "rq". Of course, use this inside the form. With this, you will have the variable $rq set in the referenced php also. Also, $passedsubject = $HTTP_GET_VARS["rq"]; is not such a useful thing, I thing you could (and should) use simply $rq if it is passed to this page. - o - From: John Guynn <John.Guynn@telescan.com> Date: Tue, 21 Nov 2000 10:32:43 -0600 Subject: Get all the enum values from a Mysql column? >Is there an easy way to get all the enum values from a column? >For example I have an enum column with the values >"Astro","Camaro","Firehawk","Neon" and I would like to >pull those values out >to put in as <option>s in a html form with <select>. >I've read the mysql maunal about pulling all the values from and enum >column, "If you want to get all possible values for an ENUM column, you >should use: SHOW COLUMNS FROM table_name LIKE enum_column_name and parse the >ENUM definition in the second column." For some reason I can't make heads >or tails of this. >Anyone? >John Guynn at first look, I did not find a php function which would solve the problem (mysql_field_type() http://www.php.net/manual/function.mysql-field-type.php should be the solution, however, there are no words if it would describe enum values). So, try running a mysql_query ("describe tablename"); query and process the result. By the way, I think you shouldn't store car types like this, but code the types - so, create another table, with fields "typecode" and "typeexplained", former one a simple integer, latter one a character array. Now, you can insert the codes and corresponding types in this field, and have your main table store only numbers for the car types. Now, for a SELECT tag, you can simply select all rows from your defining table, and, when needed, you can look up what a code stands for from the defining table. by the way, camaro rox. :) - o - From: Jeof Oyster <jeof@jeof.net> Date: Tue, 21 Nov 2000 16:55:00 -0500 Subject: problems inserting in specific row >$query = "insert into >et01app_gen(lisalvation,lireasons,lifamilylife,lileadership,statusinterview ) values('lisalvation','lireasons','lifamilylife','lileadership','statusinterv iew') where >username=\'username\'"; >mysql_db_query($db,$query,$connection) or die("Error in query"); man, where have you learned sql.. :) Problem is you cannot use an insert command with a where clause. Where is for update or delete or select, but no way for insert. You must play around with insert and update, if everyone has his/her own record already, then simply use update, if noone has their entry the simply use insert, and when data is submitted, see if he/she already submitted, and if yes, then drop an error msg, else insert. If they should be able to modify, then see if he/she already have a record, if yes, do an update, if not, do an insert. And, by the way, this query will insert 'lisalvation', 'lireasons' as strings into the db. Use "values ('$lisalvation', '$lireasons'..." etc. to have the variables' values inserted :) - o - From: "jeff marston" <marstonj@bc.edu> Date: Tue, 21 Nov 2000 22:38:50 -0500 Subject: mySQL getting primary key of the last added record >Here's my problem: > I'm trying to insert a record into a table, then redirect to a page that >shows information about that record. I do the INSERT INTO tblname VALUES >(...), and let mySQL assign an auto_incrementing primary key ID field. Does >php have a function (like mysql_affected_rows(), I guess) that can tell you >about the last record that was inserted? Or maybe it's in mySQL -- I've >done something like this with SQL Server 7. Or maybe there's an easy >workaround that I'm missing. RTFM. mysql_insert_id() is what you are looking for. - o - From: Russell John Michell <r.j.michell@anglia.ac.uk> Date: Wed, 22 Nov 2000 09:41:08 +0000 (GMT Standard Time) Subject: mysql reinstall?? >Hi all: >I've trawled mysql.com and php.net etc, but havn't found what I'm >after: >I had my mysql server run automatically in the background when I >connected to my http server remotely (simply typing mysql -p >(password)) at the shell prompt. But I messed up trying to change the >password and consequently I don't know what I changed it to! (must've >been typing too fast and made a typo) LOL. :))) first of all, I think it is a good idea to have a "bacup" account set up for this reasons, an account with which you can manipulate the passwords of users at least, and have this account put on your azz and never use it until needed. Of course a very hard to gues password should be used. With it, now you could simply recover :) But you don't have one, I bet, or maybe you do? try if you have an account which could do the job. But before, look into your mysql history file in your home, it should contain the query you issued for changing the pass and thus you should see what you changed the pass... :) Hope you have your history file and you still have that query in it. :) Anyway, should you find it in it, delete that line from it, and everyone, after changing passes, delete relevant lines from mysql history - it's for your own good. :) - o - Date: Wed, 22 Nov 2000 17:41:39 +0800 From: Hoo Kok Mun <kokmun@familyhoo.net> Subject: Query Hang >Hi there, >I have a hanging problem with my statistical query. >I am using PHP 4.0.3pl1 and mysql 3.22.32 >My logic is something like.. >while loop (exit after 12 months) > Read current-month data with user-defined condition > display current-month data (eg. number of record) > current-month minus one (previous month) >end-while >My example: >Data in Database >- Dec 1999,Jan 2000 to Nov 2000 - every month has PC sales >- Nov 2000 - only this month has software sales. >When I do a query by PC sales, it came out fine with 12 months and the >number of records. >When I do a query by software sales, it will hang and the browser will >display "page not found" after a few minutes. >If I put in records for all the months for software sales, the query will work. >How do I ignore/skip the month with zero records? >Or is there any other way that I can overcome this problem? does the query hang itself? With while loops, sometimes ppl fall in the error of not doing the iteration correctly. Try using a for cycle, maybe it helps you out - my first thought is that your while loop hangs because it found not 12 but fewer months and keeps running and waiting for the 12th. - o - Date: Wed, 22 Nov 2000 09:23:34 -0600 (CST) From: Sharif Islam <mislam@students.uiuc.edu> To: "Luis O. Hernandez" <hernande@musicsearch.com> cc: PHP db list <php-db@lists.php.net> Subject: Re: [PHP-DB] Amigos una Ayudita plis!! hey, thanks for translate. second, for sure N$ says document contains no data, since his program has no output. Well, in case of error, the die command sends the error back, otherwise nothing goes back to the browser. This program only does connect to the db and then select a database - which is in fact useless and in fact should be avoided in my opinion but that's a question not to discuss here :) Please translate him this message. And tell him this is an english list. - o - man, more than enough for now...

« previous php.db (#4687) next »