| | |||||
| ||||||||
| Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics. |
![]() |
| | LinkBack | Thread Tools |
| | THREAD STARTER #1 (permalink) |
| NamePros Regular Join Date: May 2008
Posts: 248
![]() ![]() | |
| |
| | #2 (permalink) |
| NamePros Member Join Date: Sep 2006
Posts: 99
![]() ![]() | It almost looks like a browser caching issue. You could try something like... Code: <?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
?> ????: NamePros.com http://www.namepros.com/showthread.php?t=483401 Also (But not related to the issue at hand), the site is difficult to navigate because it cuts off about 50 pixels on the right-hand side. I can scroll over, but some people might not be so intelligent. Bruce |
| |
| | THREAD STARTER #3 (permalink) |
| NamePros Regular Join Date: May 2008
Posts: 248
![]() ![]() | Hmm. I might have to pick a different theme or fix this one. I've never had that problem before, and I've seen the site both on IE and firefox2.0. What browser are you using? Thanks - I'll try that trick. I do figure it has something to do with the caching since various other non-updating issues occur with graphics. I currently have firefox set to delete the cache upon exit, but I guess that doesn't really fix the problem for others (although it isn't a problem as long as I don't want to change anything - lol). Just tried it. Unfortunately, it didn't fix the issue. I wonder if it's a drupal thing? PHP Code: My problem wouldn't have to do with echoing everything, would it? I mean - I think php pages in drupal have to be entirely php. Maybe I'm mistaken - though I used to think that it simply meant php was allowed, and I thought I found myself wrong one day.
__________________ Are you tired of viruses and popups? Use Firefox!
Last edited by omegapandor; 06-19-2008 at 08:26 PM.
Reason: added information
|
| |
| | #4 (permalink) |
| NamePros Member Join Date: Sep 2006
Posts: 99
![]() ![]() | Edit: I think I found the error... You update the database when they do something, but you never update the variables themselves. You're pulling the old information in the beginning into the variables, updating it in the database, then printing the old information back out. That's why it isn't updating. If that still doesn't fix things... Besides the header (which I haven't really worked with much, but really should), you can try another trick. You can force the browse to believe it is a different page by having a randomly generated number on the link. ????: NamePros.com http://www.namepros.com/showthread.php?t=483401 Code: <li class="menu-122 active"><a href="/maingame<?php=rand(1,100000)?>" title="" class="active">Game</a></li> The point being, anyone with a normal 1024px configuration is going to be fine. Its the 800x800px morons who are going to have the issues. Bruce
Last edited by Bruce_KD; 06-19-2008 at 08:37 PM.
|
| |
| | THREAD STARTER #5 (permalink) |
| NamePros Regular Join Date: May 2008
Posts: 248
![]() ![]() | I've moved some stuff around and I still hasn't fixed it. I wasn't sure what you meant by printing the old information back out, but I did redeclare/assign variables after the changes occur within each if statement. no difference. I tried putting all the echo stuff before the updates. same thing. Tried inserting headers after the mysql updates and the text would actually update on the second button press and then go back to the old variable before correcting itself again. weird! ????: NamePros.com http://www.namepros.com/showthread.php?t=483401 Something very important to note: the first time I hit the button, the "this page has been updated" note stays at the top, as if the page hasn't changed at all. Then, the second time when the text changes, that note goes away. So, I know the page isn't refreshing at all with the first button press, even when it's forced to. Haven't tried the random page trick yet. . .er. . .rather, I just haven't gotten it to work. I'm going to just forgo the whole menu thing (where would I put that? CSS?) and just keep the <a> tag and throw it on my about page or something. I guess I'll have to convert the whole page to php, though, since it didn't recognize the code. . .er. . .maybe not. I'll try changing the input format to php and just inserting the <a> tag. Back to work. UPDATE: The weapons button, which has no if($_POST) will correctly refresh the page the first time it is pressed. UPDATE 2: Now when I hit the survivor button, the page refreshes (the note goes away), but the text doesn't update. hitting one of the buttons updates the text but it's still one value behind. ALSO, hitting the the button without an if($_POST) will restart the process where the survivor button won't do anything the first press.
__________________ Are you tired of viruses and popups? Use Firefox!
Last edited by omegapandor; 06-19-2008 at 09:18 PM.
|
| |
| | THREAD STARTER #7 (permalink) |
| NamePros Regular Join Date: May 2008
Posts: 248
![]() ![]() | PHP Code: I might still be doing what you mentioned earlier though.
__________________ Are you tired of viruses and popups? Use Firefox! |
| |
| | #8 (permalink) |
| NamePros Member Join Date: Sep 2006
Posts: 99
![]() ![]() | Code: <?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
$connt = mysql_connect("account");
if (!$connt)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("omegapan_drpl1",$connt);
global $user;
//GAME VARIABLES GAME VARIABLES GAME VARIABLES
$r = mysql_query("SELECT * FROM users WHERE name = '$user->name' limit 1");
$z = mysql_query("SELECT * FROM game WHERE id = '$user->gameid' limit 1");
$row = mysql_fetch_array($r);
$name = $row['name'];
$turns = $row['turns'];
$zdollars = $row['money'];
$gid = $row['gameid'];
$row2 = mysql_fetch_array($z);
$followers = $row2['survivors'];
$zombies = $row2['zombies'];
$zpool = $row2['zpool'];
$cades = $row2['barricades'];
}
//POST DATA
if($_POST['sfind'])
{
mysql_query("UPDATE game SET survivors = survivors + '1' where id='$gid' ");
mysql_query("UPDATE users SET turns = turns - '1' where name='$user->name' ");
}
if($_POST['build'])
{
mysql_query("UPDATE game SET barricades = barricades + '1', zpool = zpool - '3' where id='$gid' ");
mysql_query("UPDATE users SET turns = turns - '1' where name='$user->name' ");
}
if ($_POST['sfind'] || $_POST['build']) {
$r = mysql_query("SELECT * FROM users WHERE name = '$user->name' limit 1");
$z = mysql_query("SELECT * FROM game WHERE id = '$user->gameid' limit 1");
$row = mysql_fetch_array($r);
$name = $row['name'];
$turns = $row['turns'];
$zdollars = $row['money'];
$gid = $row['gameid'];
$row2 = mysql_fetch_array($z);
$followers = $row2['survivors'];
$zombies = $row2['zombies'];
$zpool = $row2['zpool'];
$cades = $row2['barricades'];
}
echo "<html>
<head>
<style type='text/css'>
a.nav2, a.nav2:link, a.nav2:visited
{
display: block;
width: 100px;
height: 30px;
border: 1px solid #000;
color: #000;
margin-left: 2px;
float: left;
text-align: center;
text-decoration: none;
text-size: 12px;
line-height: 25px;
overflow: hidden;
background: #638F0A;
color: #fff;
}
.submitlink
{
display: block;
width: 150px;
height: 30px;
border: 1px solid #000;
color: #000;
margin-top: 4px;
text-align: center;
text-decoration: none;
text-size: 12px;
line-height: 25px;
cursor: pointer;
cursor: hand;
overflow: hidden;
background: #638F0A;
color: #fff;
}
.submitlink:hover
{
background: #86C20E;
}
</style>
</head>
<body>
<form method = 'post'>
<input class = 'submitlink' type='submit' name='sfind' value='Look for Survivors' />
<input class='submitlink' type='submit' name='findweapon' value='Look for Weapons' />
<input class='submitlink' type='submit' name='build' value='Build Barricade' />
<form><br/><br/><br/><br/>
<a class='nav2' title='Your username'>Survivor: " . $name . "</a>
<a class='nav2' title='Your Game ID'>Game: " . $gid . "</a>
<a class='nav2' title='Your current Zdollars'>ZPool: " . $zpool . "</a>
<a class='nav2' title='Your remaining turns'>Turns: " . $turns . "</a>
<a class='nav2' title='Followers'>Followers: " . $followers . "</a>
<a class='nav2' title='Zombies waiting outside'>Zombies: " . $zombies . "</a>
<a class='nav2' title='Barricades Constructed'>Barricades: " . $cades . "</a>
</body>
</html>";
mysql_close($connt);
?> ????: NamePros.com http://www.namepros.com/showthread.php?t=483401 ????: NamePros.com http://www.namepros.com/showthread.php?t=483401 A few tips on php/mysql: When you select data from a database (Like you did in $r and $z), chances are you don't need every field of data (eg, if the table `users` contained their email and password as well as the information you needed). It's better to select only the fields you need. Code: mysql_query("SELECT `name`, `turns`, `money`, `gameid` FROM users WHERE name = '$user->name' limit 1"); I also recommend doing everything by ID instead of name. Why? 1. People enjoy changing their name on occasion. Make this a possibility. 2. If you're going to be getting data from a table, you need to be using Indexes. Basically, if you have a field "indexed", it saves all that data in the RAM (instead of the disk like all the rest of the fields are stored in) so it is really fast to search for. Sure, you can index name, but names are usually 10-20 characters long. My guess is you won't have more than 1,000,000 users (Sorry, I wish we all could, but we won't), so you can make the ID Int(6). That means mysql stores 3-4x less data in the RAM, making it more efficient and much faster. Also, since you're only expecting one row of data, you don't need the whole while($row=) thing. Just do a $row=mysql_fetch_array($r); I also fixed the $_POST[field]s. While php will recognize $_POST[field] as $_POST['field'], it is much slower (php checks to see if field is a constant first, then after it determines there is no field constant, converts it to a string. Finally, you probably don't even need to do all the original variable setting. If $user is an object containing all the information, then $gid should just be $user->gameid, correct? Then, you could wipe out the first set of $r, $z, $row, $row2, and those other assignments. Set $gid to $user->gameid Check for the posted data and do your updating with it. Finally, remove the "if ($_POST['sfind'] || $_POST['build']) {" statement, as you need to set those variables for output later. I also changed your building update: You can update more than one field in the same mysql query by separating them with commas. Bruce |
| |
| | THREAD STARTER #9 (permalink) |
| NamePros Regular Join Date: May 2008
Posts: 248
![]() ![]() | OMFG IT WORKS!!! I don't know which thing you changed did it, but it works perfectly! 30NP$ Donated. You earned it. Rep added, too. Yeah, I wasn't sure what to do about selecting stuff from the users table. I figured I was probably wasting time and memory, though. In the case of game, however, I use every variable on the table anyway. I had seen that most places used id instead of name. I knew in the long run it could waste a lot of processor - just hadn't gotten around to trying to implement the id. Most places use $user[id] but I'm not sure that will work in my situation. I guess I could just use $user->id ? ????: NamePros.com http://www.namepros.com/showthread.php?t=483401 In drupal, changing your name directly changes it in the database so users could still change their name and $user->name would work. In fact, I did it a couple of times. I still planning on using the obviously faster method, but that might be important to know in the future or something. I had NO IDEA about the $_POST['var'] vs $_POST[var] thing. I'll use quotes from now on. Thanks! I never thought to use || either. Is that what fixed the problem? I'm not really getting how if($_POST) can/should be done twice. . . I'm assuming in php the || just means 'or' so I figure that statement just takes away the need for two separate if sections. I'll probably read your post several more times before I fully understand some of the things. Thank you so much for your help! I'll find happiness/success yet!
__________________ Are you tired of viruses and popups? Use Firefox!
Last edited by omegapandor; 06-20-2008 at 09:08 AM.
Reason: spelling
|
| |