Hi All,
Need urgent help with the following script because I can not see any error in the script yet it does not work properly. The following script should read text file and add them to array. Then each array value is compared with MYSQL Database. It should output all values it can find from table and display them but it only displays the last entry in table. Your help will be much appreciated in advance.
<?
$connection = mysql_connect("host", "username", "pwd")
or die("Couldn't connect.");
$db = mysql_select_db("database", $connection)
or die("Couldn't select database.");
$filename = "info.txt";
$fd = fopen ($filename, "r");
$contents = fread ($fd,filesize ($filename));
fclose ($fd);
$delimiter = "\n";
$splitcontents = explode($delimiter, $contents);
$counter = "0";
?>
<br><br>
<?
foreach ( $splitcontents as $key => $value )
{
$sql = "SELECT * FROM table where field = \"$value\"";
$sql_result = mysql_query($sql,$connection) or die(mysql_error());
$row = mysql_fetch_array($sql_result);
$sku = $row["sku"];
$mpn = $row["mpn"];
echo "
<table border=1>
<tr>
<td>$counter</td>
<td>$sku</td>
<td>$mpn</td>
</tr>
<tr><td><b>Split $counter: </b> $value\n<br></td></tr>
</table> ";
$counter = $counter+1;
mysql_free_result($sql_result);
}
mysql_close($connection);
?>
The Info.txt file has following values:
n03-00032
n04-00033
n05-00034
.
.
.
.
n70-00069
The output comes as follows. I can not see any error in the script. Just don't know why it is not working. It is supposed to get values from Info.txt and with the help of mysql query display all values one by one but it only displays last value.
Split 0: n03-00032
1
Split 1: n04-00033
2
Split 2: n05-00034
.
.
.
.
70 n70-00069 A134ABU
Split 70: n70-00069
If anyone see any error or has any idea of solving this problem then pls let me know.