Expand PHP Database Array

I am trying to break a paragraph retrieved from a database array into single words. This is the right way to do this because it is currently giving an error saying that explode () expects 2 parameters, so it should not collect 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;
            }
        }
    }
+3
source share
4 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 an array. Select the first item to explode. Read the documentation for Explode .

+3
source
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; 
            } 
        } 
    } 
0
source

.
words(). explode .
mysql, , -, . , , retirn ( , ).

,

function dbgetvar($query){
  $res = mysql_query($query);
  if (!$res) {
    trigger_error("dbget: ".mysql_error()." in ".$query);
    return FALSE;
  }
  $row = mysql_fetch_row($res);
  if (!$row) return NULL;
  return $row[0];
}

,

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

The string $ is completely filled with the value of the field, so $ e [0] is a right variable.

-1
source

All Articles