0

Array which stores the paths/names of images: $wall_filenames[]

Contents of $wall_filenames:

Array ( [0] => wallpapers/2014/03/calendar-thumbnail-520x264.jpg [1] => wallpapers/2014/03/calendar-preview2-786x305.jpg )

MySQL Query:

$sql = "INSERT INTO walls(wall_name, wall_thumbnail_path, wall_preview1_path, 
        wall_preview2_path, wall_preview3_path,
        upload_date, d_1280x800_path, d_1366x768_path, d_1920x1080_path,
        p_640x960_path, p_640x1136_path, p_720x1280_path, p_768x1280_path,
        p_1080x1920_path, t_1024x768_path, t_2048x1536_path)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
$insert_wall = $connectDB->prepare($sql);

So the problem is, the table contains several columns. But when I insert once, it not necessary to upload all files which in my example above I'm only uploading two. What I need to do is add those array elements to there appropriate columns in my table. In this case I want $wall_filenames[0] to be stored to wall_thumbnail_path and $wall_filenames[1] to wall_preview2_path. I'm not sure how can I bind an array using bind_param() to point to correct column in table.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
vephelp
  • 552
  • 2
  • 10
  • 24

2 Answers2

0

Include the array index when you call bind_param:

$insert_wall->bind_param('sss...', $wall_name, $wall_filenames[0], $wall_filenames[1], ...);
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • my `$wall_filenames[1]` contains the path for `preview2`, in this case it would store the path to a different column I guess. – vephelp Mar 31 '14 at 05:47
  • Sorry, didn't notice all the columns with similar names. But the idea is the same -- just put it in the appropriate place in the argument list. – Barmar Mar 31 '14 at 05:49
-2

Be creative.

Do not store the data that can be calculated.

There is absolutely no sense in storing constant numbers in database. Just develop some naming policy, then get rid of all these path columns, and check your files from the disk according to naming policy.

Community
  • 1
  • 1
Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • amm I think I'm not storing numbers in database, just using them as reference. but yes, thanks for your suggestion on using names instead of numbers. – vephelp Mar 31 '14 at 05:59
  • 1
    There exists a place where suggestions can be offered, comments. – AyB Mar 31 '14 at 06:04
  • @vephelp you don't understand. **786x305** IS a number stored in database. Whlie there is no point in storing it there. Now get it? – Your Common Sense Mar 31 '14 at 06:07