Note that there are some explanatory texts on larger screens.

plurals
  1. POWordPress, MySQL, php - query results not acting as a string
    primarykey
    data
    text
    <p>This is driving me nuts. I've searched for solutions but can't figure out what's wrong.</p> <p>The situation... I have an SQL query running in WordPress, as follows:</p> <pre><code>SELECT distinct guid FROM $wpdb-&gt;posts WHERE post_status = 'inherit' AND guid is not null </code></pre> <p>Dead simple. It returns a single column which contains a list of all the attachment media files currently stored on the system (well, not all of them, but it'll do as an explanation).</p> <p>In a WP plugin function, I run the query:</p> <pre><code>$media_library_files = $wpdb-&gt;get_col($get_all_media,0); </code></pre> <p>That returns an array (I don't want an object) with values like:</p> <pre><code>[0] =&gt; http://mysitename.com/wp-content/uploads/2013/05/thumb_littlefile_blah.jpg </code></pre> <p>Then I want to process each one so that there's just the filename left. The problem is that, when I run a str_replace or pretty much any other string function on the contents, it doesn't work. For example:</p> <pre><code>$horrid_bit = 'http://mysitename.com/wp-content/uploads/2013/05/'; foreach($media_library_files as $item) { $item = str_replace($horrid_bit,'',$item); } </code></pre> <p>When I print_r the array after that, there's no visible change - every line is exactly the same as it was before.</p> <p>I've tried using a (string) to cast $item, I've tried defining variables to do that, then working the str_replace on them, I've tried... loads of different things.</p> <p>I have a feeling I'm missing something really simple, but I just can't see it. Is it because the column is varchar in the original table? Or something else?</p> <p>Any help appreciated. Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload