Welcome Guest, Not a member yet? Register   Sign In
PHP loop within an sql (mysql) query
#1

[eluser]ditch[/eluser]
Hello All, please bare with me as i'm new to programming as of 1 week ago. I'm using a combination of PHP and mysql to upload my picture paths to later be called via html and presented to the screen. Pictures are uploaded via a form with 4 image-upload inputs within the form.<-- users can upload from 1-4 images. The images paths are then uploaded to mysql table with the following column heading:
image0, image1, image2, image3

Is it possible to use PHP *within* a sql query? in particular a for loop?

This is what I had in mind in simple code:

$sql = "INSERT INTO items (user_id,title,comment,<--for loop--&gt;,date_created,active) VALUES ('$user_id','$item_title','$item_comment',<--for loop--&gt;'$today','$active')";

the <--for loop--&gt; would be something like this:

for ($i=1, $i<=$count, $i++){
image[$i];
}

$count = the number of images uploaded from the form
Doing this would then get the query to only INSERT the images it received from the form.

possible?


Messages In This Thread
PHP loop within an sql (mysql) query - by El Forum - 11-25-2007, 01:14 AM
PHP loop within an sql (mysql) query - by El Forum - 11-25-2007, 11:48 PM
PHP loop within an sql (mysql) query - by El Forum - 11-26-2007, 12:46 AM
PHP loop within an sql (mysql) query - by El Forum - 11-26-2007, 10:10 AM
PHP loop within an sql (mysql) query - by El Forum - 11-26-2007, 12:47 PM
PHP loop within an sql (mysql) query - by El Forum - 11-26-2007, 04:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB