Jokeboy Jokeboy - 6 months ago 9
SQL Question

How to explode() value and save it in a variable?

Right now I'm working on a new homepage for a museum, and I have to use the old database (because it has over 70k entries).

My job now is to change the values in the "dias" table (supporter row) from full names of the supporters to their IDs (supporter table).

Right know I'm using this code:

$result = mysql_query("SELECT pate FROM dias");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
$pate = explode(" ", print_r($row[0]));
echo "<br>";
}


If I now put in
$pate[0]
, I only get "1" as output (along with the names from the print_r).

My question is:
How can I split the names and save them seperately in a variable, because I think I need this to be able to compare the names with the one in the supporter table and to write the ids in the supporter row in the "dias" table.

If you need more infomration, feel free to ask.

Answer

explode needs a string as the second argument, but you are taking the return value of print_r, which is true in this case. Just take $row[0] and you should have an array of your data in $pate.

Try printing $pate after that.

$result = mysql_query("SELECT pate FROM dias");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
        $pate = explode(" ", $row[0]);
        print_r($pate)
        echo "<br>";
}

After that continue :).

Comments