Jump to content
Larry Ullman's Book Forums

Matthaus

Members
  • Posts

    15
  • Joined

  • Last visited

  • Days Won

    1

Matthaus last won the day on March 17 2011

Matthaus had the most liked content!

Matthaus's Achievements

Newbie

Newbie (1/14)

15

Reputation

  1. It's quite possible you spelled visitorid incorrectly because I did it first (yay typos!). Glad you got it working. -matthaus
  2. I would imagine the easiest way would actually be to do a three table join and join against teams twice. Something like the following would work (probably). With this join the first id is joined against the first teams table and the second id is joined against the second teams table. The key here is to alias both tables so that mysql can tell that you're joining the same table twice. Hope this helps. select date, time, visitorid, t2.name as VisitorTeamName, homeid, t1.name as HomeTeamName, stadium from schedule inner join team as t1 on t1.id = schedule.homeid inner join team as t2 on t2.id = schedule.vistorid where season='2011' and week='1';
  3. Here's an answer for mysql: http://forge.mysql.com/wiki/MySQL_Internals_File_Formats Short answer: it's complicated
  4. Try adding this flag to mysqldump. --extended-insert=false (http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_extended-insert). It will make every row have its own insert statement, but should make it more readable. Hope that helps. -matthaus
  5. Actually, the first error indicates that /temp doesn't exist on the server (or maybe isn't writable by you). Are you using any custom session settings? If not, it sounds like a php configuration problem on the server side. Is the server running windows, linux, unix? You can try other paths using session_save_path before your session_start call (http://php.net/manual/en/function.session-save-path.php). If the server is running unix/linux, I would try using /tmp or /var/tmp as the session save path. If that fails, get in contact with the sysadmin. Or, if you're the sysadmin, give us some more information about the system, and we can try to help. The second error is because the first error generates output, which will cause all kinds of header troubles. But once you resolve the first error, the second should also go away. Hope that helps. -matthaus
  6. You could also dynamically check to see if your database object is set and is a mysqli object before including the connection script. Or you could do the check in the connection script. Something like this should work: if (!isset($db_connection) || !($db_connection instanceof MySQLi)) { // Whoops, no db_connection, better set it up... require(DB_CONNECTION); } You could replace "$db_connection instanceof MySQLi" with "is_a($db_connection, 'mysqli')" or "is_object($db_connection) && get_class($db_connection) == 'mysqli'". Hope that helps. -matthaus
  7. When having trouble with javascript, I would highly recommend using a javascript debugger like firebug (http://getfirebug.com/). It lets you step through the javascript as it executes (statement by statement), monitor variables, and has a console where errors will be printed. I can't imagine debugging javascript without it. -matthaus
  8. I would use mysql's timestampdiff function (http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestampdiff). Then use registration_date as expr1 in the example, and now() as expr2. So it would be something like... $sql="DELETE FROM joinmembersarea WHERE TIMESTAMPDIFF(HOUR, registration_date, now()) >= 24"; But rather than deleting records, you could always either use the date logic when logging in, and just issue an error if they registered more than 24 hours ago, or set an active flag to false when they've expired. I just feel funny about deleting records when I don't have to. Hope that helps. -matthaus
  9. The error is because you are referencing the $_GET array, which is passed as key/value pairs in the url. So if your script doesn't end with 'filename.php?administrator=#', then the index won't be defined. But as Stuart said, administrator should be set during login from a database query and should be saved to the $_SESSION array. Side note: Using a $_GET parameter to define an administrator is very insecure. Any logged in user would just need to add "?administrator=1" to their url to become an administrator. Hope that helps. -matthaus
  10. <html> <body> <?php $test = array(); $test[] = 'one'; $test[] = 'two'; $test[] = 'three'; echo '<form action="test-array.php" method="post">'; if (isset($_POST['submitted'])){ foreach ($test AS $testItem) { printf('<textarea>%s</textarea>', $testItem); } } printf('<input type="submit" name="submit" value="Next" /> <input type="hidden" name="submitted" value="TRUE" /> </form>'); ?> </body> </html> I did make a mistake in my previous post. I was mixing html and php too liberally. The above script should work. But I think hartleysan brought up a couple of good points. First, if you don't know how a loop structure works, then you may need to do a bit more learning or reading before taking on a script that requires loops. Second, depending upon the design of the script, it may be better to have the logic in the javascript instead of php. -matthaus
  11. I think the main problem is that you never use a loop in your code. You increment $i, but only once, if the form is submitted (you also increment an $i that was set to null, which is probably a bad idea). It's not obvious what the intent is from looking at your code (whether you want one form with a bunch of textareas, or multiple forms with one textarea each. For looping over an array, there are several options. I would probably use the foreach construct that loops over each element in the array. Code would be something like... if (isset($_POST["submitted"])) { foreach($test AS $testItem) { <form action="test-array.php" method="post"> <textarea><?php echo $testItem; ?></textarea> <input type="submit" name="submit" value="Next" /> <input type="hidden" name="submitted" value="TRUE" /> </form> } } or... if (isset($_POST["submitted"])) { <form action="test-array.php" method="post"> foreach($test AS $testItem) { <textarea><?php echo $testItem; ?></textarea> } <input type="submit" name="submit" value="Next" /> <input type="hidden" name="submitted" value="TRUE" /> </form> } Depending upon what your goal for the code is. You could also use a for loop instead of a foreach, with the same effect. It would be something like for ($i = 0; $i < sizeof($test); $i++) { // do something with $test[$i] } Anyway, hope that helps. If you expect code to be looping in some way, then make sure there's a for or do/while in your code somewhere. -matthaus
  12. You don't mention a lot of crucial details. Without them it's impossible to help. Is your site on a remote webhost or being run locally? What OS is the script on? What version of PHP is being used? -matthaus
  13. If you try running the insert statement above it will fail claiming that the column count is wrong (MySQL will expect 4 columns, and you're only providing 3). You could do the above with a full insert, like... INSERT INTO 'values' (product_id, value, datetime) VALUES (SELECT product_id FROM products WHERE product_number = $prodNum AND store_id = $storeID), $value, '$datetime') But in the absence of an explicit column list, insert statements expect all columns to be present. That's why I threw the NULL in. It basically tells MySQL that "I know there should be a column here, but I don't have a value for it just now (or maybe there isn't a value for it), so just add the row anyway." Sidenote: I added backticks (``), not apostrophe/single quote (') around values because it is a MySQL keyword, and otherwise may not be recognized as a table name. In general, it's a good idea to avoid naming columns, tables, views, or keys using reserved words/keywords (words like TABLE, SELECT, VALUES, INSERT, ...). Hope that helps. -matthaus
  14. Yes, exactly. Selects queries return rows (or sets of tuples) and insert statements insert/use rows (or sets of tuples), so you can use a select in an insert statement as long as both rows (or tuples) have the same number of columns. So in both the queries I posted, there are four columns in the insert statement. In the first, the select query returns one of the columns for the insert, and in the second query, the select is finding the product_id and returning three constants (value, null, and datetime) with that result. Both should produce the same row(s). But the basic idea is that if a select query returns a row that has 4 columns of NULL, 12, 3.95, '3/16/2011', then it can be used in an insert (or other query), as the same thing as (NULL, 12, 3.95, '3/16/2011'). You can also do other fun things like copy a table with a select statement ["CREATE TABLE destinationTable (SELECT * FROM sourceTable)"]. Or if you just want the schema of a table ["CREATE TABLE destinationTable (SELECT * FROM sourceTable LIMIT 0)"]. Anyway, that's a little bit off track, but I hope it helps clear things up. Well in that case the reason I put it there was that I assumed value_id was an auto_increment column, in which case the insert would just use the next value for the column instead of the null. It would be as if you had written an explicit insert for the table, and passed 3 columns (value, product_id, and datetime) instead of all four columns. In any case, hope that helps clear things up. -matthaus
  15. Edit: Larry beat me to it. I also don't see how this is a join issue. Two tables are involved, but no join is needed for this task. Short answer is maybe, but it depends on a how the tables are defined here. If product_number (or product_number and store_id combined do) uniquely identifies an item in the products table, then yes. It would look something like this... INSERT INTO `values` VALUES (NULL, (SELECT product_id FROM products WHERE product_number = $prodNum AND store_id = $storeID), $value, '$datetime'); or INSERT INTO `values` (SELECT NULL, product_id, $value, '$datetime' FROM products WHERE product_number = $prodNum AND store_id = $storeID); Both of those should work. Hope that helps. -matthaus
×
×
  • Create New...