Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
function to pass special character filenames to urls
Psycho replied to bad_gui's topic in Third Party Scripts
Looks like there is a known issue with reading multi-byte characters in file names: https://bugs.php.net/bug.php?id=64327&edit=1 If the special characters are only in the file names (and not the folder names). Then do a check to see if the object is a folder. If not, assume it is a file. Here is a clean-up of your previous code. function showContent($path) { if ($handle = opendir($path)) { while (false !== ($file = readdir($handle))) { if ($file!='.' && $file!='..' && !valid_extension($file)) { $fileHTML = htmlspecialchars($file); $filePath = $path . DIRECTORY_SEPARATOR . $file; $fileURL = urlencode($filePath); if(is_file($filePath)) { $fileSize = format_size(filesize($filePath)); echo "<li class='music' data-icon='false'>\n"; echo "<a class='musicfile' href='#' data-src='{$_ENV['domain']}{$fileURL}'><h3>{$fileHTML}</h3>\n"; echo "<p class='size ui-li-aside'>{$fileSize}</p></a></li>\n\n"; } else { $coverArt = $filePath . DIRECTORY_SEPARATOR . $_ENV['coverart']; $imgSrc = (file_exists($coverArt)) ? $_ENV['domain'] . $coverArt : 'images/jewelcase_empty.png'; echo "<li class='folder'><a href='{$_SERVER['SCRIPT_NAME']}?path={$fileURL}'>"; echo "<img src='{$imgSrc}'>"; echo "<h3>{$fileHTML}</h3></a></li>"; } } } closedir($handle); } } -
function to pass special character filenames to urls
Psycho replied to bad_gui's topic in Third Party Scripts
How about you provide some example file names that are failing. How have you verified that it is the is_file() function that is not reading them right? You are modifying the file name before using is_file() so I don't know why you would expect it to work. Also, no need for an is_file() check and then an else if(is_dir()). The objects returned by readdir() are either files or directories. There is no third option (well, except FALSE, which the code already handles) -
function to pass special character filenames to urls
Psycho replied to bad_gui's topic in Third Party Scripts
I didn't read through your code, but why not use urlencode()? -
Create your query as a string variable. Then when you run into problems echo THAT to the page. By recreating the query for debugging, you run the risk of creating a different string for the output than you are for the actual execution. That's a recipe for many lost hours. The problem with your query is that you are using "AND" between the values you are setting - you need to separate them with a comma if (is_array($_POST['uid'])) { foreach($_POST['hours'] as $keyd => $value) { $query = "UPDATE participantlog SET noshow=1, hours='$value' WHERE cid='$cid' AND uid='$keyd'"; mysql_query($query) or die("Query: $query <br>Error: ".mysql_error()); } } EDIT: Also, running queries in loops is a bad idea. Unless you know that the list will be very small, you need to find a single query solution. Here is a page that may help you: http://www.karlrixon.co.uk/writing/update-multiple-rows-with-different-values-and-a-single-sql-query/
-
I prefer to include the table and headers even when there are no records. It makes the layout consistent. I look at the scenario where a user might be doing multiple searches. One search might return multiple pages of records, another only one page and yet another with no records. when the user does a search with no records they are going to be presented with a screen that looks and feels the same. Plus, just throwing a "no records found" in the middle of the page can look odd - if not done right. But, yes, it is a personal preference.
-
I'll also add that the sample method you created above should be called setVariable(). A get method should be used to retrieve a propert - not set one.
-
Here is a vry simplistic solution: When you output the records create the delete links like so <a href="?deleteID=XXX">Delete</a> Where "XXX" is the unique id of the record to be deleted by that link. Then on the code to render the page, put something like this as the top io the script (before the output is generated). if(isset($_GET['deleteID'])) { $deleteID = intval($_GET['deleteID']; $query = "DELETE FROM table WHERE id = $deleteID"; $result = mysql_query($query); } This will refresh the page when clicking a link. If you want to not refresh the page, then you wuold use the same logic using an AJAX solution.
-
There isn't a NULL value being passes. The statement to set $par will either be the passed value or an empty string. Since the default is for values >= 6, use the statement to set $par accordingly $par = isset($_GET['par'])?$_GET['par'] : 6;
-
I have to disagree with Kicken. The problem with the original code was that the value in the switch is compared to the value in the case statements. So, if you have switch($par) and case $par >=0 && $par <=2: It is comparing if $par is equal to ($par >=0 && $par <=2) - which would be either true/false. What you want to do is make the value for the switch be TRUE. Then create whatever comparisons you want for the case statements. This will work <?php $par = isset($_GET['par']) ? $_GET['par'] : ''; switch (true) { case ($par >= 0 && $par <= 2): echo 'par 0-2'; echo '<br/> PAR: '.$par; break; case ($par >= 3 && $par <= 5): echo 'par 3-5'; echo '<br/> PAR: '.$par; break; case ($par >= 6): echo 'par >=6'; echo '<br/> PAR: '.$par; break; default: echo 'ERROR: invalid PAR score passed. Please contact server administrator'; } ?>
-
It depends on what you mean by 10 digit. Do you consider 0000000001 the first valid number or is it 1000000000? Either way mt_rand() is what you want. mt_rand() $randNo = mt_ranf(1000000000, 9999999999); or $randNo = mt_ranf(1, 9999999999);
-
OK, it seems you've copied and pasted several different pieces of code (HTML, AJAX, PHP, MySQL) which are designed to work together. And, now you are trying to modify those pieces of code to work differently. But, if you don't understand the code you are using you are going to have a tight time knowing what to change and what not to change. You may need to make changes in the HTML, AJAX, PHP or MySQL, several of them, or all of them. I would start by seeing what is sent by the JavaScript/AJAX code when the order is changed. Then look at the PHP code to see how it would be processed.
-
Your post s very confusing. One thing you ask has nothing to do with another. Your initial question was about ABS(). In MySQL it is a math function that returns the absolute value of a number. Put simply, the absolute value is simply the positive value of a number. So, the absolute value of 3 is 3 and the absolute value of -3 is also 3. I'm really confused by your comments about ordering results and mouse/trackpad as those have nothing to do with the query.
-
Really? Your supposed example was an "Operation Report" which one would naturally assume is for business purposes. If someone in a company is purposefully submitting data to corrupt the layout I would consider that a personnel issue.
-
If you don't include year in the query,then you would get all results for the specified month - across ALL years. So, if you selected "May" you would get results from May 2013, May 2012, etc, You are probably getting the correct results now because you don't have data that spans multiple years. So, I would create the process to auto-determine the year to use. You can format the date either in your select query or in the PHP code to produce the output using date().
-
The "date" $today is a string. $today = date('l H:i:s'); @Wendi, What you apparently are trying to achieve is to reset the value of $count the first time this function is run each week. So, if it is run on Sunday morning it is reset to 0. Then each instance of the function running will increment the value by 1 - until the first execution the next Sunday. So, you need to determine how to know when it is the first run of the function each week. Let's say the function is run for the first time at 1:00am and the value is reset to 0. But, then if it is executed again at 2:00am how do you know that the value was previously reset at 1:00am? In fact, you can't guarantee that the function would get executed every Sunday, so you really want to know the first time the function is executed each week. You will need to store another value somewhere to track this. I would set a value for "the next reset timestamp" which on midnight at the beginning of the next Sunday. Then on each execution of the function, check if the current timestamp is greater than the next reset timestamp. If yes, reset the $count value and create a new reset timestamp. //COUNT PAGEVIEWS function wpb_set_post_views($postID) { $count_key = 'wpb_post_views_count'; $count = get_post_meta($postID, $count_key, true); $nextResetTimestamp = resetTimestamp(); if($count=='' || time() > $nextResetTimestamp) { $count = 0; delete_post_meta($postID, $count_key); add_post_meta($postID, $count_key, '0'); resetTimestamp(strtotime('next sunday')); }else{ $count++; update_post_meta($postID, $count_key, $count); } } For brevity, the above assumes a function exists called reset Timestamp(). If no parameter is passed the function would return the next reset timestamp that was saved. Else, if a parameter is passed, the function would use that value to change the next reset timestamp. But, you could do this much easier using a database by just tracking ALL hits and then doing a SELECT query only on the time period you want to report on.
-
This should get you started. Define a format array to list the rows in the order you want them to appear. Then call the function passing a title, the array of data, and the rowFormat array. //Array to define the rows to display with the title as the index and //the value is the index in the data array to display on that row. //If you need more data for the rows (e.g. to pass different formats //for the row, then make the value of each element a sub-array $rowFormat = array( 'Offered' => 'Incoming', 'Handled' => 'Handled_incoming' ); Function to create the table function outputTable($title, $dataArray, $rowFormat) { $headers = ''; $subheaders = ''; $dataRows = array(); foreach($dataArray as $header => $modeData) { $colspan = count($modeData); $headers .= "<td class=\"center channel_heading\" colspan=\"{$colspan}\"><a href=\"uk_retail_hh.php?c={$header}\">{$header}</a></td>\n"; foreach($modeData as $subheader => $data) { $subClass = "{$header}_{$subheader}"; $subheaders .= "<td class=\"center site_heading {$subClass}\">{$subheader}</td>\n"; foreach($rowFormat as $label => $index) { if(!isset($dataRows[$index])) { $dataRows[$index] = "<td colspan=\"1\">{$label}</td>"; } $dataRows[$index] .= "<td class=\"center {$subClass}\">{$dataArray[$header][$subheader][$index]}</td>\n"; } } } $output = ''; $output .= "<table border=\"1\" bordercolor=\"#000000\" style=\"background-color:#FFFFFF\" width=\"100%\" cellpadding=\"3\" cellspacing=\"0\"\n"; $output .= " <tr>\n"; $output .= " <td colspan=\"1\" rowspan=\"3\" class=\"unused\"></td>\n"; $output .= " <td class=\"center main_heading\" colspan=\"33\">{$title}</td>\n"; $output .= " </tr>\n"; $output .= " <tr>\n"; $output .= $headers; $output .= " </tr>\n"; $output .= " <tr>\n"; $output .= $subheaders; $output .= " </tr>\n"; foreach($dataRows as $row) { $output .= " <tr>\n"; $output .= $row; $output .= " </tr>\n"; } return $output; } Usage echo outputTable("UK", $dataArray, $rowFormat);
-
What will be variable between data sets? Is the left hand column always going to be the same? Will there always be chat, email & Phone? Do the three lette5r column headers going to change? Also, do you care what order that the subheaders are displayed in (e.g. 'ORK', 'EDI', 'VCC', etc.)?
-
SELECT main.*, rtgitems.item, (rtgitems.totalrate / rtgitems.nrrates) AS rank FROM main JOIN rtgitems ON rtgitems.item = main.id WHERE main.Category = '$sql_Category' ORDER BY main.`Name` ASC, rtgitems.totalrate / rtgitems.nrrates) DESC LIMIT $page, $limit
-
Don't use $doNotContact = mysqli_real_escape_string($dbcon, $_POST["doNotContact"]); The value should be a 1 or 0, so you should force the value to be that $doNotContact = isset($_POST["doNotContact"]) ? 1 : 0; On your form are you providing a list of empty fields? I think this process is more difficult than it needs to be. I would simply create a form that is populated with all the current values for the selected record. Then, when the user submits the form update ALL the fields based upon what was submitted. In fact, there is a flaw in that logic. If the user wanted to remove a value it would get overlooked because of the empty() checks. By updating all the fields the suer can edit/remove any current values.
-
What - exactly - do you mean it doesn't show anything at all. Are you not getting the error message you were getting before?
-
Warning: mysql_num_rows() expects parameter 1 to be resource
Psycho replied to ZeTutorials101's topic in PHP Coding Help
That is not accurate when using the mysql_query() function. It depends on "how" you are using that connection. Using the connection as you've coded it above does not require that the function has "visibility" of them. As long as a database connection was made outside the function, you can execute a query in the function without passing those references into the function (or, god forbid, using GLOBAL). Because, as stated in the manual, the second parameter for mysql_query() (the resource link identifier) is optional. If, however, you are using mysqli then it is a little different. Typically, I would think, you would create an object for the connection and then pass that object to the function. But, I think you could run a query in the function without passing any references if you executed the query using this format: -
You need to escape the input - which you should be doing anyway. Without knowing what type of database and functions you are currently using, it's impossible to say how you should fix it. But, I'm guessing mysql_real_escape_string() is what you need.
-
Database architecture for large web based software application
Psycho replied to jwwceo's topic in MySQL Help
Definitely start with one database. Only once you've built the application and have done some load testing will you know if the database is going to be a bottleneck or not. You do not want to set up each customer on separate databases. That would create a nightmare of managing any updates. But, if you do determine that the database will be a bottleneck, you would probably want to set it up so you can have multiple databases that each host many accounts.You would just need to implement a catalog/data abstraction layer that uses the account to determine which database to use. My company has an application used by hundreds of organizations world-wide and we've just started to implement such a solution. -
Also, are you aware that checkbox values are only passed in the POST/GET data when the checkbox is checked? You would want to do something like this in the code: $doNotContact = isset($_POST['doNotContact']) ? 1 : 0; Then use that value in your query.
-
You need to learn how to debug code. There is a single if() condition that would cause that error. That condition does three different checks against the value passed to the method. So, do a var_dump() of that value to see what is actually contains. if(!$file || empty($file) || !is_array($file)) { var_dump($file); //Debug line $this->errors[] = "No file was uploaded"; // Always shows me this error when trying to upload Then, if the value is not what you expect verify the value before it is passed into the function using the same process.