Jump to content

yungbloodreborn

Members
  • Posts

    45
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Male
  • Location
    California

yungbloodreborn's Achievements

Member

Member (2/5)

0

Reputation

  1. I'm not sure how a unique constraint would help... so I got into transactions, and that looks like it is working. I'll let you know how it goes...
  2. I'm working on building an online game, and I need a little bit of assistance with the query to join people to games. The important part of the player table is: player ( regcode varchar(32) primary key, gameid bigint ) And the important part of the game table is: game ( gameid bigint auto_increment primary key, player1 varchar(32), player2 varchar(32) ) I would like to put the following code into a single query: $sql = mysql_query("select gameid from player where regcode=\"$mycode\""); $row = mysql_fetch_array($sql); if($row['gameid'] == 0) { $sql = mysql_query("select regcode from player where game=0 and not regcode=\"$mycode\" limit 1"); $row = mysql_fetch_array($sql); $opcode = $row['regcode']; mysql_query("insert into game (player1, player2) values (\"$mycode\", \"$opcode\")"); $sql = mysql_query("select gameid from game where player1=\"$mycode\" and player2=\"$opcode\""); $row = mysql_fetch_array($sql); $gameid = $row['gameid']; mysql_query("update player set gameid=$gameid where regcode=\"$mycode\" or regcode=\"$opcode\""); } I need to make sure that all this happens in one step so that each player can only be part of a single game. Would I need to use transactions? Or how would I need to do this? If I just use php as written, and the site is busy, someone else may try to grab me as a player at the same time I'm trying to get a different player, and the database would be confused.
  3. I would still like an answer on this... But for this project I've decided to use another method. Since my purpose was just to unzip a file that I've uploaded to the server, I've decided to just use a cron job search for .zip files in the games folder, and have the cron job do the unzipping.
  4. I know about the -R. I'm creating a directory and setting the owner/permissions. There is nothing in the dir yet. So what purpose would the -R serve?
  5. Did I do this correctly? I wiped out the dir: rm -rf games Then I did: mkdir games chown kevin:apache games chmod 7775 games But it still creates files with owner of apache:apache... I'm sure I missing something.
  6. I'm having a permissions problem that I don't quite understand. I have a dir called "games" on my web server owned by kevin:apache. with 0775 permissions. I have a php script create a dir called "games/kaboom". It gains the owner of apache:apache, and permissions of 0755. And I can't seem to create anything inside of "games/kaboom". I've tried explicitly setting owner & permissions, but it seems to be ignored. Is there anything I can do to create stuff deeper in "games/kaboom" ??
  7. Well, I figured it out myself... select ((select ts from item where price>avg30-1 order by ts desc limit 1)-(select ts from item where price<avg30+1 order by ts desc limit 1))/(24*60*60); If the result is positive, it is the number of days it has been over avg30. If the result is negative, it is the number of days it has been under avg30 (* -1) If the result is 0, the price is equal to avg30... I hope this helps someone... Btw, ts is a unix timestamp... -YB
  8. Weeblesue, If you can translate that from month/date to dayofyear, you will almost have it solved. For a rough translation, you could use ((month - 1) * 30) + day. That would remove months from the problem, then the only problem would be dec17-dec31 overlapping into jan. I don't have the last piece of the answer, but hopefully that helps somewhat. -YB
  9. Here's what I'm trying to do. I have a database tracking the value of something, and I have 1 record per day. Each record in the table holds the current value, and the average of the last 30 days, and of course, a time stamp. What I want to know is how long has the current trend been over/under the average. Is there an easy way to ask this of mysql? Or would I need to add another column, and have a program manually walk through all the data to fill that column in?
  10. Damn, I just found the answer in another post. heh The answer wasn't there when I posted the first time... <?php header('Content-Disposition: attachment; filename="odephp.txt"'); printf("Ode to php\n"); printf("...\n"); ?>
  11. I would like to generate a file, and give it a name for a download. The result would be something like: <a href="http://mysite.com/getfile.php?file=1335">Download Poem</a> When I click that link, I want it to pop up a save as (download) box. I want the name that appears in that box to be whatever I choose. (i.e. 'odephp.txt') And the contents of the file would be generated from a script. <?php echo 'Ode to PHP'; echo '................'; echo 'Php how do I love thee?'; echo 'Let me count the ways'; $max = $_REQUEST['file']; $cnt = 0; while ($cnt < $max) { echo "$cnt..."; $cnt++; } ?> I would imagine that I need some kind of header call, but I'm missing a key piece to make it all work. Can someone please help?
  12. I added a reply with Solved, but that doesn't change the thread topic... I would need to be able to modify my orig post... :) and I guess there's a time limit on being able to modify posts... :)
  13. Here's a trick I use in my coding to keep related stuff all in the same file: <?php //$_REQUEST['data'] matches against the name in the <input> tag. $data = $_REQUEST['data']; $enter = $_REQUEST['enter']; //has form been submitted? //with simple radio buttons, !$data is enough to see that something has been selected. //with other types of of inputs, you can put in more advanced error checking. if ((!$enter) || (!$data)) { //display form... echo "<form action=''> <input name='data' type='radio' value='SomeValue' />SomeValue <input name='data' type='radio' value='SomeOtherValue' />SomeOtherValue <input name='enter' type='hidden' value='yup' /> <input name='submit' type='submit' value='Edit' />"; exit(); } //handle form data... echo "Check out my data: $data"; ?>
  14. Um, I can't modify my older posts, so I can't mark the topic I just got solved... what do we do in that case? :)
  15. Thanks for the note about the is_uploaded_file. I got that fixed, and it now reports correctly. I also got the upload working. I discovered it wasn't an issue with the code, it was a problem with my directory permissions. (Duh) For those interested, here's my complete, one file upload script. If it says contact webmaster, check target path & permissions... <?php echo "<html><head><title>Picture Upload</title></head><body><h1>Picture Upload</h1>"; $p_enter = $_POST["enter"]; // Display form if it hasn't been submitted yet. if (!$p_enter) { echo "<form enctype='multipart/form-data' method='post' action=''><table align=center> <tr><td><b>Please choose a file:</b></td><td><input name='uploaded' type='file'></td></tr> <tr><td> </td><td><input type='submit' value='Upload'></td></tr> </table><input type='hidden' name='enter' value='yup'></form>"; exit(); } // This is where the files go to... $target = "../images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; // Size & Type limiting... if ($uploaded_size > 350000) $err_size=1; if ($uploaded_type == "text/php") $err_type=1; // Check for errors, if everything is ok, move the file. if (($err_size) || ($err_type)) { echo "Sorry your file was not uploaded:<br>"; if ($err_size) echo "File too large.<br>"; if ($err_type) echo "File type not accepted.<br>"; } else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "<p align=center><b>The file ".basename( $_FILES['uploaded']['name'])." has been uploaded.</b></p>"; } else { echo "<p align=center><b>There has been an error uploading the file. Please contact the webmaster.</b></p>"; } } ?> </body> </html>
×
×
  • 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.