-1

I want to select a single row names news_images which contains record like this :

name.jpg,image.jpg,randomimagerame.jpg

These pictures does not have similar names, so I want to set them in array, here is my code :

$info = array($row['news_image']);
print_r($info);
echo  $info[0] . ", " . $info[1] . " and " . $info[2] . ".";

I got error :

Array ( [0] => name.jpg,image.jpg,randomimagerame.jpg ) Notice: Undefined offset: 1 in D:\PORTAL\htdocs\KARGI\news.php on line 84

Notice: Undefined offset: 2 in D:\PORTAL\htdocs\KARGI\news.php on line 84 name.jpg,image.jpg,randomimagerame.jpg, and .

How can I make this work ? I want result to be like this :

$info[0] = name.jpg
$info[1] = image.jpg
$info[2] = randomimagerame.jpg
3
  • 1
    Do NOT store delimiter separated lists into the DB! read over "db normalization" . Commented Jul 30, 2019 at 12:51
  • Thanks for answer i'll change it. Commented Jul 30, 2019 at 13:04
  • i'll change it... Perfect! You'll have a much easier life :) Commented Jul 30, 2019 at 13:06

1 Answer 1

0

You can use explode : explode()

 $info = explode(',',$row['news_image']);
 print_r($info);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.