1

I made the following query:

mysqli_query($conn, "SELECT image_first, REPLACE(image_first,'/home/erik/','')   
     FROM reviews_media WHERE review_id = $id");

I've tested it in PhpMyAdmin and it's working. But when I echo it, it's still showing the /home/erik/ part.

What am I doing wrong?

1 Answer 1

1

Obvioulsy you echo image_first value, but you need to echo result of REPLACE. You can modify query as:

mysqli_query($conn, "SELECT image_first, REPLACE(image_first,'/home/erik/','') as new_img FROM reviews_media WHERE review_id = $id");

See, I added an alias to result of REPLACE function. Now you can echo something like:

echo $row['new_img'];

As you don't do anything to result of REPLACE in a query, you can also simplify it and do a replace with php:

mysqli_query($conn, "SELECT image_first FROM reviews_media WHERE review_id = $id");
// fetching results
echo str_replace('/home/erik/', '', $row['image_first']);
Sign up to request clarification or add additional context in comments.

1 Comment

If answer solves your problem - feel free to accept it)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.