hi this question is linked to this post ive made in the mysql section. http://bytes.com/topic/mysql/answers...le#post3499253
simply i want to use a form to populate a table with the locations of images, thumbnails and their corresponding captions. i want to populate the table like this:
id image location thumbnail location caption
1 folder/image1.jpg folder/t/image1.jpg just a test
2 folder/image2.jpg folder/t/image2.jpg just the test
3 folder/image3.jpg folder/t/image3.jpg just to test
is it possible to loop php to insert data into more than one row in a mysql table like shown above?
14 3710
ok i have solved how to insert multiple rows in sql but is it possible to loop this in php so it inserts the correct amount of rows for the amount of images?
yes you can loop it exactly the no. of times the amount of images you have.
for that purpose u will have to set a variable to count the images. this variable will first check the no. of images and will restrict the loop to execute that many no. of times.
now how that can be done? u need to tell whr r the images stored & fetched from.
cant find anything on multiple insert with prepared statements
and pdkadam....i want to do this on upload not once its stored it will be alot easier that way because i can get this image and thumbnail locations once the code has been run in vars and then just add them into the sql (which is the last thing to run within the php script).
i think i will be using a foreach loop, i will set a array in the form called id[] but wont store this into the database as the project number will be stored as an id for later and easier retrieval. the images are already an array so therefore i have the captions to change to an array and then write my foreach loop....
i will be back with the results...thanks for the help guys
@anfetienne
then you should read a bit more about prepared statements...
it basicly goes like this - // ...
-
$ps->prepare($sql);
-
foreach (...)
-
{
-
// ...
-
$ps->execute($values);
-
}
Dormilich i dont appreciate the manner or tone of your last message.....simple fact is the link you sent explained prepared statements i read the whole thing and nowhere on that page did it give an example or state anything about multiple inserts. moderator or not you just rude....your answer wasnt needed especially in that manner as i previously stated that i found my way that i will use and i will return the results later.
thanks but no thanks for the answer!
and i also searched it on google and for tutorials but it kept coming up with javascript!
and i also searched it on google and for tutorials but it kept coming up with javascript!
I'd have thought you could have had a look at the PHP manual (eventually you need a PHP function to use Prepared Statements (just my train of thoughts)). manual entry (further examples in the function discussions) my google search @anfetienne
1) I'm not modding PHP
2) I can't have a good day everytime. I'm a human after all and are bound to make mistakes
3) I'm sorry if I upset you
* – someone once told me that "reading the manual" is a rare skill nowadays…
Dorm,
Don't worry, when i was learning PHP, if you had slapped me in the face then gave me the wrong answer, I'd still would have loved you for it :)
But that's just me, I love learning,
Dan
yea, sometimes I wish I had a teacher for PHP… anyways, thanks Dan
Dorm the Worm *harhar*
apology accepted....being new to php doesn't exactly help me in any case.
thanks for the tip, ill give it a try as well
ok ive done a test using prepared statements.....nice and fast but one problem....i dont know whether my loop is correct for this, it has worked when i done a multiple INSERT but only inserts 1 row with the prepared statements..
here is my code -
<?php error_reporting(E_ALL);
-
-
$returnURL = $_POST['returnURL'];
-
-
if(isset($_POST['create_xml'])){
-
-
// configuration
-
$dbtype = "sql";
-
$dbhost = "localhost";
-
$dbname = "theau10_resources";
-
$dbuser = "theau10_tawUser";
-
$dbpass = "auction10";
-
-
// database connection
-
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
-
-
// query
-
$sql = "INSERT INTO flashGallery (id,imageLoc,thumbLoc,imageCap) VALUES (:id,:imageLoc,:thumbLoc,:imageCap)";
-
$q = $conn->prepare($sql);
-
-
foreach ($_POST['random_digit'] as $key => $random_digit)
-
{
-
$q->execute(array(':id'=>$random_digit,
-
':imageLoc'=>$_POST['imageT'][$key],
-
':thumbLoc'=>$_POST['thumbnailT'][$key],
-
':imageCap'=>$_POST['captionT'][$key]));
-
-
}
-
-
}
-
?>
-
problem solved....just had to change id to tempID for the project number and add a column id to auto increment
here is the final code -
<?php error_reporting(E_ALL);
-
-
$returnURL = $_POST['returnURL'];
-
$random_digit = $_POST['random_digit'];
-
-
// configuration
-
$dbtype = "sql";
-
$dbhost = "localhost";
-
$dbname = "theau10_resources";
-
$dbuser = "theau10_tawUser";
-
$dbpass = "auction10";
-
-
// database connection
-
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname",$dbuser,$dbpass);
-
-
// query
-
$sql = "INSERT flashGallery (imageNo,tempID,imageLoc,thumbLoc,imageCap) VALUES (:imageNo,:tempID,:imageLoc,:thumbLoc,:imageCap)";
-
$q = $conn->prepare($sql);
-
-
foreach ($_POST['picT'] as $key => $value)
-
{
-
$q->execute(array(':tempID'=>$random_digit,
-
':imageNo'=>$value,
-
':imageLoc'=>$_POST['imageT'][$key],
-
':thumbLoc'=>$_POST['thumbnailT'][$key],
-
':imageCap'=>$_POST['captionT'][$key]));
-
-
}
-
?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Jason |
last post by:
I have a client that would like to have drop down menus added to a nav
bar that is generated from MySQL. Is it possible to have a dynamically
driven DHTML menu from MySQL?
example link...
|
by: Robert Kattke |
last post by:
I'm designing a site for local music and entertertainment and have a
few ?s that need to be cleared up. Currently, I'm working on the Club
part and have a Contact Person form, and a Club form. ...
|
by: Ward B |
last post by:
Greetings.
I'm somewhat new to this whole MySQL/PHP thing and need a little help.
My web hosting service uses phpMyAdmin and at the bottom of the screen
iis an area where I can upload a text...
|
by: kurty |
last post by:
Hello all,
I am currently working on a project (a web based database) which entails the use of HTML, PHP and MySQL. I am new to all of these languages and would like some assistance in solving the...
|
by: prosad |
last post by:
hello,
Just solved a problem using Javascript onclick, can click on any cell in a dynamic table and it will pass the innerText object value to my form text field. parts of code given below:
...
|
by: xhermit |
last post by:
I'm creating a wiki-style website with a mysql database.
I'm not to this point yet, but I'm thinking ahead of when I'll
need to start populating the database. Obviously the point
is for users...
|
by: eihabisaac |
last post by:
Hi everyone
I'm using VS2005 C# with MySQL to do a windows application
i'm also using Devart for MySQL
i was able to populate a combobox from the database
but i really want to populate...
|
by: eihabisaac |
last post by:
hi all
im using C# with mysql
i want to populate the menustrip items based on the select statement bellow
i can select the items from the table and show them but how to popule the MenuStrip
...
|
by: Philth |
last post by:
Hi there,
I've essentially got a form with several drop down, each populated by columns in various tables.
The populating bit works fine - the column rows appear as they should in the menu.
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |