Jump to content

mallen

Members
  • Posts

    316
  • Joined

  • Last visited

Everything posted by mallen

  1. Sometimes there may be spaces before file names due to user error. If someone edits the exell file. Then when its imported I want to strip the blank space before entering it in the database. $documents = explode(",", $data[11]);
  2. Solved it. if ( ! empty($documents) ) // added foreach($documents as $addFile) NowI just need to find a way to trim file names. Just ltrim() the document name.
  3. This part of my code is causing a Invalid argument supplied for foreach() warning. I understand that the array is empty but not sure how to format this. This is used for importing a excell database. If there is no files for that particular item it will enter empty data to that table. Which is what I don't want. But making these changes causes the error. if($data[11] == "" || empty($data[11])) $documents = ""; else $documents = explode(",", $data[11]); foreach($documents as $addFile) { if(strpos($addFile, ".doc") !== false) $addFileType = "DOC"; else $addFileType = "PDF";
  4. Ok that cleared it up. Well I am about to close this thread. I think I have what I need. There is only so much I can do to make these files in order. In this list below technically are they in order? 'AB51MN50.jpg' and 'AB51MN100.jpg' are the same in the first six characters: 'AB51MN'. The seventh character is different: '5' versus '1'. One is less than 5, so 'AB51MN100.jpg' comes first. AB51HPS70.gif<--- AB51MN100.jpg AB51MN100.gif AB51MN175 w.jpg AB51MN175 w.gif AB51MN175 w.jpg AB51MN175 w.gif AB51MN175 w.jpg AB51MN175 w.gif AB51MN175.jpg AB51MN175.gif AB51MN175eue.jpg AB51MN175eue.gif AB51MN50.jpg<--- AB51MN50.gif AB51MN70.jpg AB51MN70.gif AB51PS150.jpg AB51PS150.gif
  5. So is this correct to trim just the empty space at beginning of file name? UPDATE file_name set file_name = ltrim(file_name);
  6. Would this be correct to run in PHPMyadmin to trim the empty space from beginning of files? UPDATE file_name set file_name = ltrim(file_name) WHERE id >0;
  7. That is just from me doing a copy and paste to notepad, formatting and then pasting to the forum. The extension is stored as part of the file. The other column is file_type but I am not using that.
  8. I am using latin1_swedish_ci on my file_type column. Can I just change it in PHPMyadmin?
  9. Maybe AB51MN50.jpg cannot appear 4th in the list before AB51MN100.gif because 1 comes before 5?
  10. Collation of the column is varchar utf8_general_ci
  11. Not sure if you saw my post further up but here is the entire block of code. Note the sort on $files global $wpdb; $out = ""; $query = "SELECT * FROM files WHERE `prod_id` = '". $this->curProduct ."' ORDER BY `file_name` ASC"; $files = $wpdb->get_results($query, ARRAY_A); ksort($files, SORT_NATURAL); if(count($files) >0) { $out .= "<h2>Title Here</h2>"; $out .= "<table id='xxx'>\n"; $row = 0; foreach($files as $file) { if($row % 2 == 1) $out .= '<tr>'; else $out .= '<tr class="even">'; $out .= '<td width="50"><a href="...../media/'. trim($file['file_name']) .'" target="_blank"><img src="/_image.png" alt="icon" /></a></td>'; $out .= '<td>'. $file['file_name'] . '</td>'; $out .= '</tr>'; $row++; } $out .= "</table>"; } return $out; }
  12. I have tried these queries: $query = "SELECT * FROM files WHERE `prod_id` = '". $this->curProduct ."' ORDER BY LENGTH"; $query = "SELECT * FROM files WHERE `prod_id` = '$this->curProduct' ORDER BY CAST(file_name as unsigned), file_name asc"; $query = "SELECT * FROM files WHERE `prod_id` = '$this->curProduct' ORDER BY LENGTH(file_name), file_name asc"; $query = "SELECT * FROM files WHERE `prod_id` = '$this->curProduct' ORDER BY CAST(file_name as signed), file_name ASC"; $query = "SELECT * FROM files WHERE `prod_id` = '$this->curProduct' ORDER BY CAST(file_name as alphanumeric) ASC"; $query = "SELECT * FROM files WHERE `prod_id` = '". $this->curProduct ."' ORDER BY LENGTH(alphanumeric)";
  13. Here is an another var_dump to show what results I am getting. Notice from file AB51MN50.jpg and below. This is where it is not in order. ["file_id"]=> string(2) "30" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51HPS70.gif ["file_type"]=> string(15) "GIF } [14]=> array(4) { ["file_id"]=> string(2) "38" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51MN100.jpg" ["file_type"]=> string(3) "JPG" } [15]=> array(4) { ["file_id"]=> string(2) "39" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51MN100.gif ["file_type"]=> string(15) "GIF } [16]=> array(4) { ["file_id"]=> string(2) "42" ["prod_id"]=> string(1) "5" ["file_name"]=> string(30) "AB51MN175 w.jpg" ["file_type"]=> string(3) "JPG" } [17]=> array(4) { ["file_id"]=> string(2) "46" ["prod_id"]=> string(1) "5" ["file_name"]=> string(30) "AB51MN175 w.gif ["file_type"]=> string(15) "GIF } [18]=> array(4) { ["file_id"]=> string(2) "43" ["prod_id"]=> string(1) "5" ["file_name"]=> string(30) "AB51MN175 w.jpg" ["file_type"]=> string(3) "JPG" } [19]=> array(4) { ["file_id"]=> string(2) "47" ["prod_id"]=> string(1) "5" ["file_name"]=> string(30) "AB51MN175 w.gif ["file_type"]=> string(15) "GIF } [20]=> array(4) { ["file_id"]=> string(2) "52" ["prod_id"]=> string(1) "5" ["file_name"]=> string(30) "AB51MN175 w.jpg" ["file_type"]=> string(3) "JPG" } [21]=> array(4) { ["file_id"]=> string(2) "53" ["prod_id"]=> string(1) "5" ["file_name"]=> string(30) "AB51MN175 w.gif ["file_type"]=> string(15) "GIF } [22]=> array(4) { ["file_id"]=> string(2) "44" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51MN175.jpg" ["file_type"]=> string(3) "JPG" } [23]=> array(4) { ["file_id"]=> string(2) "45" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51MN175.gif ["file_type"]=> string(15) "GIF } [24]=> array(4) { ["file_id"]=> string(2) "50" ["prod_id"]=> string(1) "5" ["file_name"]=> string(16) "AB51MN175eue.jpg" ["file_type"]=> string(3) "JPG" } [25]=> array(4) { ["file_id"]=> string(2) "51" ["prod_id"]=> string(1) "5" ["file_name"]=> string(16) "AB51MN175eue.gif ["file_type"]=> string(15) "GIF } [26]=> array(4) { ["file_id"]=> string(2) "34" ["prod_id"]=> string(1) "5" ["file_name"]=> string(12) "AB51MN50.jpg" ["file_type"]=> string(3) "JPG" } [27]=> array(4) { ["file_id"]=> string(2) "35" ["prod_id"]=> string(1) "5" ["file_name"]=> string(12) "AB51MN50.gif ["file_type"]=> string(15) "GIF } [28]=> array(4) { ["file_id"]=> string(2) "36" ["prod_id"]=> string(1) "5" ["file_name"]=> string(12) "AB51MN70.jpg" ["file_type"]=> string(3) "JPG" } [29]=> array(4) { ["file_id"]=> string(2) "37" ["prod_id"]=> string(1) "5" ["file_name"]=> string(12) "AB51MN70.gif ["file_type"]=> string(15) "GIF } [30]=> array(4) { ["file_id"]=> string(2) "48" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51PS150.jpg" ["file_type"]=> string(3) "JPG" } [31]=> array(4) { ["file_id"]=> string(2) "49" ["prod_id"]=> string(1) "5" ["file_name"]=> string(13) "AB51PS150.gif ["file_type"]=> string(15) "GIF }
  14. I did remove the offending leading characters in the data that is stored in my database table.
  15. I tried both of these and still didn't work. I mean it reorganized them but not in the order I need. I tried adding sort($files); thinking that maybe that is causing the issue.
  16. My tables are file_name and file_type one is varchar utf_general_ci the other is latin1_swedish_ci below is a sample vardump ["file_id"]=> string(2) "63" ["prod_id"]=> string(1) "6" ["file_name"]=> string(11) "AB20F84.gif" ["file_type"]=> string(3) "GIF" } [1]=> array(4) { ["file_id"]=> string(2) "64" ["prod_id"]=> string(1) "6" ["file_name"]=> string(11) "AB20F84.jpg" ["file_type"]=> string(15) "JPG" } [2]=> array(4) { ["file_id"]=> string(2) "55" ["prod_id"]=> string(1) "6" ["file_name"]=> string(14) "AB20BPS250.gif" ["file_type"]=> string(3) "GIF" } [3]=> array(4) { ["file_id"]=> string(2) "56" ["prod_id"]=> string(1) "6" ["file_name"]=> string(14) "AB20BPS250.jpg" ["file_type"]=> string(15) "JPG" } [4]=> array(4) { ["file_id"]=> string(2) "57" ["prod_id"]=> string(1) "6" ["file_name"]=> string(13) "AB20XV250.gif" ["file_type"]=> string(3) "GIF" } [5]=> array(4) { ["file_id"]=> string(2) "58" ["prod_id"]=> string(1) "6" ["file_name"]=> string(13) "AB20XV250.jpg" ["file_type"]=> string(15) "JPG" } [6]=> array(4) { ["file_id"]=> string(2) "59" ["prod_id"]=> string(1) "6" ["file_name"]=> string(13) "AB20PS175.gif" ["file_type"]=> string(3) "GIF" } [7]=> array(4) { ["file_id"]=> string(2) "60" ["prod_id"]=> string(1) "6" ["file_name"]=> string(13) "AB20PS175.jpg" ["file_type"]=> string(15) "JPG" } [8]=> array(4) { ["file_id"]=> string(2) "61" ["prod_id"]=> string(1) "6" ["file_name"]=> string(13) "AB20PS250.gif" ["file_type"]=> string(3) "GIF" } [9]=> array(4) { ["file_id"]=> string(2) "62" ["prod_id"]=> string(1) "6" ["file_name"]=> string(13) "AB20PS250.jpg" ["file_type"]=> string(15) "JPG" } }
  17. Yes I am working on code that someone else developed and I am in the process of cleaning up such forms that created these spaces. I have cleaned out the spaces on one product to test it. It still is not ordering the files. Upon searching for answers I came across the fact the letters are treated as ASCII? Is that why the mixture of numbers and letters do not give me an accurate list?
  18. I ran the var_dump() and some of the files names do have a extra space before them. What is strange is in the database, when I look at them in PHPMyAdmin there is no spaces. Can I add a trim function somewhere to these results?
  19. CAD435FG.gif CAD435FG.jpg DCG567CD.gif DCG567CD.jpg EFG324DF.gif EFG324DF.gif FG LMN WST.gif FG LMN WST.gif ABC123AB.gif ABC123AB.jpg No matter how I sort it it will put most of it in order like this except ABC123AB.gif, ABC123AB.jpg which should be at the top.
  20. global $wpdb; $out = ""; $query = "SELECT * FROM files WHERE `prod_id` = '". $this->curProduct ."' ORDER BY `file_name` ASC"; $files = $wpdb->get_results($query, ARRAY_A); if(count($files) >0) { $out .= "<h2>Title Here</h2>"; $out .= "<table id='xxx'>\n"; $row = 0; foreach($files as $file) { if($row % 2 == 1) $out .= '<tr>'; else $out .= '<tr class="even">'; $out .= '<td width="50"><a href="...../media/'. trim($file['file_name']) .'" target="_blank"><img src="/_image.png" alt="icon" /></a></td>'; $out .= '<td>'. $file['file_name'] . '</td>'; $out .= '</tr>'; $row++; } $out .= "</table>"; } return $out; }
  21. I think what is messing me up is the ordering the file by name. Then turning around sorting the ARRAY. I tried all the sort functions using sort($files); but I didn't get the result I was looking for. The files with the spaces I don't think is an issue. Because when the list is out of order those are not at the bottom or top of the list. I checked the database. Making sure there was not a space before the file name.
  22. I have this query and I want the files to be displayed in order. The problem is they are Alpha numeric. I have tried sorting them also and nothing seems to work. Sometimes a few files that should be at the top are at the bottom. Notice some have spaces also. The files follow this format. ABC123AB.gif ABC123AB.jpg DCG567CD.gif DCG567CD.jpg FG LMN WST.gif FG LMN WST.gif global $wpdb; $out = ""; $query = "SELECT * FROM files WHERE `prod_id` = '". $this->curProduct ."' ORDER BY `file_name` ASC"; $files = $wpdb->get_results($query, ARRAY_A);
  23. I figured it out. It is sending the mail OK. Its a mail server issue and I need to find a way to retrieve the mail in my mail box. I can see it on web mail.
  24. I am having trouble getting my form to send email. The script works and form is ok but I think its a formatting issue. Or maybe a header I am missing because it will send to some email addresses but one it will not. Its a Linux server. I don't get a bounce back message. Just goes nowhere. Then I change the email address to another one and it works. $headers = 'From: test@mywebsite.net' . "\r\n" . 'Reply-To: test@mywebsite.net' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); if(mail($to, "Contact Request From My website ", $msg, $headers)) header("Location:?page_id=7&m=ok"); else header("Location:?page_id=7&m=fail"); endif;
  25. I got it working now. It was a formatting issue. I checked the HTML on the page that rendered and kept tweaking the formatting. Also the CSS I had to correct so the button was working and lined up. I wasn't seeing the correct links on the page because how it was lining up. Thanks again Psycho for your help with this.
×
×
  • 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.