Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Perhaps providing the entire error message (including the line number) and showing where that line is int he code you provided would be helpful. EDIT: But a quick check shows this $options = array( 'title' => __( 'Static image Link', 'yit' ), 'desc' => __( 'The URL where the fixed image will link.', 'yit' ), 'std' => '' ); ); // <======= But, once that is fixed you will get different errors because all of the values using the underscores followed by a value in parenthesis will cause an issue - unless you actually have a function with the name "__".
-
Yes, that is the preferred way to do it. I typically create an application such that any page call will load a "bootstrap" file which will perform any common tasks. I would still have separate files for DB connection and other tasks, and then include those in the boostrap file.
-
@Q695, I think it would help a great deal to show a true representative set of sample data and what you are trying to achieve. As I stated a long time back in this thread, I am almost certain you can get the data you need without doing any post processing of the data. If you need to sum the columns, then you would run a query such as the one I provided previously: SELECT SUM(field1) as field1total, SUM(field2) as field2total, SUM(field3) as field3total FROM tableName Or if you need a sum of multiple fields for each records (i.e. sum the row), then you would do something such as Zane provided SELECT (field1+field2+field3) as recordTotal FROM tableName
-
You would only get an error if both of the conditions were true. You can add some debugging lines to see which conditions are true/false. Try this and see what is returned: echo "DEBUG: check if $emailaddress or $password are false<br>\n"; if ($emailaddress && $password) { echo "DEBUG: $emailaddress and $password are not false<br>\n"; $db = @new mysqli('loalhost','rot','','FitessHouse'); if($db->connect_errno) { trigger_error('Unable to connect to database [' . $db->connect_error . ']', E_USER_ERROR); } else { echo "DEBUG: DB connection completed<br>\n"; } }
-
How to check if more than 1 constant is defined?
Psycho replied to eldan88's topic in PHP Coding Help
if(defined("API") && defined("transaction_key")) { -
I've reread through all of my posts in this thread and I don't see any comments that were demeaning to you. I did state that I thought the code was "crappy", but I think even you admitted it is a mess. I tend to be blunt and just tell it like it is. It is not intended to hurt anyone's feelings. Yes, I rewrote your code and that was not what you asked for. But, I did that for several reasons. 1) It makes it easier to work with the code and implement changes. When the logic in the code is haphazard it makes it difficult to even try and implement changes and have confidence that they won't cause regressions. 2) I know from years of experience on this forum, that if we do not help people to improve their coding process/style we will be helping the same people over and over again to fix the same problems or many problems that occur because the logic is confusing and leads to bugs. 3) If people learn how to do something in a "less optimal" way, that is what they will continue to do.If you learn to do something in a good process then you will continue that good process in the future. You have a LOT of logic in your code around setting styles and such. All it does is make your code more confusing and error prone. It would really make your code cleaner and much easier to read/edit if you were to take all of that out and use a style sheet. All it takes is one errant character in your code to break the PHP code of the HTML output. So again, I help on this forum on my own time and get nothing in return. If someone does not want the particular type of help I provide, that's fine, I'll just move on. But, I think it is presumptuous to tell me "how" I should provide help when you are getting it for free. Again, good luck to finding a solution to your problem - no sarcasm intended.
-
So, let me get this strait. You expect me to try and read through your crappy code and tell you what is wrong. But, you can't be bothered with reading through code I provide. That is how you learn. Read the code and figure out what it is doing. if you don't understand something look at the manual and figure it out or ask questions. I am providing free help on my own time. If you don't want the help that I provide, then I won't provide it. I wish you luck and hope you find a solution to your problem.
-
Why are you using the cat_category for the value instead of the ID? Anyway, give this a try <?php //Start with configuration variable $boxes_per_row = 4; //Set array of selected categories $selectedCategories = isset($_POST['share_category']) ? $_POST['share_category'] : array(); //Then get the data you need $query = "SELECT cat_ID, cat_category FROM tblcategories ORDER BY cat_ID ASC"; $result = mysql_query($query); //Process the data into output $rowCount = 0; while($row = mysql_fetch_assoc($result)) { $rowCount++; if($rowCount % $boxes_per_row == 1) { echo "<tr>"; } //Determine checked state $checked = (in_array($row['cat_ID'], $selectedCategories)) ? ' checked="checked"' : ''; echo "<td><input type='checkbox' name='share_category[]' value='{$row['cat_ID']}'>{$row['cat_category']}{$checked}<td>"; if($rowCount % $boxes_per_row == 0) { echo "</tr>"; } } if($rowCount % $boxes_per_row != 0) { echo "</tr>"; } ?> <table width='100%' border='0' cellpadding='0' cellspacing='0' class='body_text' style='padding-left:20px; padding-right:15px;'> <?php echo $checkBoxOutput; ?> </table>
-
As I stated the very fist time, don't define the style properties in the code. You should create classes in the HTML <style> tags and then apply the classes to the elements in the PHP code. I only create the $td1Style, $td2Style, etc. because I did not see where you were starting your HTML code to do that and I wasn't going to invest a ton of time on this. I would have instead defined classes such as "td1style" (or something a little more descriptive) and then applied those class names to the elements. Same goes for $stormScale. Don't define the properties in your code. Instead, define classes such as stormScale0, stormScale1, stormScale2, etc. Then you could set the class without needing any logic to do it echo "<td class="stormScale{$ef}">{$omeVar}</td>\n"; See how that would make the class dynamic without any code needed to figure it ouot?
-
Sorry, but creating clean, logical code from the beginning will reduce the total time to get your solution and reduce bugs. It take a little bit of extra time up front to do that, but you save much more time to actually complete since you are not going back and breaking things when you try to "clean up". So, I am not going to go back and rewrite the code into a less logical format. I see no reason why that bit of code would break your format since it was a copy/paste of the code you were already using. I just put it in a format that was programatically easier to work with. But, I do see that you had an HTML error in what you previously provided. That table that follows ever storm alert has an table OPENING tag at the end. . . . height='7' width='7'></td></tr><tbody><table>\n"; Try making that a closing table tag.
-
You could do two things: 1. If the values received in PHP are the same as the prompt text, change them to an empty string. 2. Use JavaScript to implement an onsubmit() trigger to remove the values in those fields if they are equal to the prompt text I would go with the latter because you could always ending up changing the prompt text. Keeping all the functionality with the prompt text in one place will make maintenance easier.
-
One possible solution: //Define all the replacements (in lower case) $replacements = array( 'first' => 1, 'second' => 2, 'third' => 3, 'july' => 7, 'august' => 8 ); function convertValues($value) { global $replacements; $testValue = trim(strtolower(iconv($value))); if(array_key_exists($testValue, $replacements)) { return $replacements[$testValue]; } return $value; } //Usage $vect = array_map('convertValues', $vect); Note that I used "global" to avoid redefining the array in the function. Since the function is called as a 'callback' from within the array_map() function you can't pass additional parameters. Well, you can, but it's a little ambiguous and I'm too lazy to look up how it's done. So, one solution would be to make this a class where the replacement values are a property in the class.
-
Sorry copy/paste error. Forgot to remove the "!"'s from the second condition check //Verify if ANY date fields have a value if(!empty($day) || !empty($month) || !empty($year)) { //verify that ALL date fields have a value if(empty($day) || empty($month) || empty($year)) { $errMsg = "You must enter a value in all date field"; } else { header ("Location: results.php"); exit; } //Perform validation that the date fields values are a VALID date } But, I'm not sure I understand the purpose of the header(). With what you have now, if the user has entered values for all of the date fields they will be redirected and all the data lost!
-
This should really be a two step process. Once to verify that if any fields are entered that they all have values. Then you would need to validate that the value make a valid date. $day = isset($_POST['DoD_DD']) ? trim($_POST['DoD_DD']) : ''; $month = isset($_POST['DoD_MM']) ? trim($_POST['DoD_DD']) : ''; $year = isset($_POST['DoD_YY']) ? trim($_POST['DoD_DD']) : ''; //Verify if ANY date fields have a value if(!empty($day) || !empty($month) || !empty($year)) { //verify that ALL date fields have a value if(!empty($day) || !empty($month) || !empty($year)) { echo "You must enter a value in all date field"; } //Perform validation that the date fields values are a VALID date }
-
This is a very odd use of the ternary operator // get path info & protect for cross-site scripting vulnerability ($_SERVER['REQUEST_URI']) ? $sri = htmlspecialchars(strip_tags($_SERVER['REQUEST_URI'])) : $sri = ''; Do this instead $sri = ($_SERVER['REQUEST_URI']) ? htmlspecialchars(strip_tags($_SERVER['REQUEST_URI'])) : ''; I'm seeing a lot of other inefficiencies as well. For example $attrs = array(); foreach($report->attributes() as $a => $b) { $attrs[$a] = $b; } $value = array_search('1', $attrs); switch ($value) { You are looping through all of the values in attributes and putting into an array, then searching the array for a particular value and only using that value. It doesn't appear you are using the other values. Instead, just loop through attributes and "break;" the loop once you've found the value you want. Aslo, you can replace the switch with a simple array to convert the value to what you need Also, you could use classes for the default style properties to make the code cleaner. In fact, you should consider setting any "static" output as a variable outside the loop instead of redefining it inside the loop - such as the table that goes after each record. Makes it easier to manage the code. There are other things as well. Here is a rewrite of your code that should display the "no storm" message depending on the format of the XML file (as Jessica alluded to). This isn't tested since I don't have your file. So, there may be some minor typos and such. But, I tried to put it in a more logical format. I would definitely use classes instead of creating all that code in the script. <?php ####################################################################################### # # SPOTTER NETWORK STORM REPORTS # version 1.00 # # This program is free and no license is required. # # # mesquiteweather.net # ####################################################################################### //// SETTINGS //// // Change colors $bkgColor = '#FFF'; // Background color Examples: "gray" "#CCC" "#CCCCCC" $bc = '#EEEEEE'; // Background color of table cells $dtColor = '#FFF'; // Date & time color Examples: "#FC0" "#FFCC00" "white" //// END OF SETTINGS //// ####################################################################################### ini_set('display_errors','1'); ## Start Configurable data ## //Set message to display if there were not reports $noStormMessage = 'There are currently no storm reports'; //Set path to data file $data = "http://www.spotternetwork.org/data.php"; ## End Configurable data ## // overrides from the Carter Lake Settings.php file (if applicable) global $SITE; if(isset($SITE['cacheFileDir'])) {$cacheFileDir = $SITE['cacheFileDir']; } if (isset($SITE['imagesDir'])) {$imagesDir = $SITE['imagesDir'];} if(isset ($SITE['tz'])) {$ourTZ = $SITE['tz'];} if(!function_exists('date_default_timezone_set')) { putenv("TZ=" . $ourTZ); } else { date_default_timezone_set("$ourTZ"); } // get path info & protect for cross-site scripting vulnerability $sri = ($_SERVER['REQUEST_URI']) ? str_replace('#SA', '', htmlspecialchars(strip_tags($_SERVER['REQUEST_URI']))) : ''; ## ALL OF THESE STYLE PROPERTIES SHOULD BE PUT INTO CALSSES IN THE HTML ## ONLY VARIABLE STYLES SHOULD BE IN THE CODE HERE // set borders $bbrdr = 'border-bottom:thin solid black'; // bottom $lbrdr = 'border-left:thin solid black'; // left $rbrdr = 'border-right:thin solid black'; // right $tbrdr = 'border-top:thin solid black'; // top $sbrdr = 'border-right:thin solid black; '. 'border-left:thin solid black'; // side $tableStyle = "width: 100%; margin:0px auto; background-color:{$bkgColor};"; $td1Style = "{$tbrdr};{$sbrdr}; padding:2px 0px 2px 6px; background-image:url({$imagesDir}headerbgd2.gif); color:{$dtColor};"; $td2Style = "{$sbrdr}; padding:6px 0px 0px 6px; background-color:{$bc};"; $td3Style = "{$sbrdr}; line-height:5px; background-color:{$bc}": $td4Style = "{$sbrdr}; {$bbrdr}; padding: 2px 6px 6px 6px; background-color:{$bc}": //Define table to display after each storm report $afterTable = "<table style='margin-bottom: 5px;' border='0' cellpadding='0' cellspacing='0' width='100%'><tbody><tr><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td class='shadow-mid' width='100%'><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td><td><img alt='' src='images/1pixel.gif' border='0' height='7' width='7'></td></tr><tbody><table>\n"; $stormTypesAry = array( 'tornado' => 'Tornado', 'funnelcloud' => 'Funnel Cloud', 'wallcloud' => 'Wall Cloud', 'rotation' => 'Rotation', 'hail' => 'Hail', 'wind' => 'Wind', 'flood' => 'Flood', 'flashflood' => 'Flash Flood' ); $xml = simplexml_load_file($data); //Set initial output to false $tData = false; foreach($xml->report as $report) { $date = $report['stamp']; $time = strtotime($date.' UTC'); $dateInLocal = date("D g:i a", $time); $narrative = $report['narrative']; $loc = $report['city1']; $tz = $report['tz']; $stormType = 'Unknown'; foreach($report->attributes() as $typeKey => $id) { if($id == 1) { if(array_key_exists($typeKey, $stormTypesAry)) { $stormType = $stormTypesAry[$typeKey]; } break; } } // construct data for table display $tData .= "<table style='{$tableStyle}' cellpadding='0' cellspacing='0'>\n"; $tData .= "<tbody>\n"; $tData .= " <tr><td style='{$td1Style}'><b>{$stormType}</b></td></tr>\n"; $tData .= " <tr>\n"; $tData .= " <td style='{$td2Style}'>Reported: <b>{$dateInLocal}</b> - </b>Location: <b>{$loc}</b></td>\n"; $tData .= " </tr>\n"; $tData .= " <tr><td style='{$td3Style}'> </td></tr>\n"; $tData .= " <tr><td style='{$td4Style}'>Description: <b>{$narrative}</b></td></tr>\n"; $tData .= "</tbody>\n"; $tData .= "</table>\n"; $tData .= $afterTable; } //If no storms were in the source, set no storm message if(!$tData) { $tData = $noStormMessage; } echo $tData; ?>
-
So, I assume you want all the data from that query - even though many records will have the same race name, correct? But, you also want a list of the unique race names. It would be helpful to know how you want to output the data as that might affect the best solution to implement. But, there's really no way to do this with a single query. If you don't need all the data, then you could simply do a GROUP BY. But, if you do need all the data, I would do this in the PHP code that processes the results. Something such as $query = "SELECT phpbb_users.user_email, races.date, races.name, races.odds, races.race, actions.action, actions.user_id FROM races RIGHT JOIN actions ON races.name = actions.name RIGHT JOIN phpbb_users ON actions.user_id = phpbb_users.user_id WHERE races.date = $date"; $result = mysql_query($query); $uniqueRaceNames = array(); while($row = mysql_fetch_assoc($result)) { //Check if current name has been added to array, if not add it if(!in_array($row['name'], $uniqueRaceNames)) { $uniqueRaceNames[] = $row['name']; } //Process the rest of the data }
-
how inactive submit button till user not fill the form?
Psycho replied to noahwilson's topic in HTML Help
You can do it with JavaScript - but that is no real guarantee that the user cannot submit the form until then. So, you definitely want server-side code to reject the submission if all the data is not there. You can, however, add JavaScript to add some client-side functionality to prevent 99% of submissions where the data isn't entered. But, you need to make a decision as to what you will do for users that don't have JS enabled. Do you not allow them to use the form at all or do you let them submit even though they may not have had the form completed. That will be key to how the solution is implemented. -
You obviously don't have an understanding of what the SUM() function in a query does - it sums the values across records (i.e. what you mean by top-down). The whole underscores only makes your example harder to understand since ____ and _____ aren't more different. If you had even looked at the sample query I provided and tried to use it I'm sure you would find it gives you the results you want in one simple query with no need to process the results.
-
Um, what? How are you relating those fields? If you had taken the time to put at least example names for the array indexes it would make some sense. But, what you have there makes no sense. How does an array field with an index of five underscores get added to the array index in another element of four underscores? Based upon what you were attempting previously foreach (mysql_fetch_assoc($result_merge_stats) as $k=>$subArray) { foreach ($subArray as $id=>$value) { $sumArray[$id]+=$value; } } You should do this in your query. Example SELECT SUM(field1) as field1total, SUM(field2) as field2total, SUM(field3) as field3total FROM tableName
-
How to add search tool to a pagination php script
Psycho replied to phpnewbie34's topic in PHP Coding Help
It can be done many different ways. How you do it depends on how you want it to work. 1. Normally on your pagination navigation links you will add a parameter to identify which page to show (e.g. showdata.php?page=3). You could add an additional parameter to also pass the search term. If you only have a single search field this isn't a terrible solution. But, if you add more fields, it definitely makes the URL ugly. 2. You could store the search value in a cookie. Then on each load of the pagination script check to see if there is a value in the cookie for the search string. If you want the search string to persist between sessions (perhaps the user has a preferred view) this makes sense. For pagination, I only store things in cookies such as 'preferences' such as the number of records per page. 3. Session data. This would be my preferred approach. But, no matter where you store it, the logic would work something like this: 1. Check if new search values have been sent (i.e. POST data). If so, use that data for the query and save it to wherever you are storing it. 2. If no new search data was passed, check if there is existing search criteria where you store it (Cookie, Session, GET, etc.). IF so, use it 3. If no new data was passed and no data exists in the saved location, then assume there is no search criteria. -
Better yet, you should provide some details about the DB schema and the query you are using. It would probably be more efficient to use the database for this than to post-process the DB results.
-
Exactly! There really is no good reason to make sure the primary keys are absolutely sequential. You can always get the count if you need that values. But, what you are trying to do is ill advised. If it is a PK, then you must be using that value somewhere else and you would have to update the values there was well. All this does is open you up to database corruption.
-
Either you've received some bad information or I am totally missing something. When you delete the record - it is deleted. The DB does not maintain an empty record to hold the primary key. In fact, you can verify that by trying to create a new record with that ID. If the ID wasn't removed the INSERT would fail. But, if you deleted the record it can be reused. The Database maintains an internal "counter" to specify the NEXT auto-increment ID. It doesn't maintain a history of all the ones that are used.
-
// update data $sql="UPDATE $tbl_name SET name='$name', url='$url', cat='$cat', isApproved='$isApproved' WHERE id='$id'"; Where are the variables $name, $cat, $url, $isApproved and $id defined??? Pro tip: Don't use values such as yes/no for a Boolean value. use 1/0 so you can treat them as logical TRUE / FALSE values. Then you can doa condition such as if ($isApproved) { instead of if ($isApproved == 'yes') {
-
You can't do it with HTML/CSS