| | |
mySQL TABLES
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Oct 2009
Posts: 15
Reputation:
Solved Threads: 0
0
#3 18 Days Ago
no im still beginning learining php, if for example i have an items table, one of the fields in it is "images"
so what is the syntax
INSERT INTO items WHERE images
VALUES <how do i right the path>
is it a relative path or an absolute path?
can i add an image from anywhere in the machine or does it have to be from the images folder in my htdocs project folder
so what is the syntax
INSERT INTO items WHERE images
VALUES <how do i right the path>
is it a relative path or an absolute path?
can i add an image from anywhere in the machine or does it have to be from the images folder in my htdocs project folder
0
#4 18 Days Ago
•
•
•
•
no im still beginning learining php, if for example i have an items table, one of the fields in it is "images"
so what is the syntax
INSERT INTO items WHERE images
VALUES <how do i right the path>
is it a relative path or an absolute path?
can i add an image from anywhere in the machine or does it have to be from the images folder in my htdocs project folder
If you put the images in your images folder then you will need to store the path of each image you want to save in the table as a string, and then INSERT INTO items (image) VALUES ($image_path); or something like that.
Now, what you need to figure out is how to get the path in a variable basically. You can create a "browse for files" with Javascript, and then use what Javascript gets to POST the filepath as a variable and then store it in $image_path so you can use it as I mentioned before.
I hope this helps, sorry I can't really help with the JavaScript part that much, as I am not an expert on that and I would probably confuse you more. Maybe someone else can comment on that bit though.
I take your reality and substitute my own
violarisgeorge.com
violarisgeorge.com
0
#5 18 Days Ago
I'd suggest that you only use one main folder for images anyway. This then obviates the need for conditional rename functions.
Use the public document root (html) as opposed to the virtual document root (php) when storing the data. This means that if you change server, the folders will still be valid.
e.g.
'image' datum could be "/images/coolstuff/mypicky.jpg" (absolute reference to public root)
If you change your folder structure (or think it could change), reconfiguring paths in a DB can be a real pain. One (and I mean just one) way of doing this is to have a config.php file as an include file in each of your pages. This file typically contains db connection data and other important variables and constants.
You could have this:
which then gives you the freedom to store images as: "coolstuff/mypicky.jpg"
Whenever an image path is taken from the DB, just prepend the $imageroot:
If you now decide that the image folder needs to be moved below another folder, e.g. to "/media/images/...", you just need to change the value in the config.php file and not worry about your DB values.
Use the public document root (html) as opposed to the virtual document root (php) when storing the data. This means that if you change server, the folders will still be valid.
e.g.
'image' datum could be "/images/coolstuff/mypicky.jpg" (absolute reference to public root)
If you change your folder structure (or think it could change), reconfiguring paths in a DB can be a real pain. One (and I mean just one) way of doing this is to have a config.php file as an include file in each of your pages. This file typically contains db connection data and other important variables and constants.
You could have this:
PHP Syntax (Toggle Plain Text)
$imageroot = "/images/";
which then gives you the freedom to store images as: "coolstuff/mypicky.jpg"
Whenever an image path is taken from the DB, just prepend the $imageroot:
PHP Syntax (Toggle Plain Text)
$img = $imageroot . $row['image'];
If you now decide that the image folder needs to be moved below another folder, e.g. to "/media/images/...", you just need to change the value in the config.php file and not worry about your DB values.
"...the woods would be a very silent place if no birds sang except for the best"
All opinions count.
All opinions count.
![]() |
Similar Threads
- insert into multiple tables linked by foreign keys (PHP, MySQL) (PHP)
- populate select list from multiple Mysql tables (PHP)
- Help me to insert data into two tables in mysql (PHP)
- Selecting info from multiple mysql tables and display (PHP)
- Help connecting to mysql tables (JSP)
- URGENT: Implementing search with multiple dissimilar MySQL tables (MySQL)
- how to backup mysql DB to local machine? and restore? (MySQL)
Other Threads in the PHP Forum
- Previous Thread: Displaying files from database
- Next Thread: Customized user login
| Thread Tools | Search this Thread |
action advanced ajax api array autoincrement backup beginner broken button c# cache cheap check class close cms code curl database dehasher delete design display dropdown email file files flash flex folder form forms forum functions gentoo google hack hard head hosting html ibm image images include insert java javascript jpanel jquery key keywords kickfire link linux login mail mariadb menu msqli_multi_query multimedia multiple mysql mysql.data.client mysqlquery network oop open oracle php post programmer programming projectmanager provider query radio random script search security select server sms spam sql sun system table tag tutorial upload video view web webbrowser website youtube zend






