Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explode database array PHP

I'm trying to breakdown a paragraph, retrieved from a database array, into separate words. Is this the right way to go about doing it because it is currently giving an error saying explode() expects 2 parameters, so it must not be picking up the $row array.

function words() {
        $query = mysql_query("SELECT text FROM table WHERE textID = 1");
        while($row = mysql_fetch_array($query)) {
            $e[] = explode(" ", $row);
            foreach($e as $r) {
                echo $r;
            }
        }
    }
like image 647
ashley Avatar asked Dec 06 '25 03:12

ashley


1 Answers

function words() {
        $query = mysql_query("SELECT text FROM table WHERE textID = 1");
        while($row = mysql_fetch_array($query)) {
            $e[] = explode(" ", $row[0]);
            foreach($e as $r) {
                echo $r;
            }
        }
    }

$row is array. Choose first element to explode. Read documentation for Explode.

like image 91
Denis Ermolin Avatar answered Dec 08 '25 15:12

Denis Ermolin