Forum Moderators: coopster & phranque

Message Too Old, No Replies

MySQL and syntax

How do I put a relative path in a table field?

         

cyclic

9:39 pm on Jul 23, 2002 (gmt 0)

10+ Year Member



I now have a database up and running but I wish to put a relative path in a table to link to an image in a separate directory. I am a long way from home with no books at the moment and so would appreciate some help!

ergophobe

9:52 pm on Jul 23, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What's the issue? It's just a string, like any other string. Keep in mind that the link is relative to the file that is called in the URL, not relative to the DB, the file that is being included or anything else. So it doesn't matter if you are calling a library function or whatever, it will be relative to the main file, so just use whatever path you would want if you were coding it straight into a static page that has the same location as the main script file.

Tom

cyclic

10:01 pm on Jul 23, 2002 (gmt 0)

10+ Year Member



Hi Tom

I am very new to this and easily confused! When you say a string like any other, my table fields at the moment are just integers etc. What I want to do is (I'm using MySQL Front) is put the link in as a new field - excuse me if I am not making sense. So, when the data is displayed it has with it an image alongside. How do I describe the field? There are a lot of descriptors which I do not recognise in MySQL Front!

jatar_k

10:13 pm on Jul 23, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I am not too sure about mysql front but I can tell you that your field type should be either char or varchar. A sample field would be something like:

imgurl varchar(256)

again you will have to figure it out for mysql front. I would imagine that it is very similar to adding an int field but you may have an option to change the col type?

the sql for altering an existing table in this instance would be something like:

ALTER TABLE tablename ADD COLUMN imgurl VARCHAR(256) AFTER somecolumn;

cyclic

10:25 pm on Jul 23, 2002 (gmt 0)

10+ Year Member



Jatar

Thanks once again - I will go and give that a go and report back! I am in an internet cafe so time is tight. In MySQL Front you can set the field type so that is not a problem. If the IMG url is in a directory on the server then I presume it will be found?

jatar_k

10:43 pm on Jul 23, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



as long as the path is right you will have no problem.

ergophobe

1:38 am on Jul 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Cyclic,

MySQL-Front is nothing but a GUI interface for MySQL. Everything that is true for MySQL will be true for MySQL-Front. You should absolutely download a copy of the mysql manual and read it. It might not make sense at first, but as you play around, you'll find it easier and easier.

jatar_k mentioned using

varchar(256)

If you don't understand what he's talking about, check out the manual, specifically

Chapter 3, Tutorial [mysql.com]

Chapter 6.2 on Column Types [mysql.com] especially 6.2.3 on strings

And you may want to read more about strings [mysql.com]

Good luck!

Tom

sparrow

5:43 am on Jul 24, 2002 (gmt 0)

10+ Year Member



I use this in my of our sites, our field is set to "varchar".

Works like a champ. We have all of images in a directory under the root called "images" so the the sting simple is "images/url of pic"
it's that simple. We also control the size of the image for viewing purposes here as well. We have a filed for width and size, so it's all automatic.

cyclic

5:52 pm on Jul 24, 2002 (gmt 0)

10+ Year Member



Thank you everyone

I now realise that you can just put html into the table and everything works! I now have what I want ie. a thumbnail link to a more detailed page. Is there a limit to what html code you can use in a database field?

ergophobe

6:51 pm on Jul 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Not really. The big thing you have to watch out for are "escape" sequences. For example, if you have a tag that specifies a color using RGB values as in #FFFFFF for white, MySQL may interpret the # as a comment marker and disregard whatever follows. Similarly, you may need to escape quote marks.

There's currently a thread on mysql, quotes and addslashes that you might want to read.

[webmasterworld.com...]

Tom

jatar_k

7:10 pm on Jul 24, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



cyclic,

you will also have to be careful about field sizes as well. each field type has a max size attributed to it. When you create a column make sure that the max size you will be inserting will fit. Otherwise you may start losing data or getting errors.

and spend a lot of time on mysql.com

cyclic

1:03 am on Jul 26, 2002 (gmt 0)

10+ Year Member



Once again, thank you all. I am limited to an internet cafe at the moment so your advice is very welcome for long hours in front of a laptop!

From what I have read so far I presume there is no way that Mysql can store images? I have been trying to fathom out "BLOB" and I have looked at MySql but am none the wiser for the moment.

jatar_k

2:18 am on Jul 26, 2002 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



there is no need to store images in mysql (though I don't think you can). You just store them in a dedicated spot and store the path.

Blob is a large chunk of data. One thing that sets it apart is that it can not have a default value, if it isn't inserted it is blank. It can be any size you like. Each individual blob record will be a different size. Each record takes up as much room as the data it stores needs.

I use blob fields for comments. I never know how verbose someone is going to be. They could write 10 words or 10 paragraphs. If I use blob I don't have to worry about the amount of data someone might try to put in. They really are a messy field type and certain functions ie. group by are difficult to use on them. I would recommend staying away from them except where completely necessary.

As with all DB structure you have to be very careful to know what kind of data you are going to be storing and make the appropriate choice of col type. DB design and architecture is a skill, I think, and people have a tendancy to not take quite as much time designing and jump right in. I don't program one character until I have gotten all relevant input from the client and drawn and redrawn my DB until I am completely happy with its functionality. Unlike php all my DB spends most of its time on paper and all I do is input the fields when the time comes to build it.

You don't even need a computer to design a database, I usually write out all the queries and then I can hand it to someone if need be.

You also have to keep in mind that DB design is very much akin to object oriented programming. Each table within your DB represents a particular object and you store each of it's different attributes within it. Your scripting language makes up it's methods. Once you understand what piece belongs with each object you then reference each one internally by giving it a primary key to make it unique and easily referenced. You then decide which are sub classes and which superclasses and there by can create your relationships so that your data has a logical flow.

All of the above keeps you from storing row upon row of redundant data, repeating fields in multiple tables and enables you to use the true power of a select statement.

At any rate I seem to have strayed a little from my original purpose in this post but there is a definite art to DB design and creation. I don't think enough people realize that a properly created and referenced DB can save you a lot of time and problems when it comes to programming the lang for getting this data out. People treat them too often like the hall closet where they can throw whatever they find in and don't mind sorting through apile of garbage to find what they need. They don't understand that it is a living entity that is the core of the whole project and if the base of your project is stunted then the rest can only hope to ever be stunted.

just my two cents

ergophobe

5:42 am on Jul 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can store images in MySQL in a BLOB field, but for a variety of reasons you will likely prefer not to.

I just sent somebody a PM with a few reasons not to store images in the DB... now who was it? If you're reading, perhaps you could forward it?

Tom

cyclic

4:54 pm on Jul 28, 2002 (gmt 0)

10+ Year Member



This week has been a steep learning curve but thanks to you all I am making good progress. This may not be the correct forum but my next stumbling block is this:

I have images and text being grabbed from my database but what I would like to achieve is the link to the data appearing in the same page each time. As my page appears there are say 20 pieces of data all with links to more information about the individual items of data. At the moment they link to 20 new pages which is a bit time consuming to update. The pages have the same overall appearance but with the new data appearing from the link on that page. So, I am trying to have one page with the ability to show 20 new pieces of data, one at a time depending on the link chosen (I hope this makes sense!)ie. a template type of page with the ability to nest different data from MySql within in it I'm sure there is an answer, I just need a pointer to get me started.

ergophobe

10:19 pm on Jul 29, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



cyclic,

check out some fo the templating systems for PHP. There are several articles on it at devshed and phpbuilder. also look for the article on "PHP free energy". Search this forum - I've posted relevant links several times.

Cheers,

Tom