Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. Um, no. mysql_result() will pull a single value forom a query result set. The first parameter is the results set, the second parameter is the record index (index 0 is the first record). There is also an optional third parameter for the filed name or index. But, since you would only have one value in your result set it is not needed. By changing the 0 to a 5 you are trying to get the value from the 6th record in the result set - which would not exist. Yes, you need to define the max number of posts per day and change the 5 back to a 0. $post_count = mysql_result($result, 0);
  2. //QUERY TO FIND THE COUNT $query = "SELECT COUNT(*) FROM `CysticAirwaves` WHERE `FromUserID` = $auth->id AND date = `CURDATE()`"; $result = mysql_query($query, $connection); $post_count = mysql_result($result, 0); if($post_count >= $max_posts_per_day) { echo "You have reached the maximum number of posts for the day. Try again tomorrow"; } else { //Code to insert comment goes here }
  3. One solution, that I typically use, is to have form pages post to themselves. Then if there are any errors I dimply re-display the form with the previously submitted data and include the error message on the page. If validation passes, then I include the script to process the data.
  4. Interesting. Never knew you could put a conditional in the ORDER BY.
  5. Did you use the query I provided "as is"? Did you change the field names as needed? I can't see your database and, therefore, cannot know if the field name I used (i.e. 'date') was the name you used. Wherever you are running your query ensure you validate if the query was successful. If not, echo the error to the page for debugging purposes. $result = mysql_query($sql) or die(mysql_error()); By the ay. It looks like you are using the value '0000-00-00' to indicate that the user is still attending - i.e. there is no end date. I would suggest a more logical approach would be to simply set that field as NULL.
  6. Here's some sample code. I corrected some problems in your code (e.g. no TR tags around the header row) and moves some logic around to be more organized. You don't show the JO code anywhere in your code, so I just put a placeholder in the value parameter for the hidden field. Also, you will probably want to modify the default margins/padding for form tags else they rows may not display as you wish. <?php error_reporting(0); date_default_timezone_set("Asia/Singapore"); //set the time zone $con = mysql_connect('localhost', 'root',''); if (!$con) { die('failed'); } mysql_select_db("mes", $con); $sql = "SELECT ETD, PO_No, SKUCode, Description, POReq FROM sales_order"; $res_so = mysql_query($sql, $con); $recordsHTML = ''; while($row = mysql_fetch_assoc($res_so)) { $recordsHTML .= "<tr> <td> </td> <td>{$row['ETD']}</td> <td>{$row['PO_No']}</td> <td>{$row['SKUCode']}</td> <td>{$row['Description']}</td> <td>{$row['POReq']}</td> <td> </td> <td> <form name='loading_kanban' action='' method='post'> <input type='hidden' name='jo_num' value='{JO_VALUE_GOES_HERE}'> <input type='button' name='priority' value='Approved' id='priority'> </form> </td> </tr>"; } $Date_Shelve =date('Y-m-d H:i:s'); ?> <html> <head> <title>Sales Order</title> <link rel="stylesheet" type="text/css" href="kanban.css" /> </head> <body> <div id="SR_date"> <label>Date :</label> <input type="text" name="Date_Shelve" id="Date_Shelve" value="<?php echo $Date_Shelve; ?>" size="16" readonly="readonly" style="border: none;"> </div> <div id="kanban_table"> <table> <tr> <th> JO No.</th> <th> ETD </th> <th> PO No. </th> <th> SKU Code </th> <th> Description </th> <th> PO Req </th> <th> Requirements </th> <th> Priority</th> </tr> <?php echo $recordsHTML; ?> </table> </div> </body> </html>
  7. I would create each submit button as a separate form. Then you can include a hidden field in each form with the value of the ID you need to pass
  8. I guess my first question is why are you storing 000-00-00 in the first place? Why are you not storing the present date as, well, the present date? But, if you have a valid reason for doing that (which I can't think of any) a simple ORDER BY on the date column will not get what you need because you want the '0000-00-00' date (the smallest amount) to be first followed by dates that then start at the highest and then decrease. So, you will need to add a virtual sort value to get the '0000-00-00' dates first then sort descending. $sql = "SELECT *, IF(date='0000-00-00', 0, 1) as firstSort FROM user_references WHERE employment_id='{$rowe['id']}' AND user_id='{$user_id}' AND status='active' ORDER BY firstSort ASC, date DESC";
  9. One of the problems you are going to face is that there will be no simple way to assign unique coordinates to users and ensure there are duplicates. Using 0-200 for the X and Y coordinates gives you a total of 40,401 unique coordinates. You could generate a set of random coordinates, check if they are already used and, if so, discard and try again. If you were to only support a small number of users relative to the total available this should work. But, the more users you have relative to the total available the more that process will be a problem. Another option would be to create a table of all available coordinates and then remove them as they are assigned. If you are only going to have 40K options that is doable. But, if your total options was to increase significantly that wouldn't be advisable either. So, you need to strike a balance. As for
  10. Yes. Do you have some code you need help with?
  11. I already told you that date_sub() and the content within it (i.e. the INTERVAL part) was not PHP code. It is a MySQL function. Why would you then take that out of the query and try to use it as PHP code?
  12. I don't mean to be rude (well maybe a little bit) but isn't that exactly the same as the example I provided to you above for displaying user profiles? But, I want to reiterate that a "dynamic" page doesn't mean a single page such as a profile or a product page. You could have a single page such as "user.php" which could perform any number of tasks and outputs that are determined by the parameters sent (POST, GET, etc.). For example: users.php?action=list: provides a list of users users.php?action=show&id=23: displays the profile for user with the id 23 users.php?action=new: Displays the form to add a new user users.php (POST['action']='add'): Add a new user from the post data users.php?action=edit&id=23: Displays a form to edit user 23. Current values are already populated users.php (POST['action']='update'): Updates user 23 with the data sent in the post data users.php?action=delete&id=23: Provides a confirmation asking if you want to delete user 23 users.php?action=delete&id=23&confirm: Performs the delete of user 23
  13. You aren't understanding what I am saying. You don't need a cron job. You don't need to update the records to explicitly set them as active. IF the battle is exited properly then you would explicitly update them to active. But, for the battles that are not exited properly you can determine that they are active if they have not been updated in 20 minutes (or whatever period you want). That is what the example query I provided would do. Let me explain it in plain English. If you wanted a list of all available monsters you would query for all records where 1) there is no active battle record for the monster (i.e. they were exited properly) OR 2) the last activity value is > 20 minutes (i.e. the battle was not exited properly). I gave you an example query. This isn't my project so I'm not going to invest a lot of time to get your DB structure and build and test the optimal query for you. As for the INTERVAL statement, of course it isn't PHP markup. That is a query which would contain MySQL code. The date_sub() function takes a datetime value and subtracts some amount from it. In the example I provided, it is taking the current timestamp [i.e. now()] and subtracting the interval of 20 minutes from it. So in the query OR last_updated < DATE_SUB(NOW(), INTERVAL 20 MINUTE) I was including records who's last_updated value is less than 20 minutes ago. In other words, records which have been inactive for more than 20 minutes
  14. There is no all encompassing answer to your request. A "dynamic" page can be a page that is 99% static (e.g. HTML code) which simply has a value that is replaced dynamically. Or the entire structure and content of the page can be generated in real-time. It all depends upon the needs of the application. For an example, let's say you want to be able to display user profile information. You wouldn't want to create static pages for each user. Instead you build a "template" or wire-frame for a profile page. That page would be used to show the profile for any user. For example, when calling the page the user would click on a link for "Bob's" profile. That link could point to the template page and pass the unique ID for bob: display_profile.php?id=23. The template page would take that ID and query the database for bob's profile information. Then it would inject that profile information into the page and return the result back to the user. But, that is only one example. The process could be extremely complex where the process determines which type of content from many different possible output and uses many different files to create and generate different parts of the output. It would not be uncommon for a page request to 10, 20, 30 or more different files to generate the output for a single page.
  15. You state "I don't have a column for status, that's the issue.", but that's not true. You just stated that you have a field called "state" which is basically the status. But, with the additional information you've provided you don't even need that field. You can use the associated records in the battles table to derive the information you need. Here is a general idea of what I would do. When a user starts a battle you would add the associated record to the battles table with a foreign key reference back to the monster. However, I wouldn't copy the hp and no_exp to the battles record - again you can derive that from the monsters table. As actions take place with the battle you would update the battles record with the appropriate data. At a minimum I would expect that you would need to store the damage inflicted and of course there should be a automatically updated timestamp. The table would also need a field to indicate if the battle is complete/exited which you would update if the user explicitly leaves the battle or if the monster was killed. So, you could then get a list of any available monsters by JOINing the two tables and using the right criteria. Example SELECT * FROM monsters LEFT JOIN battles ON monsters.id = battles.monster_id AND battles.complete = 0 WHERE battles.last_updated > DATE_SUB(NOW(), INTERVAL 20 MINUTE) This is just a general approach. I can't really provide all the code and queries needed.
  16. You don't need to delete anything. There is no timeout event to know when a user has not performed any action. You would have to create a cron job to run every so often to check for inactive records and delete them. That's not efficient. Instead you would change the logic for determining what records are active. Instead of just looking for the status of active you would use TWO criteria to determine if a record is active or not: 1. If the status value is explicitly set as active 2. Or, the last activity value of the record is > 20 minutes
  17. Have you looked at the actual HTML source code? Depending on the context of how you are actually echoing that content it could be that the output is all there, but that the rendered HTML doesn't display it. For example, this HTML code would produce the result you describe <a href='#' title='Dream as if you'll live forever, Live as if you'll die today'>Link</a>
  18. Did you ever think of simply echoing the type value to the page and uploading a .doc file? You would then see what the value was and could implement it in your code. This is very simple stuff that you should be able to do on your own. Don't get caught up in the details that you lose common sense. Although you would want to test with .doc and .docx files.
  19. How are you determining the status now? I assume you have a database, so perhaps you have a column for status. I really can't give you a good solution based upon what you have provided. But, I will provide a possible solution with one potential scenario. You can then modify that as you need it. Ok, so I will assume you have a field in the "monsters" table to indicate the status. For simplicity's sake I will call this field "fighting" and a 1 (true) value indicates that the monster is fighting and a 0 (false) indicates the monster is active. The problem, is that you cannot force users to release a monster to go from fighting back to active. The solution is to assume after x amount of inactivity that the monster is active even if the status is 1. With the potential scenario above you could have a query to get a list of all active monsters such as this: SELECT * FROM monsters WHERE fighting = 0 I would fix this problem by first creating a "last_updated" timestamp field in the table. And set the parameters so that value is automatically updated to the current timestamp whenever the record is changed (i.e. you would not have to set the value manually when creating or editing the records). Now, to get all the records that are set as active AND to get the records that are set as fighting but have been inactive for, say, 20 minutes you simply need to change the query SELECT * FROM monsters WHERE fighting = 0 OR last_updated < DATE_SUB(NOW(), INTERVAL 20 MINUTE) Of course you would need to add some functionality for a user that did not close their page but did leave the window inactive. Instead of assuming they can still fight with that monster it would need to see if that user still had control. If not, you can display a message to the user that they lost control due to inactivity.
  20. You can't have it both ways. If you are dead-set on using a flawed method to get the data you need then you will need to rely upon a flawed method to resolve your issue. The "better way" is to create your own query with a condition to only return records where there is an image. But, if you are dead-set on not wanting go down this path, the best solution I can think of would be to query X number of records instead of 2. Then loop over the results and check if the record has an image. If so, add it to your results. If not, go to the next record. Once you have two records with images, break out of the processing loop. Querying one larger set of records will be substantially more efficient than having to do multiple queries to get two records at a time - and I don't see how the current process would allow you to ensure you are not getting duplicates if you rerun the query.
  21. And, you should consider changing that condition check so you don't need all the OR conditions. $allowedTypes = array('image/jpg', 'image/jpeg', 'image/pjpeg', 'image/gif', 'application/pdf', 'application/doc'); if (in_array($_FILES['fupload']['type'], $allowedTypes)) { //Process the file }
  22. Building upon what requinix posted, put this at the top of the page that lists the records if(isset($_POST['id'])) { header("Location: /path/to/thispage.php#{$_POST['id']}"); exit; } If you load the page without the post value it will display without moving to an anchor. However, if you do post a value for the ID, then the page immediately reloads the page with the appropriate anchor tag in the URL.
  23. You really need to re-think your logic. You are adding the image to the database before you even save it to the server. In fact. You do an insert and then follow it up with an update on that record of information you could have already had when you did the insert. Plus, you are doing things that have no purpose $new_id = mysql_insert_id(); $filetype = $photos_uploaded['type'][$counter]; $extention = $known_photo_types[$filetype]; $filename = $new_id.".".$extention; mysql_query( "UPDATE gallery_photos SET photo_filename='".addslashes($filename)."' WHERE photo_id='".addslashes($new_id)."'" ); Why are you using addslashes() on the variable $new_id? It is an integer returned from the database. In fact, why are you using addslashes() as all?! You should be using mysql_real_escape_string(). The more I read of that code the more I see wrong. while( $counter <= count($photos_uploaded) ) { You have an array. Why are you using a while() loop with an artificial counter instead of a foreach() loop/ list($width,$height) = getimagesize($_FILES['photo_filename']); Why are you referencing $_FILES['photo_filename'] for getimagesize() since that value is an array? You are in a loop list($width,$height) = getimagesize($_FILES['photo_filename']); Why are you referencing the $_FILES array? You shoudl be referencing the current image in $photos_uploaded $function_to_read = "ImageCreateFrom".$function_suffix; $function_to_write = "Image".$function_suffix; // Read the source file $source_handle = $function_to_read ( $images_dir."/".$filename ); You cannot create a variable that has the "name" of a function and then use that variable as a function. You create a STRING, so what thePHP parser sees is something like $source_handle = "imagecreatefromgif" ( $images_dir."/".$filename ); Complete nonsense. I'm sorry if you feel my response is abrasive, but you need to be more aware of what you are doing and understand why you are doing it. Do, one thing at a time and test it. Then do the next thing.
  24. It's hard to tell from that code, but are you running queries in loops? There are much more efficient ways of doing that. Anyway, as to your requested problem, you don't state how you are getting the image. Are the image names/path stored in the database? If so, what is the value of the field when there is no image? You could simply change the query used to get the posts to only pull records that have an image. However, if the image names are not stored in the database and you are storing them named in a way to associate them with the posts (e.g. using the post id), then you would have a real problem. A recursive function (especially with database requests) is a bad idea. If the query is requesting random records you have no idea how many requests would be needed to find two records with images. And, what if some category didn't have two posts with associated images - the recursive function would be caught in an infinite loop.
  25. When you state that the login works on one site but not another, can you provide some more information. Are the two sites sharing the same database? I'm not taking about the same database server, but the exact same tables? Or did you, by chance, copy the database from one site into the other?
×
×
  • 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.