Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Or, rather than startng/exiting quoted strings multiple times: fwrite($fp, "{$_SERVER['REMOTE_ADDR']}{$_SESSION["sess_name"]} {$dateTime}\r\n");
  2. That is my preferred approach. Then you never need to worry about a PHP error displaying the contents of the page or accidentally deleting an htaccess file, etc.
  3. Sure it is. If you received an error you might want to check which version of MySQL you are using. REGEXP was apparently introduced with ver. 5.1. Of course this assumes that you don't literally have a table named "table". If you do,then you need to enclose the table name in backquotes. SELECT * FROM `table` WHERE name REGEXP '^[0-9]'
  4. A better solution is to just put your include files in a non-web accessible folder. But, yes you could do that, or just use any variable along with isset()
  5. Exactly what did you change? The code you last posted still puts the ID into the OPTION tags not the SELECT tag. You want to get the value of the "selected" option. Your select list should look somethig like what I posted at the end of my previous post. You also didn't fix the errant backslashes in your code. You were using single quotes to define the option tags but using backslashes before the double-quotes. Plus, as I stated previously the values you are using don't look right to me. Is there some reason you are setting the values as "order.html?rsTown='.$row['rsTown'].'" ? I would think you just want the value and not the "order.html?rsTown=". As you have it that whole thing is going to be sent in your ajax search request. Try creating your select list like this. $display_string .= "<select name=\"town\" id=\"town\" onChange=\"ajaxFunction();\" class=\"textbox\">\n"; $display_string .= "<option value=\"\">Search by Town...</option>\n"; while($row = mysql_fetch_array($qry_result)) { $display_string .= "<option value=\"{$row['rsTown']}\" onclick=\"\">{$row['rsTown']} ({$row['PubCount']})</option>\n"; } $display_string .= "</select>\n"; Then, for the time being, add the following line indicated below to your AJAX function for debugging purposes: var name = document.getElementById('name').value; var county = document.getElementById('county').value; var town = document.getElementById('town').value; var queryString = "?name=" + name + "&county=" + county + "&town=" + town; //Add the following line alert('Query String: ' + queryString); townRequest.open("GET", "http://www.mypubspace.com/dashtest/pubs.php" + queryString, true); townRequest.send(null); That will allow you to determine if the correct values are being sent
  6. Using Firebug, I can see that in the dynamically created lists you are setting the ID in the OPTIONS not the SELECT tag. That is incorrect. The Select tag is the object with a value. Plus, you give all the options the same ID. This is also incorrect. You cannot give mutliple objects the same ID in an HTML page. Your code <form action="" method="post" name="form3"> <select class="textbox" onchange="MM_jumpMenu('parent',this,0)" name="menu2"> <option value="">Search by Town...</option> <option id="\"town\"" onclick="\"ajaxFunction()\"" value="order.html?rsTown=Abbots Langley">Abbots Langley (</option> <option id="\"town\"" onclick="\"ajaxFunction()\"" value="order.html?rsTown=Aberaeron">Aberaeron (4)</option> ... First off there is a literal backslash in the code - not an escape character. Second, the values look to be a partial URL not just the value of the town. Not sure how you are using that value, but I would think it is incorrect. I don't know what the purpose is of the MM_jumpMenu function, looks like it is trying to change the displayed page. BUt, you have the onclick in the options trying to run the query. I think this is how that code should look for your purposes (But I would still suggest the solution I first proposed above) <form action="" method="post" name="form3"> <select class="textbox" onchange="ajaxFunction()" id="town" name="town"> <option value="All">Search by Town...</option> <option value="Abbots Langley">Abbots Langley (</option> <option value="Aberaeron">Aberaeron (4)</option> ...
  7. One thing that sticks out is the fact that you are putting the select lists for the town and counties BEFORE the opening form tag, so they are not included in the Form fields. But, since in the main request you are accessing data based upon the ID, that shouldn't matter. But, for good coding standards you should put the fields within the form. In the main ajax request you are trying to acces the town/county value using var county = document.getElementById('county').value; var town = document.getElementById('town').value; But, those fields do not exist when the page loads and you are creating them dynamically. So, I don't know if you have referenced them correctly or not. But, I have seen problems where javascript has problems referencing values from dynamically created fields. Here is what I would do: Create the page so that the Town and County select lists are always generated when the page loads (and included in the form). Plus, make the first value in both lists "All" and make the display property of both as hidden. Then instead of using javascript to populate the lists, use JS to display/hide the list (be sure to set the value to "All" when hiding the lists. Then on your main AJAX call you will always be sending the Town/County value. Of course, if that value is ALL it will not affect the results.
  8. It seems the forum code did not create it correctly, just coopy/paste the lik and it will work.
  9. explode() can be problematic since there may be instances of multiple concurrent spaces. In those instances you will get less than the 90 words you are looking for. However, the solution to that (splitting by any instances of one or more spaces) has a problem where you will remove the duplicate spaces, but that may be wanted. Here is a function I use that will treat multiple spaces as a single break between words, and they are replaced as a single space in the output. function wordSlice( $input, $offset, $length=NULL) { $words = preg_split('%[\s,]+%', trim($input)); $words = ($length) ? array_slice($words, $offset, $length) : array_slice($words, $offset); $output = implode(' ', $words); return $output; } To get a string of the first 90 words you would use like so echo wordSlice( $content, 0, 90) That one doesn't add ellipses if the string is truncated, but it could be easily added. But, I do have a different function that will truncate a string based upon the number of characters and add an ellipse if needed. But, if the length falls in the middle of a word it will truncate additional characters so it does not cut a word. function truncateString($string, $length, $ellipse='...') { if (strlen($string) <= $length) { return $string; } return array_shift(explode("\n", wordwrap($string, $length))) . $ellipse; }
  10. The error conditions are exactly what YOU set them to. Without specifying the input, the expected output and the actual output I can't say whether your error conditions are correct or not. But...I think I know what the error may be. I just noticed that you are defining the variables $itemname and $itemurl after modifying the input with mysql_real_escape_string()! Since I assume the url has slashes in the input they are likely getting escaped for into the database. But, you are trying to compare escaped input from the user to the unescaped value from the database and they are not equal. To solve that define one variable for the user input and a different, escaped value, one for the query. Then compare the results of the query to the user input - not the escaped value. Also, your list of conditions for errors has no final "ELSE" condition. It is possible that the "good" condition is not met, yet none of the current bad conditions are met either. I'd put a final else condition with "bad0" just in case those erros ever occur. if (isset($_POST['submitmenuitem'])) { $menuid = (int) $_POST['menuid']; $itemname = trim($_POST['itemname']); $itemnameSQL = mysqli_real_escape_string($dbc, $itemname); $itemurl = trim($_POST['itemurl']); $itemurlSQL = mysqli_real_escape_string($dbc, $_POST['itemurl']); $sortorder = (int) $_POST['sortorder']; $contentpage = (int) $_POST['contentpage']; $newscategory = (int) $_POST['newscategory']; $application = (int) $_POST['application']; $query = "SELECT * FROM `menuitems` WHERE (`itemname` = '{$itemnameSQL}')\n"; $query .= (!empty($itemurl)) ? " OR `itemurl` = '{$itemurlSQL}'" : ''; $query .= (!empty($contentpage)) ? " OR `contentpage_id` = '{$contentpage}'" : ''; $query .= (!empty($application)) ? " OR `application_id` = '{$application}'" : ''; $query .= (!empty($newscategory)) ? " OR `newscategory_id` = '{$newscategory}'" : ''; $query .= " AND `menu_id` = '{$menuid}'"; $result = mysqli_query ( $dbc, $query ); // Run The Query if (mysqli_num_rows($result) == 0) { $query = "INSERT INTO `menuitems` (menu_id, itemname, itemurl, sortorder, contentpage_id, newscategory_id, application_id, creator_id, datecreated, enabled) VALUES ('{$menuid}', '{$itemname}', '{$itemurl}', '{$sortorder}', '{$contentpage}', '{$newscategory}', '{$application}', 1, NOW(), 0)"; mysqli_query($dbc, $query); $result = "good"; } else { $row = mysqli_fetch_array($result); if (($row['itemname'] == $itemname) && ($row['newscategory_id'] == $newscategory)) $result = 'bad9'; elseif (($row['itemname'] == $itemname) && ($row['application_id'] == $application)) $result = 'bad8'; elseif (($row['itemname'] == $itemname) && ($row['contentpage_id'] == $contentpage)) $result = 'bad7'; elseif (($row['itemname'] == $itemname) && ($row['itemurl'] == $itemurl)) $result = 'bad6'; elseif ($row['newscategory_id'] == $newscategory) $result = 'bad5'; elseif ($row['application_id'] == $application) $result = 'bad4'; elseif ($row['contentpage_id'] == $contentpage) $result = 'bad3'; elseif ($row['itemurl'] == $itemurl) $result = 'bad2'; elseif ($row['itemname'] == $itemname) $result = 'bad1'; else $result = 'bad0'; } }
  11. "Two rows wide"? A row is a row. You mean you want two COLUMNS per row. the code I provided should still do what you want - just modify the display function to display the records in multiple columns. //Function to display each category with the subcats function createTable($categoryName, $subCatAry, $subCatCols=1) { //Prepare the subcategory array if($subCatCols==1) { //Modify to a into multidimensional array with one element $subCatCells = array(0 => $subCatAry); } else { //Break array into multidimensional parts $subCatCells = array_chunk($subCatAry, ceil(count($subCatAry)/$subCatCols) ); } //Output the results echo "<table>\n"; echo "<tr><th colspan=\"$subCatCols\">{$categoryName}</th></tr>\n"; foreach($subCatCells as $subCatCell) { echo "<td>" . implode("<br />", $subCatCell). "</td>\n"; } echo "</table>\n"; }
  12. Huh? According to that statement you want any value that isn't already 0 to be changed to 0 - in other words you want all the values to be 0. I will try to provide help based upon what I *think* you are asking for. I think you are saying that you want the query to only be run against those individual four fields where a seach value has been passed in the POST data. In that case, you should check the POST values and use those to dynamically create the query. The sample code below assumes that the values will be empty if you don't want them checked - as opposed to not being set. Use the following to generate your query: //Prepare POST data $menuid = mysqli_real_escape_string($dbc, trim($_POST['menuid'])); $itemname = mysqli_real_escape_string($dbc, trim($_POST['itemname'])); $sortorder = mysqli_real_escape_string($dbc, trim($_POST['sortorder'])); $itemurl = mysqli_real_escape_string($dbc, trim($_POST['itemurl'])); $contentpage = mysqli_real_escape_string($dbc, trim($_POST['contentpage'])); $newscategory = mysqli_real_escape_string($dbc, trim($_POST['newscategory'])); $application = mysqli_real_escape_string($dbc, trim($_POST['application'])); //Create dynamic query $query = "SELECT * FROM `menuitems` WHERE (`itemname` = '{$itemname}')\n"; $query .= (!empty($itemurl)) ? " OR `itemurl` = '{$itemurl}'" : ''; $query .= (!empty($itemurl)) ? " OR `contentpage_id` = '{$contentpage}'" : ''; $query .= (!empty($itemurl)) ? " OR `application_id` = '{$application}'" : ''; $query .= (!empty($itemurl)) ? " OR `newscategory_id` = '{$newscategory}'" : ''; $query .= " AND `menu_id` = '{$menuid}'"; $result = mysqli_query ( $dbc, $query ); // Run The Query
  13. It's late so I am not going to read through all of your code. But, I think you are making this more difficult than it needs to be. First, and foremost, you only need to run one query with a JOIN to get the data you need. Running queries in loops is a bad idea. You don't state "how" you want to select if there are two rows for the subcategories or not - either specifically set or dynamically determined. Here is some pseudo code to help you on your way //Function to display each category with the subcats function createTable($categoryName, $subCatAry, $subCatRows=1) { echo "<table>\n"; echo "<tr><th>{$categoryName}</th></tr>\n"; if($subCatRows==1) { //Display subcategories in one row echo "<td>" . implode(', ', $subCatAry) . "</td>\n"; } else { //Display subcategories in multiple rows $subCatAry = array_chunk($subCatAry, ceil(count($subCatAry)/$subCatRows) ); foreach($subCatAry as $subCatRow) { echo "<td>" . implode(', ', $subCatRow). "</td>\n"; } } echo "</table>\n"; } //Create and run query $query = "SELECT c.catid, c.catname, sc.subcatid, sc.subcatname FROM $t_cats as c JOIN $t_subcats as sc ON c.catid = sc.catid WHERE c.enabled = '1' AND sc.enabled = '1' $sortcatsql"; $result = mysql_query($query); //Process the results $category = false; while($row = mysql_fetch_assoc($result)) { //Check for new category if($category != $row['catname']) { //New category if($category!==false) { //Display last category data createTable($category, $subCats2); } $subCats = array(); $category = $row['catname']; } $subCats[] = $row['subcatname']; } //Display last categoiry data createTable($category, $subCats2);
  14. Also, for the sake of readability, you could always rewrite all those elseif statements as a switch switch(true) { case (($row['itemname'] == $itemname) && ($row['newscategory_id'] == $newscategory)): $result = 'bad9'; break; case (($row['itemname'] == $itemname) && ($row['application_id'] == $application)): $result = 'bad8'; break; case (($row['itemname'] == $itemname) && ($row['contentpage_id'] == $contentpage)): $result = 'bad7'; break; case (($row['itemname'] == $itemname) && ($row['itemurl'] == $itemurl)): $result = 'bad6'; break; case ($row['newscategory_id'] == $newscategory): $result = 'bad5'; break; case ($row['application_id'] == $application): $result = 'bad4'; break; case ($row['contentpage_id'] == $contentpage): $result = 'bad3'; break; case ($row['itemurl'] == $itemurl): $result = 'bad2'; break; case ($row['itemname'] == $itemname): $result = 'bad1'; break; } Although, if it were my code I would use a bitwise operator for the return value. Have each bit represent a different error condition (e.g. ($row['itemname'] == $itemname) could be bit in position 1) and set each bit to true if that error condition is met. The value would equal 0 if there were no errors, otherwise you would have a bitwise number to pass that can be used to determine all of the error conditions As it is right now, you have no specific error condition for something such as $row['itemname'] == $itemname) && $row['newscategory_id'] == $newscategory && $row['application_id'] == $application
  15. To be honest I'm not really following you code. Although it is apprently used for an AJAX request - which would have been helpful to know in your original post. Anyway, from what I seem to understand you want that script to return just one value; either "good", "badX" or the sort order variable, correct? If that is the case, then I think there is a simple solution. Instead of directly echoing the output in those specific places set an output variable (e.g. $result) and echo the output at the end. So, you will first define $result as the $sortorder variable. But, if you reach a condition where you want "good" or one of the "badX" responses you will redefine $result as that value. Then when the script gets to the end just echo $result. So, if the conditions for good or bad responses are never met then the script will output the sort order. Is that what you want? <?php // Include the database page require ('../inc/dbconfig.php'); if ( isset( $_POST['menuid'] ) ) { $menuid = (int) $_POST['menuid']; $query = "SELECT COUNT(sortorder) AS numOrder FROM `menuitems` WHERE `menu_id` = '{$menuid}'"; $result = mysqli_query ($dbc, $query); $row = mysqli_fetch_assoc( $result ); $sortorder = $row[ 'numOrder' ] + 1; $result = $sortorder; } if (isset($_POST['submitmenuitem'])) { $menuid = mysqli_real_escape_string($dbc, $_POST['menuid']); $itemname = mysqli_real_escape_string($dbc, $_POST['itemname']); $itemurl = mysqli_real_escape_string($dbc, $_POST['itemurl']); $sortorder = mysqli_real_escape_string($dbc, $_POST['sortorder']); $contentpage = mysqli_real_escape_string($dbc, $_POST['contentpage']); $newscategory = mysqli_real_escape_string($dbc, $_POST['newscategory']); $application = mysqli_real_escape_string($dbc, $_POST['application']); $query = "SELECT * FROM `menuitems` WHERE (`itemname` = '{$itemname}') OR (`itemurl` = '{$itemurl}') OR (`contentpage_id` = '{$contentpage}') OR (`application_id` = '{$application}') OR (`newscategory_id` = '{$newscategory}') AND `menu_id` = '{$menuid}'"; $result = mysqli_query ( $dbc, $query ); // Run The Query if (mysqli_num_rows($result) == 0) { $query = "INSERT INTO `menuitems` (menu_id, itemname, itemurl, sortorder, contentpage_id, newscategory_id, application_id, creator_id, datecreated, enabled) VALUES ('{$menuid}, {$itemname}, {$itemurl}, {$sortorder}, {$contentpage}', '{$newscategory}, {$application}, 1, NOW(), 0)"; mysqli_query($dbc, $query); $result = "good"; } else { $row = mysqli_fetch_array($result); if (($row['itemname'] == $itemname) && ($row['newscategory_id'] == $newscategory)) $result = 'bad9'; elseif (($row['itemname'] == $itemname) && ($row['application_id'] == $application)) $result = 'bad8'; elseif (($row['itemname'] == $itemname) && ($row['contentpage_id'] == $contentpage)) $result = 'bad7'; elseif (($row['itemname'] == $itemname) && ($row['itemurl'] == $itemurl)) $result = 'bad6'; elseif ($row['newscategory_id'] == $newscategory) $result = 'bad5'; elseif ($row['application_id'] == $application) $result = 'bad4'; elseif ($row['contentpage_id'] == $contentpage) $result = 'bad3'; elseif ($row['itemurl'] == $itemurl) $result = 'bad2'; elseif ($row['itemname'] == $itemname) $result = 'bad1'; } } if (isset($_POST['deletemenuitem'])) { $menuitemID = (int)$_POST['menuitemID']; $query = "UPDATE `menuitems` SET `enabled` = '1' WHERE `id` = '".$menuitemID."' LIMIT 1"; mysqli_query($dbc,$query); } //Output the result echo $result; ?>
  16. It depends. Since you are setting the value to 1/0 are you wanting the value of $c to be a boolean value or are you going to use the numerical values of 0 and 1 in calculaions? If you are only wanting to set $c to a boolean then it is unnecessary to create a condition such as "if this condition is true set this value to true otherwise set this value to false". Instead, just create a line such as "set this value to this condition", such as: $c = ($a == $b);
  17. It "looks" ok, but I can't tell you if it is what I would do or if there are any specific problems because I don not understand all the relationships of your data and the specific needs of the user. To do that would take a LOT of time. The only thing that doesn't make sense to me is in the table_products you have two fields "id" and "product_id" - those look like they would be for the same purpose. Again, this comes down to analyzing the specific requirements for the application. Typically, in a situation with estimates which may become jobs I would have a table for the estimate records (which of course are tied to various other tables for materials, labor, etc) and then I would have a separate table for the job tickets. The job tickets table would have a reference back to the estimate record (or records if appropriate for the application). The job ticket could also be used to track actual materials/labor which is helpful during the billing process and to validate the accuracy of the estimating logic. Again, depends on the needs of the user. But, I would "assume" that you want to store the calculated values (not the formulas) with the estimate. That way you will know what was presented to the customer. Depending on the needs you could add a "recaculate" feature to recalculate the estimate based upon any changes to the formulas. But, if so, I would again assume that would create a new estimate so you don't lose the history of previous estimates. I would put that in a separate table for "additionals". You would store a separate record for each "additional" charge and link each back to the respective estimate. I would think that they are logically 4 different products. But, if the user wants to be able to select "posts" and then have a sub-selection for the post type, then you would need to figure out how best to achive that. The easiest method is to simply treat them as separate products. Not sure here. Again, making some assumptions, I would think that the POs are specific to certain vendors and that specific products will always be purchased from specific vendors. So, the products would need a reference to the vendor that the product will be purchased from (in a vendor table). For the purchase orders I would have at least two tables. The main PO table would include an ID back to the vendor along with non-duplicative data about the PO (e.g. date). For the line item details of the PO (i.e. the materials) I would use a second table which would have (at a minimum) a reference to the PO ID, the material ID, the material QTY, the material unit cost. You would need to store the material unit cost in this table even though it should already be in the material table because if the material cost changes you still need to know what the cost was on previous POs.
  18. The fact of the matter is you can store your data anywhere you choose: sessions, cookies, database, flatfile, etc. It all depends on how you want to use that data: how much data will there be, do you need multiple tables of data, does the data need to persist, etc. How you use the data will determine the best format of where it should be stored. In fact, I would say, it doesn't matter where you store the data for your game at all. If you di it right, you can change where it is stored at any time.
  19. Not to mention the fact that all the array functions are right there in the manual plain as day. It's not like you did anything extraordinary to derserve his love. Kind of cheapens the whole "love" thing IMO.
  20. $html = preg_replace("/<p>.*?<\/div>/is", "", $html);
  21. It's been about three hours since your last post and the one before. Are you saying you have read through the tutorials that were provided and don't understand them? If so, what - specifically - do you not understand?
  22. To add to Maq's explanation: The six lines of code following the IF statement is interpreted as a single line of code to the PHP interpreter. It is a single function call with one parameter as an array that is defined over multiple lines. The semi-colon at the end is what tells the parser that the line is done - not the line breaks.
  23. I believe what he is trying to achive is to have records displayed in a grid where each row in the grid will display three records - not one record per row with three fields. So, row one displayes records 1-3, row 2 displayes records 4-6, etc. Here is some pseudo code //Variable to determine number of records in a row $recordsPerRow = 3; $query = "SELECT * FROM table"; $result = mysql_query($query); $recIdx = 0; while($row = mysql_fetch_assoc($result)) { //Increment the record index $recIdx++; //Open new row if first record in row if($recIdx%$recordsPerRow==1) { echo "<tr>\n"; } //Display the record echo "<td>{$row['somevalue']}</td>\n"; //Close row if last record in row if($recIdx%$recordsPerRow==0) { echo "</tr>\n"; } } //Close last row if not already done if($recIdx%$recordsPerRow!=0) { echo "</tr>\n"; }
  24. True, I forgot about that. You can also use count($_GET)
  25. Well technically index.php?category is still the index.php page. In any case, you could checkif $_GET is set if(!isset($_GET)) { //No URL parameters set show index.php page content } else { //Some $_GET parameters are set, show appropirate content }
×
×
  • 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.