Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. "UPSERT" (update if exists, insert if doesn't exist) is on the todo list for postgresql, but it doesn't seem to be high priority. You can use triggers to simulate it for specific tables (eg, have your trigger check if the row exists and then insert or update accordingly)
  2. No it will only run if the query is a valid query. What it does is asks postgres to plan the query, but not to execute it. If there's a problem with the query then postgres can't plan it, and it'll give an error (pg_query() will return false). If the query is valid then you'll get a result back with some text describing how postgres would execute that query.
  3. You can execute "EXPLAIN query" in postgresql. If it succeeds then your query is valid. For example: EXPLAIN SELECT * FROM table
  4. btherl

    php sorting

    Aha. There's an issue there about the order in which things happen. A user can only select from a dropdown after the page has been displayed. Once they select from the dropdown you have two options 1. Use javascript to either sort the list or display an already sorted list 2. Have the user submit a form that tells php which list they want Option 1 is preferable from an interactive point of view, as the user doesn't have to reload the page. But option 2 does not require any javascript. I suggest you try a simpler page first. Make a page which has only a drop-down and two pieces of text, and make it so the drop-down displays one piece or the other. Once you can do that, you can modify that code to do what you want here. This is not really a postgres issue, so you might want to post again in the main PHP help forum. The reason is that you won't get much visibility here.
  5. You've got double quotes inside a double quoted string there. You can do this to make it work: echo "<table width=\"243\" cellspacing=\"0\" cellpadding=\"0\"> ... and so on A backslash in front of every double quote. Another option is to use single quotes in your html or just omit the quotes altogether (html perfectionists won't like that of course )
  6. You can use this method of argument passing. It's more verbose but that's often a good thing: function foo($args) { $bob = $args['bob']; $baz = $args['baz']; $enable_some_flag = $args['enable_some_flag']; } foo(array( 'bob' => 'bob', 'baz' => 'baz', 'enable_some_flag' => true, ));
  7. Try adding this to your code: echo "Query: $sql<br>"; A lot of problems can be solved by looking at the query your code is generating.
  8. btherl

    php sorting

    I don't think pg_fetch_array() means what you think it means. It fetches a single row of data. For example: ?php $sort_query = pg_query("SELECT * FROM projects ORDER BY title"); while ($row = pg_fetch_array($sort_query)) { $projByTitle[] = $row; }?> Now $projByTitle will be an array of rows from the query. To check what you've fetched use this code: print "<pre>"; var_dump($projByTitle); print "</pre>"; I'm not sure what your next step should be as I'm unclear on what you want to do.
  9. Yes that does look right. So it takes "squadronDB" from the $fields array and then sets a variable $squadronDB from the value $record['squadronDB'] Earlier you said that squadronDB is set correctly in the database. The first thing I would do is add this code just after $record is set: print "<pre>"; var_dump($record); print "</pre>"; die(); What this will do is dump the contents of $record and immediately terminate the script. Take a look in the output and see if 'squadronDB' is set correctly. If it IS set correctly, then the bug comes later. If it is NOT set correctly, then the bug is probably in your db query. There is something I want to clarify: $squadronNames = array( "None", "Alpha Flight", "Buckaroo Banzias", "Corsairs", "Excaliber", "Omega Gang", "Paragons", "X-MEN (Blue)", "X-MEN (Gold)", "Reservist", "Unnassigned"); echo "<td width=\"10\"> </td><td valign=\"top\"><p>" . $squadronNames[$squadronDB] . "</p></td></tr>\n"; This implies that $squadronDB is expected to be a number ranging from 0 to 1 less than the number of squadron names in that list. Does that sound right?
  10. Thanks .. hmm. So far I see nothing that sets $squadronDB. Can you look through your code to see where it is set? It may look something like this: $squadronDB = $record['squadron']; At least that's what I would expect.
  11. Thanks, that partially answers my question. To fetch data from a database you must call mysql_query(), followed by mysql_fetch_row() or a similar function. But I don't see any mysql functions before your use of $squadronNames[$squadronDB]. Can you show me where $squadronDB comes from? Also can you clarify exactly which line is not displaying correctly? (If there are many lines not working, just pinpoint one of them exactly).
  12. Is that your entire script? Where do the values for variables such as $gradeLevels come from?
  13. Parse error: parse error, unexpected T_VARIABLE, expecting ',' or ';' in /var/www/vhosts/tempforcestaffing.com/httpdocs/WA_Universal_Email/WAUE_registration_1.php on line 47 This error is worrying - did you modify this file in any way? If you did not modify it, then it's possible you have a php version different from what the Web Assist extension requires. In either case, can you show us the contents of WAUE_registration_1.php ?
  14. Try like this: <img src="<? echo $result['location']; ?>.jpg" alt="COUNTRY" width="20" height="14" />
  15. I think it's quite unlikely. If feedfile.php has no arguments, then there is nothing the user can pass in. An exception may be register_globals, so you must check that it is OFF. You can check by making a script that does this: phpinfo(); That will display your full php configuration, including register_globals. As long as register_globals is off, I can't imagine any way to attack your script. You might want to check that nothing can happen if the user puts one of your other php scripts in place of feedfile.php
  16. To be 100% sure I'd need to see the feed.php script. But if feed.php does not take any user arguments, it's most likely to be safe. Most problems come when you take data sent to you by the user and use it in the database queries. Just to confirm: feed.php is on your website, and is the only script which accesses the database The code the other webmaster gets accesses feed.php and does not have any direct access to the database Is that right?
  17. Is it possible the whois server doesn't like being spammed?
  18. I don't recommend doing that .. instead you can use tags like phpbb does. But if you really want php code in your database, you need eval()
  19. There's some documentation about timestamps here It looks like they are formatted like dates.. Does your query execute succesfully or does it return an error code?
  20. Ginger, the comparison works in that order because it's a character-by-character string comparison. Eg "2008-10-21" > "2008-05-10" PHP will compare each digit of 2008 in turn, finding all are the same. Then it will compare "-", finding it the same. Then it compares 1 with 0 (the first digit of the month), and determines that 1 is greater. Therefore "2008-10-21" > "2008-05-10". Elmas, you could make a function like this: function compare_dates($a, $b) { list($amonth, $aday, $ayear) = explode('/', $a); list($bmonth, $bday, $byear) = explode('/', $b); $a2 = "$ayear-$amonth-$aday"; $b2 = "$byear-$bmonth-$bday"; if ($a2 < $b2) return -1; if ($a2 > $b2) return 1; return 0; } $d1 = '09/25/2008'; $d2 = '09/26/2007'; if (compare_dates($d1, $d2) == 1) { print "$d2 comes before $d1\n"; } That allows you to keep your date in mdy format in your program, but still compare them correctly. Edit: compare_dates() returns 3 possible values, -1 means "d1 < d2", 0 means "d1 == d2", 1 means "d1 > d2"
  21. Yes but the limit is probably so big it doesn't matter. But .. No! But you can easily store multiple rows in one table, one for each blog entry, and have a "user" column to identify which user the row belongs to. This will probably make your life easier later than trying to store everything in one big field. Representation of data in the database and display of the data are two separate things, and you should keep them separate. You can do something like this: <? $sql = "SELECT * FROM `Character` ORDER BY `maintoonsname` ASC"; database_connected(); $result = mysql_query($sql) or die(mysql_error()); $columns = 0; while($row = mysql_fetch_array($result)) { if ($columns == 0) { # Start the table and start first row } elseif (($columns % 3) == 0) { # End a row and start a new row } # Display this entry's data (but do not start or finish any table row) $columns++; } # End last row and end table Basically that will execute the code at "End a row and start a new row" every 3 columns. That way you can put 3 items in a table row, then start a new table row. Is that what you are looking for?
  22. If you want to compare dates, constructing them like this works well: $cdate = "$cyear-$cmonth-$cday"; You can keep two representations of the date - one to use for internal calculations (in the order year-month-day) and another to display to the user (in the order month-day-year).
  23. Are you sure the data in your database is ok? My first impression is that you may have newlines embedded in your secnum column's data.
  24. Here's are the differences between the two pages: -<div style="clear:both;"></div></div> +<div style="clear:both;"></div></div><h3>Comments</h3> +<br /><br /> +<div> +<form name="login" method="POST" action="/newsingle.php"><table> +<tr><td>Username:</td><td><input type="text" name="username" value=""/></td></tr> +<tr><td>Password:</td><td><input type="password" name="password" value=""/></td></tr> +<tr><td></td><td><input type="submit" name="submit" value="Log in"/></td></tr> +<input type="hidden" name="_submit_check" value="1" /></table> +</form><script language="JavaScript"> + document.login.username.focus(); + </script><br /><br /> The newly added div does not appear to be closed. Could that be the problem?
  25. You can try this query: SELECT i.industry, i.used, u.coname FROM industry i LEFT JOIN users u ON (i.industry = u.industry) Using a left join guarantees that you will get every industry in your result, instead of just those matched in users table. The only issue you might have here is if there are multiple matching rows (or if I made a mistake in the sql ) I think the problem in your original code is that you do your echo after the main loop has finished. It should be inside the main loop. The reason it's not easy to notice is that your indenting is not consistent.
×
×
  • 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.