solution-digest
| From: | Trapeer | Date: | Tue, 31 Oct 2000 06:41:23 +0000 |
| Subject: | solution-digest | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-4063@lists.php.net to get a copy of this message | ||
>From: "Matthe Smit" <matthe@wol.nl>
>Date: Mon, 30 Oct 2000 16:56:51 +0100
>Subject: [PHP-DB] How to get a JPEG from a MS-SQL Database ?
>
>Hi,
>
>I'm having a problem with PHP4... I have saved some pictures (BLOB) in a
>MS-SQL7 Database. But I don't know how to get them out and use them in my
>html. Can anybody help me?
DO NOT store images in your database. Store images as files on your web
server. It is far more faster, etc., you do not have to run it thorugh the
database when accessing it, simply link it. In your database, store only the
filename or description of the file. The is absolutely NO use of storing
images in a database though some DBs even have direct support for it. Let's
assume you have a table containing the filename, x*y dimensions, and a
comment for each image (and an id, you can even use the id for file naming,
call them id.jpg) - you can easily search thorugh the files, and outputting
into html is as simple as:
echo "<img src=\"images/".$row["filename"]."\"
width=".$row["xdim"]."
height=".$row["ydim"].">";
additionally, you can make use of converting, identifying programs (such
program pack is image magick, available for linux and also windows as I
remember), or use GetImageSize (built in PHP command). So DO NOT store
images in databases.
-o-
>From: "Jayme Jeffman Filho" <jjeffmanweb@conex.com.br>
>Date: Mon, 30 Oct 2000 14:45:33 -0200
>Subject: Re: [PHP-DB] how can i use a link as a session var
>
>The "mysql_connect" function establishes a non permanent connection that
>will be automatic closed when the scripts finished its work. If you want to
>use the same mysql connection you should use "mysql_pconnect" instead.
>
>Jayme.
No, these connections will not be shut immediately, however, they won't be
any use to other scripts. But, using "mysql_pconnect" is a good idea. I do
not see a reason to use link variables themself passed to another script as
identifyers, and so I suggest you (the originator of the problem :) find
another solution.
-o-
>Date: Mon, 30 Oct 2000 11:20:43 -0700
>From: bryan <bryan@concept-factory.com>
>Subject: Navigation
>
>Say I have the following code to display a piece of article information:
> $query = "SELECT * FROM articles ORDER BY id";
> $result = mysql_query($query, $dbcnx);
> $row = mysql_fetch_array($result);
>
> if (!$result) {
> echo "NO RESULTS";
> } else {
> echo $row['content'];
> }
>
>How would I write Navigation to go to the next record through a link? And
>be able to go back? I am wanting to be able to search through records of
>articles using navigation instead of links to each article
There are several methods to do so, and it always depends on the given
situation (and the programmer's mood, hehe :) which to use.
1.) when displaying an article, select three rows, one to display, a
previous, and a next. you can do it in three steps, select where id=$id,
where id<$id, where id>$id. With this, you can even combine where statements
(where id<$id and del="n" for e.g.) and will work fine. Then, use links to
display prev/next article, and pass the appropriate id through the link
(href="view.php?id=42"). With this method, you can even step more than 1 at
a time (for e.g., back 10 steps, etc.).
2.) the other method is kinda more messy, and I think the only reason to use
it is when your database gets modified very often (once a second or maybe
even more often which I doubt :) pass the id displayed and "prev" or "next"
strings to the view script, and then use select statement with a "where
id<$id" for previous and id>$id for next entry. I mention this is really
messy and unless their is some specific reason, I do not suggest using it.
write a very simple displaying rutin and later spice it up with components
you might need.
-o-
>From: obo <tom@arb.net>
>Subject: Re: [PHP-DB] relational table help
without quoting your anti-recommendation, I really suggest this method to
use (see solution-digest 4058 by: Trapeer) with a little modification.
(furthermore, if You use coding like "<1><8><65><29>" then you can
use
select blahblah where category_codes like "%<$catnumcode>%" in your
statement, however, processing will be a bit messier since you cannot simply
use explode). I have used and also use this method and just works fine. Do
not overcomplicate things when not necessary. If your contact moves, simply
update his address. You can also manage categories simply, you just have to
use the coded category thing and use explode() to get appropriate numbers
which then You can manage like you would individual records. For e.g., I
have used this method to list members of a database who participated in jobs
(in the jobs table, I included the appropriate id's from the members table
separated by commas as described before).
Anyway, this method THEORETICALLY is totally equivavelent to the solution of
using a separate table do the job!!!! thinking goes a long way... :)
If we talk about this so much, there is one small "backpoint" of this
solution compared to having a separate table to do the job, but this can be
eliminated also (and will not be a problem in all cases). Who can gues what
it is? (I'll post it tomorrow if noone finds it out)
-o-
>From: "Chris Lee" <lee@mediawaveonline.com>
>Date: Mon, 30 Oct 2000 14:56:39 +0800
>Subject: update multiple tables... ?
>
>update product, product_image set price = '35' where stockno = '123456'
>
>(...)
>
>ERROR 1064: You have an error in your SQL syntax near ' product_image set
price = '37' where stockno = '972582589098437' at line 1
I just can't look up my mysql reference, but You can simply split up your
query into two separate querys. This will work fine I think.
-o-
>Date: Mon, 30 Oct 2000 16:31:30 -0700
>To: php-db@lists.php.net
>From: bryan <bryan@concept-factory.com>
>Subject: required
>
>Rather than using javascript to validate my input boxes that are required
>fields, is there a way in MySQL to do such a thing? I figure NOT NULL
>would do the trick, but it seems to take "" values just fine.
>
>Thanks for the help
>bryan
>
>Bryan Fitch
why not use php for validating ? I suggest using javascript so users will
not post querys which are invalid. Then, in the second step, use php to
validate _ALL_ the incoming data before doing anything. If an error found,
you can echo what the error exactly was, and use "exit;" to exit the script.
If you find variables correct, then you can do whatever needed in the same
script. If You have to do a lot of checks, put functions in a separate php
file including only function definitions, and include this file in your php
scripts.
OTHER: anyone found kind of this function-collection anywhere? Or, if
negative, is there anyone out there interested in writing a common-purpose
function definition collection to do such validating things? (for e.g.,
check if a value can be inserted into an sql statement without any errors,
etc.) ?
-o-
>Date: Mon, 30 Oct 2000 18:24:46 -0800 (PST)
>From: "Adv. Systems Design" <asd_2000@yahoo.com>
>Subject: JS or PHP (a little OT)
>
>hello:
>
>I have created a form that spawns a child window where
>user makes a selection and value selected in child
>window is returned to parent form textbox. This works
>great! (thanks to those who sent replies, it was just
>a syntax error...getting friendly with the netscape
>javascript console!)
>
>Problem: I have 6 textboxes on the parent form and
>want the child window to keep putting values in the
>parent form textboxes, but only if they are
>empty...for instance: user makes a selection in child
>window and clicks button to put value on to parent
>form textbox 1...user wants to put another value,
>clicks button on child form and script checks parent
>form, sees that textbox 1 is full so puts the value
>into textbox 2, and so on...
>
>Question is...can this be done in javascript or do I
>need to go into PHP?
I think it should be done via php, two methods you can use:
1 - pass all variables to your parent window, and display textboxes onyl if
a variable is empty, othervise, display the already set value.
2 - pass all variables to your parent window, then pass these back to the
parent window along with the new values (name them $old_var1, $old_var2,
etc, and $new_var1, $new_var2, etc.) then, when processing your parent
window, at the very beginning of the script (at validating, if you are doing
any, which I hope) look if $old_varX is empty, then use the new one,
othervise, use the old value and thus set up initial values. With this
method, you can even do the following: in your child window, display all
values, display input fields for all variables, and include checkboxes - if
a variable already has a value, but user checks the checkbox, then it will
override that value, otherwise, the new value will be ignored. If the
variable is empty, then use the new one whether checkbox is set or not.
I hope I understood correctly your question... :)
-o-
Best regards,
Trap
p.s.: if You find any of my responses useful, please tell me so in private
so I can feel my posts are not useless :) Or, if You disagree with any
solution, post your idea or at least why you find it bad.