I'm using a for loop to go through an array and trying to make that the fields name in my database in phpmyadmin. The table gets created but my field name does not. Is there a reason for this?
At first I thought it was because of the space in each array so I replaced it with "_".
Here is my code:
<?php
include 'simple_html_dom.php';
include ('connection.php');
function getsquad($url, $tablename){
$html = file_get_html($url);
$player_fromsite = array();
$space = ' ';
$replacespace = '_';
$player = array();
foreach($html->find('td[align=left]') as $element) {
if ($element->children(0)) { // work only when children exists
array_push($player_fromsite ,$element->children(0)->innertext);
}
}
array_push($player, str_ireplace($space, $replacespace, $player_fromsite));
unset($player_fromsite);
$length = count($player);
for($i = 0;$i<=$length;$i++){
// Create a MySQL table in the selected database
mysql_query(" CREATE TABLE $tablename(
$player[$i] VARCHAR(30) ) ") or die(mysql_error());
}
echo "Table Created!";
}
$Squad = new squad();
$Squad->getsquad('site', 'Ars');
?>
The error message I'm getting are: "Array to string conversion" "Undefined offset: 1"
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCHAR(30) )' at line 2"
The errors are all on one line "$player[$i] VARCHAR(30) ) ") or die(mysql_error());"