Jump to content


Photo

Several Questions, 1 Topic


  • Please log in to reply
10 replies to this topic

#1 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 21 May 2006 - 12:01 AM

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:

<a href="undo.php?clientID=$clientID>

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

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 May 2006 - 12:05 AM

#1 - retrieve URL passed variables from the $_GET array. Basic code as below:
<?php
// undo.php
$clientID = $_GET['clientID'];
?>

#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).
Legend has it that reading the manual never killed anyone.
My site

#3 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 21 May 2006 - 12:31 AM

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...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#4 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 21 May 2006 - 12:33 AM

[!--quoteo(post=375595:date=May 20 2006, 08:05 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 20 2006, 08:05 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
#1 - retrieve URL passed variables from the $_GET array. Basic code as below:
<?php
// undo.php
$clientID = $_GET['clientID'];
?>

#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 :).

#5 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 21 May 2006 - 12:48 AM

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?

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;

Thanks!

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 21 May 2006 - 12:48 AM

#2 - the html meta-refresh is 'unstoppable' - content is in seconds url is the filename.
<meta http-equiv="refresh" content="10;url=http://www.someplace.com/">


#4 -
$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);

#5 - just issue a query including an ORDER by whatever ASC (for ASCending)
Legend has it that reading the manual never killed anyone.
My site

#7 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 21 May 2006 - 12:54 AM

Thanks again Andy, I think that answers those questions :).

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 02:21 AM

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...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 21 May 2006 - 02:26 AM

[!--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) View Post[/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 :).

#10 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 21 May 2006 - 02:35 AM

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.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#11 DaVuLf

DaVuLf
  • Members
  • PipPipPip
  • Advanced Member
  • 124 posts

Posted 21 May 2006 - 03:36 AM

[!--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) View Post[/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 :).




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users