In multiple files upload(PHP/Mysql), the images are stored in single column. Want to store each image in single row with same id

Mukii kumar

table1

right now the images are stored in single column. I want to store each image in single row.

eg. the id "1149" has two images, now i want the image 1136524631.png in next row with same id i.e 1149. Similar for the id "1150".

here is the code->

if ( isset( $_FILES[ 'image' ][ 'name' ] ) ) {
    // Count # of uploaded files in array
    $total = count( $_FILES[ 'image' ][ 'name' ] );

    $image_name = array();
// Loop through each file
    for ( $i = 0; $i < $total; $i++ ) {
        //Get the temp file path
        $tmpFilePath = $_FILES[ 'image' ][ 'tmp_name' ][ $i ];
        $i_names = $_FILES[ 'image' ][ 'name' ][ $i ];
        $i_sizes = $_FILES[ 'image' ][ 'size' ][ $i ];
        $i_errors = $_FILES[ 'image' ][ 'error' ][ $i ];
        $i_tmp_names = $_FILES[ 'image' ][ 'tmp_name' ][ $i ];
        $i_types = $_FILES[ 'image' ][ 'type' ][ $i ];
        $exts = pathinfo( $i_names, PATHINFO_EXTENSION );
        $msgs = '';

        if ( $i_errors == 0 ) {
            if ( $exts == 'jpg' || $exts == 'jpeg' || $exts == 'png' || $exts == 'gif' ) {
                if ( $i_sizes > 0 ) {
                    $image_name[$i] = rand() . '.' . $exts;
                    $paths = '../img' . $image_name[$i];
                    $uploads = copy( $i_tmp_names, $paths );
                    if ( $uploads ) {
                        $image_name[$i] = $image_name[$i];
                    } else {
                        $image_name[$i] = '';
                    }
                } else {
                    $image_name[$i] = '';
                }
            } else {
                $image_name[$i] = '';
            }
        } else {
            $image_name[$i] = '';
        }
    }
} 



$image_name = implode(", ", $image_name);

mysql_query( "insert into posts(user_id,title,email,description,`condition`,contact_info,looking_for,price,location,image,is_active,created) values('$user_id','$title','$email','$description','$condition','$contact_info','$looking_for','$price','$location','$image_name','1','$created_date')" );
Mukii kumar

ANSWER: I solved the query. Please see the below code snippet

if ( $uploads ) {
                 //insert data into the database
                 $image_id = mysql_query( "insert into post_images(post_id,name) value('$postID','$image_name')" );
                        } else {
                            $image_name = '';
                        }

What i did? I just insert and save the image value in another table with "Foreign Key" and change the name

$image_id = array();

instead of $image_name = array();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Detecting multiple images in a single image

From Dev

Store multiple files in single document

From Dev

Displaying multiple columns from a single column in same row

From Dev

MySQL; Make a single row if multiple rows have the same id

From Dev

select multiple column into a single row

From Dev

I have two images that I want to display in a single row next to each other

From Dev

Multiple Row Param String to Single Stored Procedure

From Java

How to store an entire list in a single row of a column?

From Dev

Compare a column with multiple row to a colum with a single row

From Dev

Single array to store multiple variables in each element

From Dev

How to make images align side by side when fetch multiple images in a single column that belongs to the same category

From Dev

How to insert multiple data of same name from single form in multiple row of same column of table

From Dev

How to insert multiple data of same name from single form in multiple row of same column of table

From Dev

Read each row in a single column in a DataReader

From Dev

Multiple uses of single store on same page

From Dev

How to merge multiple images and text into single image?

From Dev

i want fetch the multiple data available in single row-column of table using query how to do that?

From Dev

All images in one single row, or all images below each other

From Dev

Convert multiple rows to single row for same Material

From Dev

Array of images stacked next to each other, using LayerDrawable.(Displaying multiple image in single imageview)

From Dev

combine an array of images to a single image which is a row of images in swift

From Dev

Multiple rows into a single row and combine column SQL

From Dev

Getting multiple column values in single row

From Dev

Excel - String in a single Row to Characters in Multiple Column

From Dev

Inserting multiple rows with column into single row

From Dev

Combining multiple row values into a single column

From Dev

Getting multiple column values in single row

From Dev

Calculated Column for multiple rows based on single row

From Dev

MS SQL Store Procedure to Merge Multiple Rows into Single Row based on Variable Table and Column Names

Related Related

  1. 1

    Detecting multiple images in a single image

  2. 2

    Store multiple files in single document

  3. 3

    Displaying multiple columns from a single column in same row

  4. 4

    MySQL; Make a single row if multiple rows have the same id

  5. 5

    select multiple column into a single row

  6. 6

    I have two images that I want to display in a single row next to each other

  7. 7

    Multiple Row Param String to Single Stored Procedure

  8. 8

    How to store an entire list in a single row of a column?

  9. 9

    Compare a column with multiple row to a colum with a single row

  10. 10

    Single array to store multiple variables in each element

  11. 11

    How to make images align side by side when fetch multiple images in a single column that belongs to the same category

  12. 12

    How to insert multiple data of same name from single form in multiple row of same column of table

  13. 13

    How to insert multiple data of same name from single form in multiple row of same column of table

  14. 14

    Read each row in a single column in a DataReader

  15. 15

    Multiple uses of single store on same page

  16. 16

    How to merge multiple images and text into single image?

  17. 17

    i want fetch the multiple data available in single row-column of table using query how to do that?

  18. 18

    All images in one single row, or all images below each other

  19. 19

    Convert multiple rows to single row for same Material

  20. 20

    Array of images stacked next to each other, using LayerDrawable.(Displaying multiple image in single imageview)

  21. 21

    combine an array of images to a single image which is a row of images in swift

  22. 22

    Multiple rows into a single row and combine column SQL

  23. 23

    Getting multiple column values in single row

  24. 24

    Excel - String in a single Row to Characters in Multiple Column

  25. 25

    Inserting multiple rows with column into single row

  26. 26

    Combining multiple row values into a single column

  27. 27

    Getting multiple column values in single row

  28. 28

    Calculated Column for multiple rows based on single row

  29. 29

    MS SQL Store Procedure to Merge Multiple Rows into Single Row based on Variable Table and Column Names

HotTag

Archive