Hey Guys,
I would like to think I am slowly making progress with PHP but even the most simple scripts require endless tweaking to get working! Figured this is the best place to get some advice, and hopefully it will not be long before I can also contribute in a constructive way.
Without a doubt this issue is dead simple so please excuse the ignorance. Also not sure what I should search for to find a solution, which must already exist on the forum.
Here is my code without any repetition and it works fine. The id is retrieved from the database and is successfully passed to the query, which I have verified updates the categoryID for the correct row.
$domain = "domain.com";
print $domain . "<br>";
$sql = mysql_query("SELECT id FROM domains WHERE domain = '$domain'");
$row = mysql_fetch_array($sql, MYSQL_ASSOC);
$id = $row['id'];
mysql_query("UPDATE domains
SET categoryID
= '22' WHERE id
='$id'");
However, I am really trying to change the categoryID for a large number of records (domains) which are stored in a text file. 1 per line.
This is what I have so far:
// executes the code between { } once per line, until the end of the file is reached.
while (!feof($file)) {
$domain = fgets($file);
$sql = mysql_query("SELECT id FROM domains WHERE domain = '$domain'");
$row = mysql_fetch_array($sql, MYSQL_ASSOC);
$id = $row['id'];
print "UPDATE domains
SET categoryID
= '22' WHERE id
= $id<br>";
}
I would like to see the mysql queries before anything else, thus I am printing them. The while loop executes once for every domain in the text file as expected. However the $id is not printed. I don't understand how it works in the single case but not when the code is repeated. I have used $array['label'] in loops before and it worked fine.
If anybody could shed some light on my very newb problem I would be very grateful.
Thank you in advance,
Hal
:eek: