Jump to content

codebyren

Members
  • Posts

    156
  • Joined

  • Last visited

Everything posted by codebyren

  1. There are many ways to do this (and probably more) as you've just discovered: 1. using in_array() after exploding by comma 2. strcmp after exploding by comma 3. array comparison after exploding by comma and then by pipe I suspect that both the first two are faster than the third. But I do recall reading another thread of yours where you suggested calculating how close the user's balls were to jackpot - in which case having each chosen ball as an array value would be useful. Also, unless this is for a ridiculously large lottery, I doubt you would notice the performance difference.
  2. You can compare arrays with comparison operators which would take the order into account: <?php $numbers_chosen = "8|18|3,18|3|8,3|8|18"; $winning_numbers = "8|18|3"; // Let's get those winning numbers into an array $winning_numbers = explode('|', $winning_numbers); $winner = false; $tickets = explode(',', $numbers_chosen); foreach ($tickets as $ticket) { $balls = explode('|', $ticket); if ($balls == $winning_numbers) $winner = true; # This is where we compare the arrays (including order) } echo ($winner) ? "We have a winner" : "Try again."; exit; ?>
  3. The problem here is that the $organised_data variable needs to be an array of associative arrays (where each associative array represents a row of data to be updated in your database). At the moment, you have organised the submitted data in such a way that there is no relationship between values. You have an array that contains: 1. An array of pickupids 2. An array of pickuplocations 3. An array of Date1s 4. An array of Date2s 5. An array of Date3s When what you need is an array of arrays that look something like: <?php // I'm assuming the pickupid shouldn't be included in the data to be updated (since you used it as your WHERE clause) $single_row = array( 'pickuplocation' => 'Something', 'Date1' => 'some date', 'Date2' => 'another date', 'Date3' => 'different date' ); ?> This is also why I suggested using the pickupid (or whatever your table's primary key is) as your array keys in your HTML form. This would make it easier to manage the submitted data and maintain relationships between the data for updating.
  4. Well, the URL parameters are being split by the presence of "&" in the URL. So, it's breaking at where &cid=130 kicks in and adding "cid" as a new URL parameter (same with &utm_source etc.). If you need to pass this kinda info in the URL, you will need to look at http://php.net/manual/en/function.urlencode.php and its urldecode counterpart.
  5. I'd say learning to use SimpleXML is quite valuable long-term but there's nothing stopping you from using it alongside you current library of choice. With your sample XML: <?php $xml = '<Result><Info><Details><Type><Who><Name key="1">This is Me</Name><Number1 key="2">18.93</Number1><Number2 key="2">20.01</Number2><Number3 key="2">15.21</Number3></Who></Type></Details></Info></Result>'; $xml = simplexml_load_string($xml); // This is not ideal for seeing attributes but gives you a good idea of the XML tree/structure // print_r($xml); // Access the first <Name> in the XML echo "The first instance of name is: ", $xml->Info->Details->Type->Who->Name[0], "<br>"; // (notice how Info->Details->Type->Who->Name matches the XML tree/structure making it pretty easy to navigate) // Access the attributes tied to the first instance of <Name> using atributes() method foreach($xml->Info->Details->Type->Who->Name[0]->attributes() as $key => $val) { echo "The key is $key and the value is $val. <br>"; } exit; ?> Hope this gets you going in the right direction...
  6. There are a lot of approaches you could take to validating the data. Something like this should do: <?php $entry = "20|10|5"; $errors = 0; $numbers = explode("|", $entry); foreach($numbers as $number) { $number = (int) $number; # cast the value as an integer if ($number < 1 OR $number > 36) $errors++; } if ($errors > 0 OR count($numbers) < 3) { echo 'No. Bad.'; } else echo 'Looking good'; ?>
  7. I'm not sure if I understand the problem completely but why not: <?php // A function that prints out a list of links function my_function($links) { $html = ''; // There might be cases when the array of links is empty if (count($links) > 0) { // Open the list $html .= '<ul>' // Add the list items foreach ($links as $link) { $html .= sprintf("<li>%s</li>", htmlspecialchars($link->name)); } // Close the list $html .= '</ul>'; } return $html # or echo $html; } ?> Then you can do something like: <?php $links = Link::find_all(); echo my_function($links); ?>
  8. Since each form field name is the same, you will only get the last row's data in the submitted form data (as you mentioned). You'll need to indicate that the form data should be handled as an array by adding [] to each form field name: <input type="text" name="pickuplocation[]"> You might also consider including the pickupid as the array key (assuming it's your DB table's primary key). It's not really necessary but it might help you process the data more easily: <input type="text" name="pickuplocation[<?php echo $row['pickupid']; ?>]"> PHP will then process the form values into an array that you can loop through: <?php $pickuplocations = $this->input->post('pickuplocation'); foreach ($pickuplocations as $key => $location) { echo "The pickup ID is $key and the location is $location"; } ?> Then once you have captured and organised each row's data (probably into a nested array with pickupids as the keys), you would need to run the DB update code in a loop: <?php foreach ($organised_data as $data) { $this->db->where('pickupid', $data['pickupid']); $this->db->update('pickup', $data); } ?> Hope this makes sense...
  9. Any reason you need to do the conversion in PHP? You could do this all in JavaScript: var date_string = "2011-01-01" ; // The date printed using PHP var d = new Date(date_string); var new_date = d.getFullYear() + ',' + d.getMonth() + ',' + d.getDate(); alert(new_date); Otherwise in PHP you could do something like: <?php $php_date = '2011-01-01'; $date_parts = explode('-', $php_date); $js_year = $date_parts[0]; $js_month = (int) $date_parts[1] - 1; // the (int) will get rid of any leading '0' $js_day = (int) $date_parts[2]; $js_date = "$js_year,$js_month,$js_day"; echo $js_date; ?>
  10. jonsjava has shown you the light. If you read the SimpleXML docs, you will see there is a way to load XML from a string directly: <?php $string = "<response><imei>123123123123111</imei><unlockcode>34343434</unlockcode></response>"; $xmlobj = simplexml_load_string($string); // Play with objects $imei = $xmlobj->imei; $unlockcode = $xmlobj->unlockcode; echo "The imei is $imei and the unlock code is $unlockcode <br />"; // or play with arrays $xml_array = (array) $xmlobj; echo "The imei is {$xml_array['imei']} and the unlock code is {$xml_array['unlockcode']}"; ?> That should get you going...
  11. I was thinking the same thing - but if the form is manipulated in any way to submit less names than items or vice versa then the numeric indices won't match up. Not sure how serious this is in the context of the application though... Something for the OP to think about anyway.
  12. I haven't used xml_parse_into_struct myself but have always read that simplexml is very fast. Add that it's really easy to use and it's a no-brainer for me. Here's other people giving simplexml the +1 on stack overflow: http://stackoverflow.com/questions/188414/best-xml-parser-for-php Hope that helps.
  13. You could use the explode() function to break the url string into an array of segments (separated by '/'): <?php $url = "http://example.com/something/more/more/1"; $url_parts = explode('/', $url); ?> Then if 'something' is found as the first segment (looks like it would be in $url_parts[3] in my example), use php's substr() function to remove the '/1' from $url if relevant.
  14. I can't see how you are building your SQL queries in the code you provided but basically you need to convert the array checkbox values into a comma separated list yourself. Something like: <?php // Assume $project_lists array has been validated and looks like this: $project_lists = array('chat', 'forums', 'tech'); // Make it into a comma separated list $project_lists_string = explode(',', $project_lists); // "chat,forums,tech" // Do SQL query with new comma-separated value now // ... ?>
  15. No, you'll need to have a look at what some of the other users suggested in response to your original question.
  16. It depends on what your safe_query() function does? If it intelligently 'escapes' the $cupID then you should be ok from an SQL injection perspective.
  17. From memory, checkboxes only appear in $_POST if something was actually checked so you can never assume that $_POST['project_list'] will always exist. Try the following to see what's going on: <?php if (isset($_POST['submit'])) { $project_lists = isset($_POST['project_list']) ? $_POST['project_list'] : array(); # this is called a ternary operator if (is_array($project_lists) && count($project_lists) > 0) { // Sweet. Do 'foreach' statement here. } else { echo "Something went wrong. Take a look at what was posted: <br />"; print_r($_POST); exit; } } ?> Hope that helps.
  18. You should start your $request_counter at 0 (not 1) since PHP's internal arrays generally (always?) start at 0 . This is probably causing your data to be off by one somewhere. That's my immediate thought anyway...
  19. Hopefully this gets you going in the right direction. The code basically spits out a form for each user and has a hidden input with the username to either approve/decline depending on which button was pressed. I hope it's easy enough to follow... <?php $fake_db_data = array(); $fake_db_data[] = array('username' => 'Superman', 'firstname' => 'Clark', 'lastname' => 'Kent', 'email' => 'superman@email.com'); $fake_db_data[] = array('username' => 'Spiderman', 'firstname' => 'Peter', 'lastname' => 'Parker', 'email' => 'spiderman@email.com'); $fake_db_data[] = array('username' => 'Batman', 'firstname' => 'Bruce', 'lastname' => 'Wayne', 'email' => 'batman@email.com'); // Process the form submission if appropriate if (isset($_POST['approve'])) { // Google "php ternary operator" if you don't understand the next line $username = isset($_POST['username']) ? (string) $_POST['username'] : FALSE; if ($username) { echo "The username to be verified was: " . htmlentities($username) . "<br />"; } } if (isset($_POST['decline'])) { // Similar to the approval process die('Not implemented (try approve).'); } ?> <?php foreach ($fake_db_data as $person): ?> <form action="" method="post"> <input type="hidden" name="username" value="<?php echo htmlentities($person['username']); ?>" /> <p> <strong>Username: </strong><?php echo htmlentities($person['username']); ?> <br /> <strong>Name: </strong><?php echo htmlentities($person['firstname']) . ' ' . htmlentities($person['lastname']); ?> <br /> <input type="submit" name="approve" value="Approve" /> <input type="submit" name="decline" value="Decline" /> </p> </form> <?php endforeach; ?>
  20. You're missing a certain parameter on the submit button: <input type="submit" name="register" id="register" value="Join!"> Without it, your form processing code doesn't recognize that the form has actually been posted since it's looking for the 'register" input: <?php if (isset($_POST['register'])) { // whatever goes here } ?> Pretty sure that's it.
  21. When you're capturing the data that the user submitted, just ignore the input if nothing was selected. For example: Print Quantity: <select name="quantity2"> <option value="">--Please Select--</option> <option value="500"></option> <option value="1000"></option> <option value="2500"></option> <option value="Other"></option> </select> You might notice the value="" on the "--Please Select--" option element. Then handle the post: <?php if (isset($_POST['quantity2']) && $_POST['quantity2'] != '') { // Add quantity to the email since it wasn't left blank } ?> Hope that puts you in the right direction.
  22. I'm not 100% sure that I understand your question but I'll give it a shot... <?php $htime = $row['htime']; # Some timestamp stored in a database $now = time(); # Current timestamp $cutoff = $now - (15*60); # The timestamp for 15 minutes ago // Check that $htime is in the past, but also not more than 15 minutes ago. if ($htime < $now && $htime > $cutoff) { echo "htime was less than 15 minutes ago..."; } ?> Hope that helps
  23. As a merchant, security is YOUR responsibility. Authorize.net has to, of course, go through its own drama to pass regular security audits but this is separate from what should concern you. In the Authorize.net AIM sample code you have there, the cardholder would be submitting their credit card details for processing via YOUR website and so the responsiblility lies with you to handle that properly. You would need to, among other things, provide an encrypted connection for when credit card data gets submitted (use an SSL certificate) and avoid storing sensitive credit card details at all costs. You should look into PCI DSS compliance (https://www.pcisecuritystandards.org/) since it will likely govern whether you will even be granted a merchant account to accept credit card payments online in the first place. Getting compliant can be quite intense and costly which is why gateways like Authorize.net provide alternative solutions (e.g. SIM - Simple Integration Method) which involve redirecting the cardholder to the Authorize.net website so that the cardholder enters their credit card info on the secure Authorize.net site and not yours. That simplifies the PCI DSS process a whole lot. So yeah, processing credit cards isn't the hard part. Jumping through hoops so that you're allowed to is...
  24. If I understand what you're asking, you could just use a nested if statement. Something like: <?php if (in_array($title, $otherTitles)): ?> <?php if ($title != 'Product Selector' && $title != 'Avon Range'): ?> <link rel="stylesheet" type="text/css" href="homepage.css"/> <?php endif; ?> <?php endif; ?>
  25. Once the content has been rendered, CodeIgniter's job is done. And since you say the href is correct when the page has been loaded, CI can't be at fault here. It sounds like you have some javascript (you mentioned jquery) that is dynamically prepending the site URL when you hover over these links. If you disable javascript in your browser you should be able to confirm this - so I'd start with that. You might want/need to use something like firefox's web developer toolbar to only disable javascript after the relevant <tbody></tbody> content has been loaded in via ajax.
×
×
  • 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.