Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. How about SELECT table1.fielda, table1.fieldb, table2.fieldc, COUNT(table.fieldc ) FROM table1, table2 WHERE table1.fielda=table2.fielda AND table1.fieldb = 'INFO1' GROUP BY table2.fieldc You can add as many conditions as you want using AND. Mysql will choose which order to apply them in, but the results will always be identical. If you want to do filtering after grouping, you can use HAVING, but it sounds like you want to filter before grouping.
  2. Just rename the variables. You might want to adjust the formatting a little too, depending on your preferences. It doesn't look very obfuscated to me.
  3. So instead of $start_position = $start_position - $backtrack; you want something like while ($start_position > 0) { if ($content{$start_position} === '.') { # Found a dot. Probably the end of a sentence. $start_position += 1; # So let's assume the sentence starts just after the dot break; # And finish the while loop } # Otherwise, go back one letter and keep looking $start_position -= 1; } That will keep searching backwards until it finds a dot, or until it reaches the start of the string.
  4. The function call for your update query should look the same as your other queries. The best way (in my experience) to do it is like this: $update_sql = "UPDATE users SET ".ROW NAME HERE." = '".POST VALUE."' WHERE username = '".$_SESSION['username']."'"; print "About to run $update_sql<br>"; $q = &$db->query($update_sql); The key here is that you get to see your query before it's sent off to the database. That is very valuable for debugging. The way you call an update is query is identical to how you call other queries. Eg, if you use mysql_query() for your other queries, you should continue using that, instead of $db->query(). Then you should use the "affected rows" function for the interface you're using (either $db->query() or mysql_query()) to see if the update affected any rows.
  5. The problem being that "first" is not defined here, and may change if the query plan changes, or if the ordering of data as physically stored on the disk changes. It's suitable for cases where you want any value of y and you don't care which one it is. This often happens when you are joining tables.
  6. Oh I get it. $bold_words = array( 'bold', 'powerpuff', ); # Find the first word of each sentence containing a word from $bold_words # Then find the first 50 (or some other fixed number) words from that sentence # Then display each sentence, with the bold word bolded Is that the right idea?
  7. It looks good. But to combine "where" conditions you must use "and". $resultb2 = mysql_query("SELECT members.*, post.* ". "FROM members, post ". "WHERE members.mid = post.bmid AND bid='1'") or die( "Query failed: " . mysql_error()); Try that out.. I also adjusted your error message to match the function. If you still have trouble, try storing your query in a variable and printing it out to see if it looks the way it should look.
  8. Hmm.. was $sci_id set before you used it in that line? If it was not set anywhere, then you had register_globals on in php4, but off in php5. You can fix that by switching it on in php.ini, or by using $_GET['sci_id'] instead of $sci_id, giving you $sci_id = $_GET['sci_id']; $mail->mailParam["sci_id"]=$_GET[$sci_id];
  9. Currently, you have code for 1 child to enter dob? And you want to extend it so 2 or 3 children can enter dob? Is that correct? And you want to know how to store that data in the database?
  10. I'm very confused by your description. In your second sentence, you ask how to find the first letter of a bold word, and then the first letter of that sentence. How do you know that a letter is bold (or should be bold)?
  11. Can you post your entire script? $_GET works the same way in php5, so the problem is most likely somewhere else.
  12. If it displays properly in webmin, then it must be something in your script.. Are you able to track the data through the php code, and print it out at each stage? That's the usual technique I use to find out why data that is fine on one end (mysql) comes out garbled on the other end (the html output). Just statements like print "{$data['item']}<br>"; or var_dump($data); echo "<br>"; The first place to check is immediately after the data comes out of mysql. If the data displays incorrectly at that point, then you know it's either the way you are accessing mysql, or it is something to do with display of the page itself.
  13. Oops, I forgot to mention - if you're using php to do the authentication, then your script will have to print out the file as well. The files can be kept somewhere that can't be accessed via the webserver. If you simple link to the file, then someone who knows the link can simply download it directly.
  14. You can find the user's ip address in $_SERVER['REMOTE_ADDR']. If they are using a proxy server, this will be the address of the proxy server. For password authentication, you can implement this yourself in php, providing php is running as an apache module. Details are here: http://sg2.php.net/features.http-auth
  15. It looks like an encoding issue. What encoding do you use to store the names in mysql? It's likely you'll need to convert from that encoding to UTF-8. If your mysql data is UTF-8 already, then the data is getting mangled along the way somehow.
  16. $str = 'Hello everyone. Welcome to class. I hope you\'re all smart enough not to be dumb.'; $str_pieces = explode('.', $str); $str_pieces = array_slice($str_pieces, 0, 2); $new_str = join('.', $str_pieces) . '.'; print "$str => $new_str\n"; That's the explode/join technique. You can also use regular expressions.
  17. You can create new inputs on a page using javascript.. i'm unsure of the details however.
  18. A standard technique is $price = 18.50112; # Too many digits! $price = round($price * 100.0) / 100.0; The idea is 18.50112 * 100 = 1850.112 round(1850.112) = 1850 1850 / 100 = 18.50
  19. Please tell us 1. What you did (eg, typed data into form and clicked submit) 2. What happened (eg, saw the message "Error in mysql query!") 3. What you expected to happen (eg, I should have seen "Your order was submitted successfully")
  20. That's interesting.. The session variable should NOT be set when going from page 1 to page 2. It gets set by page 3. So that is probably a left-over session from earlier. You can make a script that calls session_destroy() to clear out the data before you do each lot of testing. My guess is that the session variable is unset by the code in page 3, because that's the only code which could do it. Can you try checking its value both before and after the code that sets $_SESSION['comic_id'], to see if it's there that it gets changed? Regarding the $_POST['comic_id'], that will only be set if you submit comic_id in a form. It's expected that it will not be set if you follow a standard "a href" link.
  21. Can you show your group by attempt? It basically depends on what condition you want your rows to be distinct by. If you want only one row for each Block_Batch_ID, and you don't care which row it is, then use "GROUP BY Block_Batch_ID" and you will get what you're looking for.
  22. I'm a bit confused by your terminology. By "table window", do you mean a particular table in the html, such as a large table in the center of the page? An example of a website which does what you want would help.
  23. I think the problem is that you use $_POST['comic_id'] on page 2. This is fine when page 2 is accessed after submissions of page 1, but not when it is accessed from page 3's "Go back". So you need to check if $_POST['comic_id'] or $_SESSION['comic_id'] has the data you want, or you can check how you were called. You could do: if (!empty($_POST['comic_id'])) { $comic_id = $_POST['comic_id']; } elseif (!empty($_SESSION['comic_id'])) { $comic_id = $_SESSION['comic_id']; } else { # No comic_id from any source } That will take post data in priority over session data. I'm also suspicious of your use of $_SESSION at the bottom of page 2. It looks like the session data is only set in page 3, so that data would be blank if going directly from page 1 (did you clear your session data regularly while testing?)
  24. Did you run 'script.php' from crontab, or 'php script.php' ?
×
×
  • 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.