smoked1 Posted June 19, 2007 Share Posted June 19, 2007 I am working on a script that will update a companies prices for the items that they list at pricewatch.com. I am pretty new to PHP but it's been easy so far. Basically the way that it works is that we can type this in to a browser: "http://mate.pricewatch.com/dl/updateprice.asp?d=MY_ID&x=MY_PASSWORD&pt=amdxp1500&pr=999" and the price will be changed to 999.00. I need to submit about 3000 of these from a script inside of a while loop using data from a database. It also needs to create a CSV file but I think I have that working just fine. Here is the code. If anyone could help me to get these URLs going like they should I would really appreciate it. <?php require('includes/application_top.php'); // Create DB variables $host = "localhost"; $user = "user"; $pass = "password"; $dbname = "dbname"; // Connect to mysql mysql_pconnect($host, $user, $pass) or die("Couldn't connect to SQL Server on $host"); // Select the database mysql_select_db($dbname); // Query the needed info $select = " SELECT products.products_model, products.products_model, products_description.products_name, products.products_price, products.products_id, products.products_image_med, manufacturers.manufacturers_name, categories_description.categories_name, products.products_model FROM products INNER JOIN products_description ON (products.products_id=products_description.products_id) INNER JOIN products_to_categories ON (products_description.products_id=products_to_categories.products_id) INNER JOIN categories_description ON (products_to_categories.categories_id=categories_description.categories_id) INNER JOIN manufacturers ON (products.manufacturers_id=manufacturers.manufacturers_id)"; // Create the variables $export = mysql_query($select); $fields = mysql_num_fields($export); // These are NULL because it is needed on WINBLOZE $header = ""; $data = ""; // Get the field names //for ($i = 0; $i < $fields; $i++) { // $header .= mysql_field_name($export, $i) . ","; //} // Replace the lame field names $header .= "PartNo" . ","; $header .= "Model" . ","; $header .= "Description" . ","; $header .= "Price" . ","; $header .= "URL" . ","; $header .= "ImageLink" . ","; $header .= "Brand" . ","; $header .= "Category" . ","; $header .= "ManPart" . ","; $header .= "Ship1" . ","; $header .= "Ship2" . ","; $header .= "ShipMess" . ","; // The while loop while($row = mysql_fetch_row($export)) { $line = ''; // Some static data $row[0] = $row[0]; $row[1] = $row[0]; $row[2] = $row[2]; $row[3] = $row[3]; $row[4] = 'http://domain.com/product_info.php?products_id='.$row[4]; $row[5] = 'http://domain.com/images/'.$row[5]; $row[6] = $row[6]; $row[7] = $row[7]; $row[8] = $row[8]; $row[9] = '0'; $row[10] = '0'; $row[11] = 'FREE FedEx Ground'; foreach($row as $value) { // If the data is NULL toss a tab in there if ((!isset($value)) OR ($value == "")) { $value = ","; } else { // If the data is not NULL delimit the shit $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . ","; } // Update prices now. $ch = curl_init("http://domain.com/dl/updateprice.asp?d=STATIC_USER&x=STATIC_PASS&pt=".$row[0]."&pr=".$row[3]); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_exec($ch); curl_close ($ch); // Line equals the value dickwad $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); // If there is not the user should probably know about it if ($data == "") { $data = "\n(0) Records Found!\n"; } // Modify the header $fp = fopen("../pricewatch/export.csv","w"); fwrite($fp, "$header\n$data"); fclose($fp); echo "Pricewatch file has been updated!"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/56283-need-help-with-http-requests/ Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 your question is weird but tell me if im wrong you want to send a header file right?? you cant loop a header file a thousands of time but to have your idea keep going ad a counter on your header file so that when the script see that counter the script starts at the given number of header file hope that helps or elaborate more if i was wrong Quote Link to comment https://forums.phpfreaks.com/topic/56283-need-help-with-http-requests/#findComment-278047 Share on other sites More sharing options...
smoked1 Posted June 19, 2007 Author Share Posted June 19, 2007 This is the part of the code that I am having issues with: // Update prices now. $ch = curl_init("http://domain.com/dl/updateprice.asp?d=STATIC_USER&x=STATIC_PASS&pt=".$row[0]."&pr=".$row[3]); curl_setopt($ch, CURLOPT_NOBODY, 1); curl_exec($ch); curl_close ($ch); I don't even want to open the page. All that this does is change settings on a server using the variables. Quote Link to comment https://forums.phpfreaks.com/topic/56283-need-help-with-http-requests/#findComment-278048 Share on other sites More sharing options...
teng84 Posted June 19, 2007 Share Posted June 19, 2007 "I don't even want to open the page. All that this does is change settings on a server using the variables."? using the url?? and change setting trough your db like UPDATE the db is that what you mean?? Quote Link to comment https://forums.phpfreaks.com/topic/56283-need-help-with-http-requests/#findComment-278053 Share on other sites More sharing options...
smoked1 Posted June 20, 2007 Author Share Posted June 20, 2007 Yeah it is an option provided for changing our prices on pricewatch. They say just submit a url to change the prices Quote Link to comment https://forums.phpfreaks.com/topic/56283-need-help-with-http-requests/#findComment-278515 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.