Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Which version of postgres do you have? Google search shows that older versions of postgres could fail when making a tar pg_dump, because they needed to store the uncompressed table dump in /tmp.
  2. I'm a little confused by your question, but I think you are looking for something like this: $pg_res = pg_query($conn, "SELECT blah blah blah FROM tablename WHERE id="$id_request"); while ($row = pg_fetch_assoc($pg_res)) { var_dump($row); } var_dump() gives you a view of what's inside that $row variable. Instead you can fetch individual columns by accessing $row['column_name']
  3. UDP connections will always come back with a handle, even if the destination is inaccessible. All that you'll see is that no data comes back. That's just the way it is unfortunately. If your webhost started blocking that udp port, then the behaviour you see would be consistent with that.
  4. Making it an official extension takes a LOT of work.. I've got a family and only enough spare time to make it functional unfortunately.
  5. You could create a trigger on update which checks to see if a row is open or closed, if you want to prevent changes directly in SQL. But I think it makes more sense to check it in the software. If someone wants to add a row, first check the table to see if there are any rows that are closed and have matching project number.
  6. Ok, for your second problem, start adding more debugging statements (prints) to the battleship placement code. If you get totally stuck, post your current code along with the EXACT output, and we can most likely help you out!
  7. To fix the session_start() error, remove any blank lines before the "<?" at the top of your script. I'm taking a look at the other problem now.
  8. Can you try this: if ($tireqty <=5) $discount=0; elseif ($tireqty >=5 && $tireqty <49) $discount=0.95; elseif ($tireqty >=50 && $tireqty<=99) $discount=0.9; elseif ($tireqty >100) $discount=0.80; $totalamount = 0.00; define('TIREPRICE', 100 ); define('OILPRICE', 10); define('SPARKPRICE', 4); $totalamount = ($tireqty * TIREPRICE * $discount) + ($oilqty * OILPRICE) + ($sparkqty * SPARKPRICE); echo 'Subtotal: £'.number_format($totalamount,2).' '; $taxrate = 0.175; // local sales tax is 17.5% $totalamount = $totalamount * (1 + $taxrate); echo 'Total including tax: £'.number_format($totalamount,2).' '; What output does it give?
  9. If you have only 3 numbers, I think that's fine. If you have a large or unlimited quantity, then you might want to use a generic duplicate checking algorithm (such as putting all the numbers as keys in an associative array, checking for duplicate keys first).
  10. Show us the output of "echo $sql;" and we may be able to help
  11. Oh.. I just thought about your code's logic. It doesn't make sense. You can do it like this: $sep = ''; for ($i=1; $i<31; $i++) { ${'rg1tName'.$i}=$_POST['rg1_'.$i]; ${'rg2tName'.$i}=$_POST['rg2_'.$i]; echo $sep . "rg1_".$i. "=".${'rg1tName'.$i}; $sep = '&'; echo $sep . "rg2_".$i. "=".${'rg2tName'.$i}; } $sep will be blank for the first variable only, ensuring that you get a & in front of every subsequent variable.
  12. Using OOP eliminates the need for many globals which can be made "per object instance". An alternative to a registry class is to have a single global array storing all your globals. Then you just have to worry about not clobbering that single array. If you're keen about not polluting the namespace, you can make the "global" variable array static inside a function (but then the function itself is in the global namespace, so you haven't gained much).
  13. What happens when you try that? Any error message? Blank page?
  14. The echo sections give an error? What is the error?
  15. $session->username instead of $session->$username ? It's a good idea to print out $sql too, so you can see what query you are running. That fixes a LOT of errors.
  16. I don't see anything obviously wrong (apart from the unusual use of variables instead of an array for ${'rg1tName'.$i}. That makes me nervous, but I guess it ought to work ) Is it possible that the url is too long?
  17. It's a matter of preference. Some people like sprintf style, others like "substitution" style. These are equivalent: $sql = sprintf("SELECT user FROM users WHERE user='%s' AND number='%s'",$user, $number); $sql = "SELECT user FROM users WHERE user='$user' AND number='$number'";
  18. Functions are from traditional programming, oop uses methods You would call it like this $margin = calculate_margin($qty); Where $qty is the quantity you want to find the margin of. If you can show us your current code, we can help you modify it to do what you want.
  19. Yep, changing page to p is simple: $p = $_REQUEST['p']; if (!empty($page_mapping[$p])) { include_once($page_mapping[$p]); } Be aware that php's arrays are something quite different to arrays in other languages. In PHP, an array also acts as a hash table and a linked list, as well as a simple array. The array in the code I posted is called an "associative array", becasue it associates strings with values. Most other languages would call it a hash table. A "normal array" is just a group of items in order, such as a list of products with name and price.
  20. If you think it's too ugly or complicated, you can create a function that does the work. function calculate_margin($qty) { if ($qty < $carton_qty) { return $item_margin; } elseif ($qty < $bulk qty) { return $carton_margin; } else { return $bulk_margin; } } Then your foreach loop just has to call that function each time (the function will need the margin values available to it .. you can make those global or pass them as an argument, depending on how professional you want to be )
  21. Is it something like this you are looking for? $page_mapping = array( 'page1' => 'content/page1content.php', 'page2' => 'content/page2content.php', 'news' => 'content/news.php', ); $page = $_REQUEST['page']; if (!empty($page_mapping[$page])) { include_once($page_mapping[$page]); } There are 2 reasons I use an array to map names to pages 1. Users can only request a page that appears in your list (security) 2. You can have a different name for the filename You would call this script as http://www.mysite.com/folder/index.php?page=page2
  22. What you're suggesting looks fine. Are those thresholds and margins all in separate columns?
  23. It may be browser related. Firefox and IE have different algorithms for deciding what type a file is. Which sites give you trouble? And which version of firefox do you have? BTW, this is not really a php question.
  24. Barand, that results in team 1 playing multiple teams in the first week. I can imagine a solution where you assign team 1 vs someone they haven't played, then continue assigning the other teams vs someone they haven't played. But I am too busy to implement it. It just needs you to keep track of who has played who, and then make "random" (or rather systematic) assignments of who plays who. I think that will work, right? Or is there some situation you can get in where it will fail?
  25. How about this: <?php include("include.php"); foreach ($_POST['Checkbox'] as $Value => $ItemID){ $Quantity = mysql_real_escape_string($_POST['Quantity'][$Value]); If($Value == '' OR $Quantity == '' OR !(is_numeric($Quantity)) OR !(is_numeric($Value))){ ?> <p align="center"><br><br> <span class="NegativeMoney">There was an error!</span><br><br><br> <a href="myitems.php?choice">Back</a></p><br><br><br><br> <?php break; } }
×
×
  • 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.