Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. It counts them while it is processing and outputting them. If you want the list afterwards then it needs to be stored then printed after the counts are printed. $data = explode("\n", $stream); $fail=0; $failed = ''; foreach ($data as $line) { $arr = str_getcsv($line,',', "'"); if ($arr[5] != 'OK') { $failed .= $line.'<br>'; // store failures ++$fail; } } $tot = count($data); printf("%d sensors tested<br>%d OK<br>%d failed (listed below)<hr>%s", $tot, $tot-$fail, $fail, $failed);
  2. In that case, writing it for you isn't going to help you understand either. The manual should be available in different languages. Go to the site and select your native one.
  3. like this $data = explode("\n", $stream); $fail=0; foreach ($data as $line) { $arr = str_getcsv($line,',', "'"); if ($arr[5] != 'OK') { echo $line.'<br>'; ++$fail; } } $tot = count($data); printf("<hr>%d sensors tested<br>%d OK<br>%d failed", $tot, $tot-$fail, $fail);
  4. Then look at the examples, and see how they differ from yours
  5. http://uk1.php.net/manual/en/mysqli-stmt.bind-param.php
  6. does this do it? $data = explode("\n", $stream); foreach ($data as $line) { $arr = str_getcsv($line,',', "'"); if ($arr[5] != 'OK') { echo $line.'<br>'; } }
  7. buildSelectOptions() takes 3 arguments, you are passing 4.
  8. The answer is clearly "Yes"
  9. Look again! before: ID: 14 Cover:1 after: ID: 14 Cover:0 Both the image and cover are changed. If your objective is to switch which is the main image, just change cover and not the image name (or vice versa)
  10. if it's in a file, fgetcsv() would be my weapon of choice.
  11. OK, so what you told us in the first post was just a small part of the whole story. Is that "unformatted output" held in a text file?
  12. for($i = 0; $i < count($_POST['option_title']); $i++) { if (trim($_POST['option_title'][$i]) != '' && trim($_POST['option_quantity'][$i]) != '' && trim($_POST['option_retail_price'][$i]) != '' && trim($_POST['option_discount_price'][$i]) != '') { $insert_options->execute(array( $get_item_id, $_POST['option_title'][$i], $_POST['option_quantity'][$i], $_POST['option_retail_price'][$i], $_POST['option_discount_price'][$i] )); } }
  13. Example CREATE TABLE IF NOT EXISTS users_access_log ( log_id INT UNSIGNED NOT NULL AUTO_INCREMENT, user_id INT UNSIGNED NOT NULL, action VARCHAR(50) NOT NULL, previous_data VARCHAR(250) NOT NULL, current_data VARCHAR(250) NOT NULL, changed_date TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (log_id), KEY (user_id) ); CREATE TRIGGER log_address_change AFTER UPDATE ON user_addresses FOR EACH ROW INSERT INTO users_access_log (user_id,action,previous_data,current_data) VALUES ( NEW.user_id, CASE NEW.address_type WHEN 1 THEN 'Residential change' ELSE 'Postal change' END, CONCAT_WS(', ', OLD.street_no, OLD.street_name, OLD.city), CONCAT_WS(', ', NEW.street_no, NEW.street_name, NEW.city) );
  14. Triggers http://dev.mysql.com/doc/refman/5.6/en/create-trigger.html
  15. try foreach ($xml->Device as $device) { echo (string)$device['clientIdentifier'] . '<br/>'; }
  16. You can't include function calls inside strings as you are doing. You need to split the string in two and concatenate the function call. For example, instead of $message = "<p>Expected Repair Date: date('d/m/Y', strtotime($exrdate))</p>"; you would need $message = "<p>Expected Repair Date: " . date('d/m/Y', strtotime($exrdate)) . "</p>"; Alternatively you could store the results of the function calls in variables and then put those in the string EG $newId = mysqli_insert_id($mysqli); $repairDate = date('d/m/Y', strtotime($exrdate)); $message = "<p>Expected repair date: $repairDate</p> <p>ID: $newId</p>";
  17. Sorry. Check for blanks before inserting postal address
  18. Check the individual values inside the loop, before calling execute()
  19. First two lines should be $header = "Content-Type: text/html;charset=utf-8\r\n"; $header .= "From: [email protected]\r\n" . "Reply-To: [email protected]\r\n";
  20. mysql> SELECT * FROM item_images; +----------------+---------+-------+---------+ | item_images_id | item_id | cover | path | +----------------+---------+-------+---------+ | 1 | 58 | 1 | 111.jpg | | 2 | 58 | 0 | 222.jpg | +----------------+---------+-------+---------+ Then your query (the names have been changed to protect the innocent) UPDATE item_images im1, item_images im2 SET im1.cover = im2.cover, im2.cover = im1.cover, im1.path = im2.path, im2.path = im1.path WHERE im1.item_id = im2.item_id AND im1.path = '222.jpg' AND im2.path = '111.jpg' AND im1.item_id = 58; gives mysql> SELECT * FROM item_images; +----------------+---------+-------+---------+ | item_images_id | item_id | cover | path | +----------------+---------+-------+---------+ | 1 | 58 | 0 | 222.jpg | | 2 | 58 | 1 | 111.jpg | +----------------+---------+-------+---------+ which looks OK to me ???
  21. According to my IDE, the {s at the ends of these three lines have no corresponding closing }s <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['search'])){
  22. Would it be asking too much for you to post the error message that you are getting?
  23. I have to admit to being confused about why there is a repairs table with both an auto_inc ID and a unique repairID column. Why are these not the same column?
  24. What happened to the while($row=mysql_fetch_array($result)){ which you had in you previous version? You now have foreach ($result ... ) which is completely wrong
  25. $sql = "INSERT INTO user_addresses (user_id, address_type, street_no, street_name, city) VALUES (?,?,?,?,?) ON DUPLICATE KEY UPDATE street_no = VALUES(street_no), street_name = VALUES(street_name), city = VALUES(city)"; $stmt = $db->prepare($sql); $stmt->bind_param('iisss', $user_id, $address_type, $street_no, $street_name, $city ); // res address $address_type = 1; $stmt->execute(); // postal address $address_type = 2; $street_no = $p_street_no; $street_name = $p_street_name; $city = $p_city; $stmt->execute();
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.