DaVuLf Posted May 21, 2006 Share Posted May 21, 2006 As the title denotes, I've got a couple of quickies:1. How do you pass variables between php files? Suppose I want to have an 'undo' function to undo the last transaction. I set a link with:[code]<a href="undo.php?clientID=$clientID>[/code]Is that right? If so, can I just access the variable from undo.php with no difficulties?2. How would I code a .php file to refresh itself every minute? I want it to automatically update so that I can see team standings (in order of account balance). 3. Suppose I have a form called input.html, which posts to input.php, which inserts data into a table (or several tables). Is it possible that two people from different locations can access both of these files simultaneously? So that people can submit the form on different PC's, and the mySql will still work properly?Thanks for the help,DaVuLf Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/ Share on other sites More sharing options...
AndyB Posted May 21, 2006 Share Posted May 21, 2006 #1 - retrieve URL passed variables from the $_GET array. Basic code as below:[code]<?php// undo.php$clientID = $_GET['clientID'];?>[/code]#2 - that's a client-side question, and the answer is to use the HTML meta-refresh tag (in the HEAD of the generated html file).#3 - good question. Simultaneously (as in at the same instant)? I hope a MySQL guru spots this thread (which might be a good reason to actually post that specific query in the MySQL forum). Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37518 Share on other sites More sharing options...
litebearer Posted May 21, 2006 Share Posted May 21, 2006 As to #3.[a href=\"http://tecfa.unige.ch/guides/mysql/man/manuel_LOCK_TABLES.html#LOCK_TABLES\" target=\"_blank\"]http://tecfa.unige.ch/guides/mysql/man/man...tml#LOCK_TABLES[/a][!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Normally, you don't have to lock tables, as all single UPDATE statements are atomic; no other thread can interfere with any other currently executing SQL statement. There are a few cases when you would like to lock tables anyway: If you are going to run many operations on a bunch of tables, it's much faster to lock the tables you are going to use. The downside is, of course, that no other thread can update a READ-locked table and no other thread can read a WRITE-locked table. MySQL doesn't support a transaction environment, so you must use LOCK TABLES if you want to ensure that no other thread comes between a SELECT and an UPDATE. The example shown below requires LOCK TABLES in order to...[/quote]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37525 Share on other sites More sharing options...
DaVuLf Posted May 21, 2006 Author Share Posted May 21, 2006 [!--quoteo(post=375595:date=May 20 2006, 08:05 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 20 2006, 08:05 PM) [snapback]375595[/snapback][/div][div class=\'quotemain\'][!--quotec--]#1 - retrieve URL passed variables from the $_GET array. Basic code as below:[code]<?php// undo.php$clientID = $_GET['clientID'];?>[/code]#2 - that's a client-side question, and the answer is to use the HTML meta-refresh tag (in the HEAD of the generated html file).#3 - good question. Simultaneously (as in at the same instant)? I hope a MySQL guru spots this thread (which might be a good reason to actually post that specific query in the MySQL forum).[/quote]Thanks for the answers. About #3, I was just worried about posting too many topics at once and spamming. I figure most people using php understand more than I do about mySql, so I'd rather keep it concise and post one topic instead of many. As for #2, I don't want the client to be able to stop this from refreshing, he cannot click on 'stop' or anything else. It is imperative that it refreshes and nothing should be able to stop it.#4 (another probably mySql question) - What php code would you use to Modify a fireld in a table. I want to say 'MODIFY balance WHERE id = $clientID;', effectively replacing the old balance with the new. #5 - If I query the new table that I just made in #4, how would I retrieve the data, but sorted ascending? (I think this is the hardest SQL question I've asked... If nobody can help, I'll concede to moving this thread to mySQL help.) Thanks again guys :). Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37527 Share on other sites More sharing options...
DaVuLf Posted May 21, 2006 Author Share Posted May 21, 2006 Lite, I hadn't seen your reply. Here is what I understand from that... It's best in my situation to lock tables so that people can be 'queued' for their actions (ie, they get set next in line to access) so that my rows don't fall out of sync. Now, how would I put this in php?[code]mysql> LOCK TABLES trans READ, customer WRITE;mysql> select sum(value) from trans where customer_id= some_id;mysql> update customer set total_value=sum_from_previous_statement where customer_id=some_id;mysql> UNLOCK TABLES;[/code]Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37531 Share on other sites More sharing options...
AndyB Posted May 21, 2006 Share Posted May 21, 2006 #2 - the html meta-refresh is 'unstoppable' - content is in seconds url is the filename.[code]<meta http-equiv="refresh" content="10;url=http://www.someplace.com/">[/code] #4 - [code]$query = "UPDATE tablename SET somefield, someotherfield VALUES ('$abc', '$xyz') WHERE something = '$somethingelse'";$result = mysql_query($query) or die("Error ". mysql_error(). " <br>with query ". $query);[/code]#5 - just issue a query including an ORDER by whatever ASC (for ASCending) Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37532 Share on other sites More sharing options...
DaVuLf Posted May 21, 2006 Author Share Posted May 21, 2006 Thanks again Andy, I think that answers those questions :). Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37534 Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 You could also setup a cronjob to execute the query every minute, in a seperate .php file. This might actually be a preferred method over refreshing the page every minute, as that tends to get annoying, from the user side. But the downside is that even though the info is being updated, it won't actually appear updated in the user's webbrowser unless they click refresh. But you could also go learn some ajax to have it auto update in the browser without refreshing the whole page... I guess it just kinda depends on your project requirements... Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37551 Share on other sites More sharing options...
DaVuLf Posted May 21, 2006 Author Share Posted May 21, 2006 [!--quoteo(post=375629:date=May 20 2006, 10:21 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 20 2006, 10:21 PM) [snapback]375629[/snapback][/div][div class=\'quotemain\'][!--quotec--]I guess it just kinda depends on your project requirements...[/quote]Thanks for the info Crayon. The thing about this project is it is for a club of mine on campus, for free. This means that I'm not spending any money on it, and it doesn't need to be super sophisticated earlier. I think we'll be able to deal with the page refresh :). Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37552 Share on other sites More sharing options...
.josh Posted May 21, 2006 Share Posted May 21, 2006 well i wouldn't call a cron job extremely sophisticated.. maybe the ajax part. but then, maybe i only consider ajax to be sophisticated cuz i haven't gotten around to learning it yet [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /] no matter, choose the simplest method that works for you. can't go wrong there. Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37556 Share on other sites More sharing options...
DaVuLf Posted May 21, 2006 Author Share Posted May 21, 2006 [!--quoteo(post=375634:date=May 20 2006, 10:35 PM:name=Crayon Violent)--][div class=\'quotetop\']QUOTE(Crayon Violent @ May 20 2006, 10:35 PM) [snapback]375634[/snapback][/div][div class=\'quotemain\'][!--quotec--]no matter, choose the simplest method that works for you. can't go wrong there.[/quote]Yea. The whole ajax thing scared me away from that idea. I'm just learning php and mysql (with help from all of you!), so I'm not much into learning another language right now. Maybe I'll think about it later :). Quote Link to comment https://forums.phpfreaks.com/topic/10088-several-questions-1-topic/#findComment-37567 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.