Jump to content

iSE

Members
  • Posts

    33
  • Joined

  • Last visited

About iSE

  • Birthday 05/12/1986

Profile Information

  • Gender
    Male
  • Location
    Manchester, UK

iSE's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. The format of your statements must be SELECT cols FROM table WHERE field OPERAND value LOGIC field OPERAND value LOGIC field OPERAND value... So... SELECT parts_table.*, manufacturers.* FROM parts_table, manufacturers WHERE parts_table.ManufacturerID = manufacturers.ManufacturerID AND parts_table.PartNumber LIKE '%siemens%' OR parts_table.PartNumber LIKE '%6SN%' OR manufacturers.ManufacturerID = parts_table.ManufacturerID AND manufacturers.ManufacturerName LIKE '%siemens%' OR manufacturers.ManufacturerName LIKE '%6SN%' That work?
  2. Hi, I'm interested in sending the REQUEST_URI variable to a MySQL database, and retrieving the data for that particular page. The problem is that since all the URL's are dynamically changing, only part of the REQUEST_URI may be specified in the database. So for instance, the REQUEST_URI may be: /holdcroft-renault-hanley/used-cars/2/4/price-asc/ And the request_uri fields in the database will be something like: /holdcroft-renault-hanley/used-cars/ /new-cars/ /used-cars/ /holdcroft-renault-hanley/ /price-asc/ What I need to do, is to create a regex pattern so that preg_match_all will be able to get every possible combination of /(.*)/. I've been trying various different methods and patterns only to keep on getting stuck. So far I have: preg_match_all('/\/?(.*)\/?/', $_SERVER['REQUEST_URI'], $matchesArray); var_dump($matchesArray); and this gives me: array(2) { [0]=> array(2) { [0]=> string(50) "/holdcroft-renault-hanley/used-cars/2/4/price-asc/" [1]=> string(0) "" } [1]=> array(2) { [0]=> string(49) "holdcroft-renault-hanley/used-cars/2/4/price-asc/" [1]=> string(0) "" } } What I want to get, is an array filled with every possibility, so: /holdcroft-renault-hanley/used-cars/2/4/price-asc/ /holdcroft-renault-hanley/used-cars/2/4/ /holdcroft-renault-hanley/used-cars/2/ /holdcroft-renault-hanley/used-cars/ /holdcroft-renault-hanley/ /used-cars/2/4/price-asc/ /used-cars/2/4/ /used-cars/2/ /used-cars/ /2/4/price-asc/ /2/4/ /2/ /4/price-asc/ /4/ /price-asc/ are all the possible matches, how do I create a regular expression to collect these results? As always, all help is very much appreciated, and indeed passed on. Regards, iSE
  3. it should be WHERE field = value OR field = value OR field = value... so you should have WHERE field LIKE value OR field LIKE value as LIKE as an opperand.
  4. On another look through the documentation, I must have misread it the first time, because I can just use mysqli_stmt::execute to return success or failure. So your sarcastic remark actually helped me double check. Thanks
  5. Not really considering I'm using the MySQLi extension and prepared statements. Something I obviously should have stated...
  6. Ok, so fairly typical scenario... I have a form whereby the user can update both their membership and vehicle details in one form. Sometimes, the user will only make changes to their membership but not to their vehicle details. When performing an update, if there is no change to the details, the update statement will affect 0 rows even though it submitted successfully. Since for execution statements, my script checks against the number of rows affected as to whether it was successful or not, my entire site is throwing an error and undoing the previous changes as it thinks some weren't completed successfully. One option I've thought of would be to simply check for an error to report the success of an execution statement (INSERT, UPDATE, DELETE). However, I'm not entirely convinced this would be fool proof. Since this seems a fairly common thing to go through, I'm just wondering how people have gotten round this? In the past I've checked every detail against a SELECT statement and updated individual fields. This seems a huge overhead and I'm thinking there must be a better way. Thanks, iSE
  7. Thats another method, the disadvantage being that it will no longer be a self-contained system which is reusable. This approval system won't always be used, so rather a plug-in type module would be easier to maintain. To be fair, I'm going to try and figure a way to use both, I just don't want to have to go changing all my code to include it, only to change it back again on reuse. Thanks for your opinions though guys.
  8. Alright guys, not really a request for help with specific code, more help with how I should start my code... Problem... The client wants an approval system so that any actions performed through the CMS to a website, are held in a pending table to be approved or declined. Possible solution... My previous attempts for this was to use a layer between the Business Logic and Data Access Tier to save all database executions (i.e. insert, update, delete) in a table. If approved, the sql was recombined with the saved variables and executed. If declined, the record was deleted. Anybody any opinions, suggestions which could help? iSE
  9. What I was trying to do was add a dummy $_POST[$fieldName] value hoping this would force the callback method to be called. However, filter_input_array, uses a copy of the input array BEFORE the script is run, so any changes to POST don't reflect in the filter_input_array values to be filtered. I changed from filter_input_array to use filter_var_array, and used the superglobal as the input array. Works fine now. Is a bit annoying that it works this way but what can you do. Thanks for your help guys.
  10. Well that's not surprising as I can find very little documentation on the filters as it is. I add rules, forwhich is gets the filter argument to add to the filter argument array when calling: filter_input_array($this->_inputType, $this->_filterArgs); Everything works fine. The filter argument for each rule object which uses callbacks is: <?php public function getFilterArgument() { return array('filter' => FILTER_CALLBACK, 'options' => array($this, 'callbackFunction')); } ?> Then the callback function will be (for example, checking the length of a string): <?php public function callbackFunction($string) { // Check arguments if (!is_string($string)) throw new InvalidArgumentException('Form_Rule_Length::callbackFunction() expects a string as the first argument; ' . gettype($string) . ' given.'); // Check length if (isset($this->_min)) if (strlen($string) < $this->_min) return false; if (isset($this->_max)) if (strlen($string) > $this->_max) return false; // Must be valid if reached here return $string; } ?> This all works fine, when I use a callback for a file, i can get to the getFilterArgument() method, but the callback method is NEVER called on filter_input_array. iSE
  11. Hi All, I'm using the php filter functions to validate my form data. For custom filters, I'm using the FILTER_CALLBACK filter but when I'm using files, this never seems to be called? It may be that the filters are not designed to be called for files but I can't find any documentation to support that. Anybody know anything about this? iSE
  12. Hi AikenDrum, You'd probably be best creating two arrays, indexed by the common value for each (i'm guessing ID, but this could be date?) and calling from each, such as: <?php // Initialise arrays $resultsThisMonth = array(); $resultsLastMonth = array(); // Loop through first result set while ($row = mysql_fetch_array($resultArea)) { // Add row to array by using unique value, shared by both result sets, as the index $resultsThisMonth[$row['id']] = $row; } // Loop through second result set while ($row = mysql_fetch_array($resultAreaLast)) { // Add row to array by using unique value, shared by both result sets, as the index $resultsLastMonth[$row['id']] = $row; } // Loop through first array again to output HTML foreach ($resultsThisMonth as $id => $row) { echo '<input type="text" name="Size" id="Size' . $id . '" title="' . $resultsLastMonth[$id]['Size'] . '" value="' . $row['Size'] . '" /> } ?> If you don't need the full row with each ID (for instance, you just want the size), then you could use: <?php // Initialise arrays $resultsThisMonth = array(); $resultsLastMonth = array(); // Loop through first result set while ($row = mysql_fetch_array($resultArea)) { // Add row to array by using unique value, shared by both result sets, as the index $resultsThisMonth[$row['id']] = $row['Size']; } // Loop through second result set while ($row = mysql_fetch_array($resultAreaLast)) { // Add row to array by using unique value, shared by both result sets, as the index $resultsLastMonth[$row['id']] = $row['Size']; } // Loop through first array again to output HTML foreach ($resultsThisMonth as $id => $size) { echo '<input type="text" name="Size" id="Size' . $id . '" title="' . $resultsLastMonth[$id] . '" value="' . $size . '" /> } ?> I'm guessing a lot at the purpose of this, but hopefully that should help somewhat. If you're stuck approaching it one way, try going back to the beginning, and write out in plain english what it is your trying to do, then convert the plain english to php. iSE
  13. Thank you, that's exactly what I wanted
  14. Where's the $row variable coming from? When doing any programming, your best writing out the comments first to get in your head in plain english the process you want to go to... So: Create connection If connection created perform query If query success get results Loop through results... I'll give you a hand here, use... <?php while (($row = mysql_fetch_row($result)) !== false) { } ?> Show material image etc... You may want to check that mysql_fetch_row is the right command you wish to use... A handy resource we all hammer every day we're programming is http://www.php.net. Also, I'd recommend that you use MySQLi as soon as you feel comfortable as the traditional MySQL extension is being phased out Hope this helps, iSE
  15. Guys, I feel really embarrased that I'm stumped by this but unless I'm blind, I can't seem to find a thing in the php manual. How do you get the array index from a key? The problem is I have an array sorted alphabetically by their key's, each key's value is an array of information relating to the key name. However, the client want's a certain key to appear last in the list. I was going to do this by using array_slice to extract the array by the key name, but array_slice expects the key to be long not a string. <?php $dealerList = VSM::getDealershipList(); $prmDealer = array_slice($dealerList, 'KEY NAME', 1); array_push($dealerList, $prmDealer); ?>
×
×
  • 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.