Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. I didn't read your entire post but I think you are making this more difficult than it needs to be. Look into using the INSERT ON DUPLICATE KEY UPDATE clause. You might need to set the uniqueness on a two column combination though.
  2. @MMDE; You calculation for the limit parameters is incorrect. $min = 8*5*($page-1) $max = (8*5*$page)-1 LIMIT $min $max You are apparently calculating the start index and the end index. However, the two parameters for LIMIT are the start index and the row count. So it should be coded more like this: //Define the rows/cols instead of hard coding $rows = 8; $cols = 5; //Calculate records per page and the limit start for the selected page $records_per_page = $rows * $cols; $limitIndex = ($page - 1) * $records_per_page; $query = "SELECT * FROM table LIMIT $limitIndex, $records_per_page";
  3. OK, I really wanted to get the details of each individual parameter, because it looks like there are several different codes in the text. In order to build a single expression I'd need to know if there are some variances not included in your examples. But I've made some guesses and produced the code below. Assuming all the messages have the same parameters, using the "example" strings you posted it appears to work. function getDetails($string) { $regEx = "(\d+) (\d\d:\d\d:\d\d) (\d\d-\d\d-\d\d) "; $regEx .= "@@ALERT ([^ ]*) ([^ ]*) ([^ ]*) (.*?)(?=/\w)"; $regEx .= "/([^ ]* [^/]*)//([^ ]* [^(]*)"; $regEx .= "\(([^\)]*)\) ([^ ]*) ([^ ]*) ([^ ]*) \[([^\]]*)\]"; // CTHEB CBOROS PT28 [THEB] preg_match("#{$regEx}#", $string, $match); return $match; } Using the two examples stings you posted the function will return the following for each Array ( [0] => 0571040 15:45:21 30-04-12 @@ALERT F546356345 THEB8 STRUC1 SMELL OF SMOKE AND ALARM OPERATING 900 SOME ROAD SOMESUBURB /CROSSSTREET1 RD //CROSSTREET2 AV M 99 A1 (429085) CTHEB CBOROS PT28 [THEB] [1] => 0571040 [2] => 15:45:21 [3] => 30-04-12 [4] => F546356345 [5] => THEB8 [6] => STRUC1 [7] => SMELL OF SMOKE AND ALARM OPERATING 900 SOME ROAD SOMESUBURB [8] => CROSSSTREET1 RD [9] => CROSSTREET2 AV M 99 A1 [10] => 429085 [11] => CTHEB [12] => CBOROS [13] => PT28 [14] => THEB ) Array ( [0] => 0571040 15:45:21 30-04-12 @@ALERT F546356345 THEB8 STRUC1 SMELL OF SMOKE AND ALARM OPERATING 4 / 900 SOME ROAD SOMESUBURB /CROSSSTREET1 RD //CROSSTREET2 AV M 99 A1 (429085) CTHEB CBOROS PT28 [THEB] [1] => 0571040 [2] => 15:45:21 [3] => 30-04-12 [4] => F546356345 [5] => THEB8 [6] => STRUC1 [7] => SMELL OF SMOKE AND ALARM OPERATING 4 / 900 SOME ROAD SOMESUBURB [8] => CROSSSTREET1 RD [9] => CROSSTREET2 AV M 99 A1 [10] => 429085 [11] => CTHEB [12] => CBOROS [13] => PT28 [14] => THEB )
  4. That's what I said. I still don't understand what your question is about. Is there a problem you are experiencing or a more specific question? If not, I cannot help you further.
  5. It would REALLY help if you were to explain all the parameters of the message and what the possible values are.
  6. Correct based on what? It is a validly named PHP file if that is what you mean.
  7. EDIT: jesirose beat me to it, but I'll post this nonetheless since I don't like seeing queries written inside the mysql_query() function as it makes debugging more difficult You didn't show your current code, so this is only a guess based upon the table fields $query = "SELECT comp_images.image, company.name FROM company LEFT JOIN comp_images ON company.id = comp_images.company"; $result = mysql_query($query) or die(mysql_error()); $company = false; while($row = mysql_fetch_assoc($result)) { if($company != $row['name']) { $company = $row['name']; echo "<br><b>{$company}</b><br>\n"; } echo $row['image'}; }
  8. One single database would be the best option for scalability and probably performance. It would also be much easier to maintain. For example, if you make updates to the application that requires changes to tables, you only need to make those changes once instead of multiple times for each database. What one customer does should not have any impact on what another customer does. That assumes you have taken the necessary precautions against SQL injection and other DB security threats. Also, you should make sure EVERY query includes an appropriate WHERE condition to only get information for the user's company.
  9. This isn't a desktop app that is installed with a point and click dialog, it is a web-based app that requires someone with knowledge to set up a web server, database, etc. If you want to protect your intellectual property then just host it as a SaaS application. It would cost more for hosting fees and such, but that gives you more leverage for a higher price point since there will be zero IT/maintenance costs for the end users. In addition, it means you will not have to worry about the most complicated part of support - the back end issues.
  10. What you are asking is simple. Just use file_get_contents() with a user back to your site passing an optional parameter for the CompID: $auth = file_get_contents('http://www.developersite.com/authenticate.php?CompID=123'); Then set up the page on your site to take the CompID from teh $_GET array, perform the validation, and then return a 1 or 0 (i.e. true/false). however, there is one big problem here. This could easily be circumvented by the user. They could easily find the place in the code that makes the check and simply circumvent it or hard code it to assume a true response is received. I don't have a good solution other than using some obfuscation - which would never be foolproof. You would need to do something so the user can't make the application operational by just commenting out or circumventing some lines of code. The only thing that comes to mind is some king of encryption process that would require them to get a new key once a month. But, this would lead to more complexity and if someone was really determined they could circumvent it anyway if they want to put forth the time and effort.
  11. I think you are making this significantly harder than it needs to be and it will not scale. It looks like you are running multiple queries to get the data? Why? Just run ONE query for the entire period you need. Then when you process the records you can manipulate the output by day/month or whatever you need.
  12. Values passed on the URL are available in the global $_GET array. So, if the user access a page using http://mysite.com/page.php?foo=bar&this=that Then when that script runs the $_GET array will look like this array( 'foo' => 'bar', 'this' = 'that' ) So, to expand on what jesirose suggested, you would do something like this: $query = "SELECT * FROM example"; if(isset($_GET['type'])) { $query .= " WHERE type = '" . mysql_real_escape_string($_GET['type']) . "'"; }
  13. There's also a tutorial right here on PHP Freaks: http://www.phpfreaks.com/tutorial/basic-pagination
  14. From what I understood he was going to have several functions that would be acting upon these variables. I don't know the nature of these functions, but if they would logically encompass a class then the code could instantiate the class and the variable(s) he is wanting to work with. He could then call the various functions (methods) of the class and they could reference the variables within those methods using $this->varName instead of having to pass them around or using the GLOBAL keyword. Then in the procedural code he can execute the different methods as needed and reference the current values at any time using $objName->varName; Without knowing how all the pieces fit together or not it's impossible to say if this is the right solution, but it is a possible solution.
  15. Sounds to me like you should create a class. You can then reference variables within the class inside and outside the scope of the functions (methods).
  16. I'm not following what your request it. I understand that a search is being performed. But, I'm a little lost on what is meant by "removing" the results of the search. Are you wanting those records to be deleted or only suppressed when displaying results on the other pages. If you want the records deleted, then you don't need to run a SELECT query at all, just change it to a delete query $query = "DELETE FROM uddannelser WHERE uddannelse LIKE '%$uddannelse%'"; $result = mysql_query($query); However, if you are wanting to perform that search and then suppress the results of that search on other pages, I see two solutions. 1. Don't run the select query at all (unless you do want to display them on that page). Instead, just save the search criteria to a session variable $_SESSION['uddannelse'] = $uddannelse; Then on the other pages where you want to suppress those records, just add the same condition with the NOT operator to suppress those records in the results SELECT * FROM uddannelser WHERE uddannelse NOT LIKE '%{$_SESSION['uddannelse']}%' Or you could run the SELECT query in the above code and retrieve the primary key for those records and save those to a session variable (probably as an array). This would be a little more code, but it would probably be more efficient. Then, again, add an appropriate clause to the other queries to suppress those records $suppressedIDs = implode(',', $_SESSION['uddannelser_ids']); $query = "SELECT * FROM uddannelser WHERE id NOT IN ({$suppressedIDs})";
  17. What you are saying and what you have coded are two different things. You state you only want to show an image if it is empty. That makes no sense. If the image is empty how would you show it. Now, if you were going to show a default image if the image was empty that would make sense. but, that is not what you stated and that is not what you coded. What you have coded would show the image if it is NOT empty - which makes more sense. If you are getting an image placeholder then the condition is apparently resulting in true. So, there are two probable issues that I can think of; both of which you can verify by inspecting the source code as jesirose suggests. The first one is that the value is not really an image name or not an image name that actually exists. So, check the source to see what the value is. The second problem is that the name is correct for an actual image, but the path is incorrect. Double check the actual URL that you can type in your browser to access the images directly and make sure that is what you are using. If the 'name' in the HTML source is empty you may want to verify what the actual value is. Try doing a var_dump() on $node->field_img['und'][0]['filename']
  18. Hold on a minute! Are you trying to say that Apple, of all companies, would actually implement some type of limiting ability and would think it was prudent or even preferred? Heck they might even refer to some such implementation as a "feature". I mean, c'mon, Apple and particularly it's user base are the epitome of humbleness. It's as if you might be implying that Apple would, in some way, be a little arrogant in thinking it is superior.
  19. PHP is a loosely types language. For example the number 0 will be treated as equivalent to the string '0' or the logical FALSE Boolean, etc. But, it can be problematic to rely upon these type of comparisons. If the value of a variable is 0 or '0' and you used (!$var) the condition would be true - even though the value was not an empty string. It is much better to be explicit in these situations to prevent problems. So, if you want to know if a certain variable has been set or not, then you use isset(). If you want to know if the var is an empty string then do that comparison. But, there is another problem with using !$var as well - especially with $_GET vars. Depending upon the error reporting level on the server, trying to use if(!$_GET['var']) would produce warning messages on the page if the value was not set.
  20. Maybe I missed something, but I would think a standard pagination script with the ability to reorder when the user clicks a column header is all that is needed. I didn't see anything in the requirements about having to filter the data. But, I would advise first implementing a solution with just PHP/MySQL. Then once that is working you can add some AJAX into it if you really want to.
  21. I have to agree. I'll second (or would it be third) that. You will NEVER get 100% accuracy. If you force the format based upon your rules you are going to save some names incorrectly. Granted, it might be a small percentage, but will sure makes those users unhappy. I have the problem that my last name routinely has an apostrophe added in many mailings I receive - even though I don't use one. It's disappointing to see that, but not a huge deal. But, if a website did that to my name and how it was displayed on that site I would be looking for a support email or phone number to voice my complaint. If you cannot get all the names correct then don't even try. Unless you are going to format it and then let the user approve it first.
  22. $query = "SELECT etchat_user_online_user_sex AS gender FROM db1_etchat_useronline WHERE etchat_user_online_user_name = '$usern'"; $result= mysql_query($query); $user = mysql_fetch_assoc($result); echo "DB gender value: {$user['gender']}<br>\n"; $displayGender = "Unknown"; if($user['gender']=='m') { $displayGender = "Male"; } if($user['gender']=='f') { $displayGender = "Female"; } echo "Full gender description: {$displayGender}<br>\n";
  23. You don't have anything in your code to display an image. I would assume your query is returning the ID, so you just need to add a line in the code that produces the output that looks something like this: echo "<img src='path/to/image/folder/{$row['id']}.jpg'>\n";
  24. Um, no that will not work. Did you even test it? Try changing one of those select list more than once. Besides, you should never hard-code functionality into event triggers.
  25. 1. Add the following JavaScript function to the HEAD of your HTML page <script type="text/javascript"> function updateQuery() { var state = document.getElementById('state').value; var prop = document.getElementById('prop').value; document.getElementById('query').value = state + ' ' + prop; } </script> 2. Modify the two SELECT opening tags so they have the appropriate IDs and call the above function onchange instead of hard coding. <select name="state" id="state" onchange="updateQuery();"> <select name="prop" id="prop" onchange="updateQuery()"> 3. Change the first options of those two select statements so the VALUES are empty strings. The label/text can still be what you have <option value=""> Choose State </option> <option value=""> Choose Property Type </option> Done.
×
×
  • 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.