Jump to content

mac_gyver

Staff Alumni
  • Posts

    5,449
  • Joined

  • Days Won

    174

Everything posted by mac_gyver

  1. if ($tango["uuid"]=$tablevalues[0]) { one equal is an assignment operator. your code is assigning $tablevalues[0] to $tango["uuid"] and testing if the value being assigned was equivalent to a true value. two equal == is a comparison operator.
  2. the best way would be to read, parse, and store the information in a database. you can then let the database engine do the work of finding information. all you need to do is form and run the database query statements.
  3. because you have a one to many relationship (each message can have many users that have not read it) you should not have the unread information stored with the message. you need a separate table to hold the message_id/user_id of the users who are in the corresponding chatroom, but have not read the message, one row for each message_id/user_id. when any user has read the message, simply remove his row from this separate table.
  4. @aysiu, the OP is trying to let a user selectively map/filter which csv columns correspond to which database table columns to provide a general purpose script for importing data from any arbitrary csv file into a database table.
  5. are you sure you have rows in your navigate table with values like that? your date('c') value, when being inserted into the table (i.e. your previous thread) is either producing a mysql error for an invalid date/time value (mysql in strict mode) or is inserting an all zero date/time (mysql not in strict mode.)
  6. the session variable i showed was just an example defining what the code expected as an input. it shows the index values that would be kept in the csv data and the corresponding field names. to produce your query statement, you could just loop over the session variable, getting the $key and $field name from each element. then use the $key to reference the data - $data[$key]. however, you can avoid an explicit loop by letting php do all the work using array functions - // list of fields to keep $_SESSION['fields'] = array(2=>'alt_email', 4=>'company'); // the key values are used to intersect with the actual array of data // callback function to produce the field = 'value' term for each set of fields/values function _set_terms($arr_k,$arr_v){ return "`$arr_k` = '$arr_v'"; // you could expand this to address the actual field type (not all of type string) } // example data, actual data would be from the csv line (fgetcsv) $data = array('field0','field1','field2','field3','field4','field5'); // for this example, want field2 and field4 values out of the array of data $result = array_intersect_key($data,$_SESSION['fields']); // keep only the csv fields you want // form the query $query = "UPDATE your_table SET "; $result = array_map('_set_terms',$_SESSION['fields'],$result); // produce the field = 'value' for each set of array entries $query .= implode(', ',$result); // combine into the query statement $query .= " WHERE some_condition_here..."; // finish the query statement echo $query; // display/run your query here.... lastly, if you are updating a large number of rows, you would actually want to use a multi-value REPLACE query, where you update/replace as many rows in one query statement as possible (2K - 5K.) each complete query you run (or each prepared query you send values for and run) requires a round-trip from php to the database server. for simple queries, each of these communications with the database server takes much longer than the actual query takes to run on the database server, so you should avoid running queries inside of any sort of loop.
  7. if the form you have shown is the form that is being submitted, it doesn't have a field named submit and your php logic testing if(isset($_POST['submit'])){ will never be true. what debugging have you done to pin down what your code is actually doing?
  8. your php code in the download file is either intentionally (i.e. your previous thread for this subject) or accidentally outputting characters to the browser that become part of the downloaded file, corrupting it. if you open the downloaded file that is failing in a programming editor, you will be able to see either what is being added to the start of the file. it's either some specific content, a php error message, or byte order mark characters.
  9. // list of fields to keep $_SESSION['fields'] = array(2=>'alt_email', 4=>'company'); // the key values are used to intersect with the actual array of data // example data, actual data would be from the csv line (fgetcsv) $data = array('field0','field1','field2','field3','field4','field5'); // for this example, want field2 and field4 values out of the array of data $result = array_intersect_key($data,$_SESSION['fields']); echo '<pre>'; print_r($result);
  10. echoing anything before the header will either prevent the header from being sent or if output buffering is on will become part of the downloaded data and corrupt the file and echoing anything after the header statements will also become part of the downloaded data and corrupt the file.
  11. you would build an array of non-empty search terms and implode it to produce the WHERE term. see this post - http://forums.phpfreaks.com/topic/281041-adding-filters-to-sql-databasephp-query/?do=findComment&comment=1445605
  12. if you don't want your files to be directly accessible (i.e. you would like to control who can access them, how many times they can be downloaded, throttle the speed, ...) you need to do two things - 1) place the files into a folder that cannot be directly accessed via any client/server protocol. you can either make a 'private' folder outside of your document root folder, which by definition/design won't serve up the files in it due to any external requests or you need to put a .htaccess file into a public folder containing the files to prevent direct external requests to the files. 2) dynamically output the files using a server-side script, i.e. php. at this point, this is a repeat of what Ninjakreborn has suggested. the download link will be to your .php script that is performing step #2. that php script will enforce any requirements you need, such as only allowing logged in users to download specific files they have permission to access, then it will find the appropriate file based on the id it was passed in the url, then it will output the appropriate headers to cause the file to be downloaded, then it will finally read the file from the protected location and output it to the browser.
  13. sorry to be blunt, but you would absolutely never store an id that defines the relationship between tables like this. you would use the actual value. if you have a need to display the id with the b and e around it, you would add those characters at the point where you are producing the output to display. the reason your query is returning everything as a match is it's probably doing a type conversion between strings/numbers and coming up with a true value that matches everything.
  14. what happened to the result in this recent thread - http://forums.phpfreaks.com/topic/281997-multiple-entries-to-db-using-one-text-area/ where a database table with an autoincrement id, date, player, and points and code to process and insert the data was produced?
  15. the php.ini settings that would allow an external php file to be included onto your server will also allow file_exists() to return a true value for that same file (when using the ftp:// wrapper.) you MUST validate that the string you are taking from the $_GET variable and using in your include statement ONLY consists of a permitted value for a local file to insure that it doesn't allow your code to include remote php code and run it on your server.
  16. using array_diff_key() - $list1 = array( "brym@yahoo.com", "gargamel@yahoo.com", "grungel@gmail.com", "shushlek@hotmail.com", "gushterlqk@aol.com", "shuslica@web.de" ); $list2 = array( "brym@yahoo.com", "grungel@gmail.com" ); $array1 = array(); foreach($list1 as $email){ list($name,$domain) = explode('@',$email); if(!isset($array1[$domain])){$array1[$domain] = array();} $array1[$domain][] = $email; } $array2 = array(); foreach($list2 as $email){ list($name,$domain) = explode('@',$email); if(!isset($array2[$domain])){$array2[$domain] = array();} $array2[$domain][] = $email; } $result = array_diff_key($array1,$array2); $final = array(); foreach($result as $arr){ // there should be a way to do this without a loop... $final = array_merge($final,$arr); } echo '<pre>'; print_r($final);
  17. just satisfying your second condition of removing all entries with the same domains found in the second list will remove the specific emails in the first condition. the quickest code would be to preprocess the arrays of addresses so that you have an array of arrays, where the main key is the domain name (shown in pseudo code form, not the actual array) - $array1['yahoo.com'] = array(brym@yahoo.com,gargamel@yahoo.com) $array1['gmail.com'] = array(grungel@gmail.com) $array1['hotmail.com'] = array(shushlek@hotmail.com) ... $array2 .... then (untested), you should be able to use array_diff() and the main key values in the second list will remove all the corresponding domain entries in the first list.
  18. in your original code, after the two exec(....) statements that resized/cropped the image, you had the remainder of your code that processed the form data? you still need for that code to run. change this - if (imagejpeg($canvas, "/home2/smiztita/public_html//images/content/" . $slika . '.jpg', 100)) { return true; } else { return false; } to this (note that i added a ! to complement the conditional test) - if (!imagejpeg($canvas, "/home2/smiztita/public_html//images/content/" . $slika . '.jpg', 100)) { // do something here when this process fails - some application error reporting/logging perhaps... }
  19. since you have provided zero actual information in this thread about what your code and data is, except for maybe your $row['amount'] variable, how could anything posted in this thread be anything more than an example/outline of a way of doing what you asked? programming isn't about randomly copy/pasting together things that you have seen or found. its about writing code, line by line, that does specifically what you want. in order to do that you must first define the steps that accomplish what you want and you must actually know what each statement does so that when you put statements together they contribute toward the goal you are trying to accomplish. if you currently have a loop that is iterating over the data from your query, couldn't you just take the example LOGIC that kicken posted and at the point where he showed a foreach() loop, use the existing loop in your code?
  20. actually creating an application involves coming up with a concept, then moving onto the design phase. the design phase involves defining what steps there will be in the process, what the user interface will look like for each step, what data will be input or displayed at each step, what data will need to be persistently stored... once you have defined what steps are needed, you can research and prototype code to develop and prove out the methods you are going to use to implement each step. then you write and test the code needed to produce the application. you are at the concept stage. you have a statement of what you want. what trq has suggested in your two recent threads is for you to actually sit down and think through the problem. have you tried to define any of the things i listed? start by pretending someone sits down at a computer and navigates to your web site. what can they see and do in front of them in the browser to use your application.
  21. what output did the print_r($_FILES); statement produce?
  22. or you could just use an existing open-source php based CMS (content management system), where all you do is produce and store the content and the navigation is built for you, not the other way around.
  23. the current code is somewhat a copy/paste of what someone posted in this thread and it contains return statements after the image resizing code. that will cause your code to stop at that point and return to the calling code (or if this is your main code, terminate execution.) at a minimum, you need to remove the logic containing the return statements.
  24. if you set the phpmailer Sender property to be your mail box on the sending mail server, it will set the Return-Path header to be that mail box and any bounce messages should be then sent to that mail box.
  25. your code has a $path variable that defines the path to where you have/want the source file and the destination file. use that $path variable everywhere you perform a file operation.
×
×
  • 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.