So what I need to do is this: I have a field like this:
Chris Mayers 2 Anthony Street Melbourne, Australia.
I need to split the Chris Mayers part and put it in a column called 'Name' and then leave the "2 Anthony Street etc" part.
I have around 1200 rows I need to split and I have determined that the delimiters I will need to use are as follows: The numbers 1-10 and then Level, Suite or Unit.
This is the code I currently have.
<?php
// Create connection
$con = mysql_connect("localhost","root","","db");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else
{
echo "Connection Established.";
}
$db_selected = mysql_select_db('db', $con);
if (!$db_selected) {
die ('Can\'t use foo : ' . mysql_error());
} else
{
echo "DB Selected";
}
$sql = "SELECT `ADDRESS` FROM `table 1`";
$result = mysql_query($sql) or die(mysql_error());
$i = '1';
while($row = mysql_result($result,$i))
{
if($name = strstr($row, '1', true))
//$row contains the company name and address.
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '2', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '3', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '4', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '5', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '6', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '7', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '8', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, '9', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, 'Level', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, 'Unit', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
} else if($name = strstr($row, 'Suite', true))
{
$sql = "UPDATE `table 1` SET `NAME` = '$name'";
$yeah = mysql_query($sql) or die(mysql_error());
}
$i++;
}
echo "Cycle finished";
?>
It's not working. It has entered the same name into every field on the name column..
I'm a beginner at this kind of automation so any help is appreciated. Go easy on me ;)