Jump to content

zeodragonzord

Members
  • Posts

    104
  • Joined

  • Last visited

Everything posted by zeodragonzord

  1. In that case, you'll want to put the value of each subject_id into the array directly. If you can access the variable subject_id directly, try this. $match_subject[] = $t2s->subject_id; If the members are protected/private, then perhaps there's a getter function to get it. $match_subject[] = $t2s->getSubjectId(); I don't know the API, but perhaps that'll help step you to the right direction.
  2. Modulus is your friend. It's the remainder of a division. Here's an example. $arr = array(); for($i=0; $i<100; $i++) { if(($i%3) == 0)//If the division by 3 has 0 for remainder, do the following. { echo $i . " <-- Hi<BR>"; } else//Otherwise, do this. { echo $i . "<BR>"; } }
  3. My suggestion is this. When the user first successfully logs in, store the user's username in the $_SESSION variable. That way, the only time you'll ever need to capture a username from a $_POST is during login. Any other time, such as making a post, you'll take it directly from the session variable, $_SESSION['username']. This will prevent someone from fooling your script and give a fake username. I would go a step further and store the user's user_id along with the username in the $_SESSION variable and use the user_id for determining who the user is, but use the username for display purposes.
  4. It looks like you have an array of objects, not an array of arrays. in_array works if by comparing the array of the second parameter directly on the first level. So if the $match_subject has nested arrays, you'll need to dig deeper to look for the values. If you post how you've generated the array, that would help.
  5. If you need a leading zero, you must store it has characters, not integers. As teamatomic says, CHAR or VARCHAR should work, though if you're expecting 10 numbers always, then use CHAR.
  6. Knowing what you will update before you the update is a good idea since you can assure that the rows in focus are already in the database. If you do a SELECT beforehand, you can verify that rows exist and keep a copy of the primary keys. Run your update statement and you'll still have your primary key list of rows you've updated. If you do a straight UPDATE, you can't guarantee that you've affected any rows, if criteria doesn't match any rows.
  7. That's because it takes the first name/value pair it finds and attaches a ? to it after the page name. All other name/value pairs after that will have &. The ACTION attribute should only have the page name; remove any ? or & it has. You never have to manually add in ? or &, the form will do it for you. On any form tags, the NAME attribute should have a name only, and the VALUE attribute should have a single value only; no mixing and adding of multiple values with ? and &. Not tested... <form action="index.php"> <select name="site"> <option name="clanID" value="{$dm['clanID']}'"> </select> <input type="hidden" name="cupID" value="{$dl['ID']}"> <select type='hidden' name='action' value='clanregister'> </form> I'm assuming that you don't have multiple values for cupID for each form. Basically, your loop would generate more <option></option>.
  8. I'm not sure if there's a natural MySQL way to do it, but you can instead create a last_updated DATETIME column field that is changed each time you update a row in that table. Then do a SELECT statement on it, sorting by that column DESC LIMIT 1 to get the last updated row.
  9. What did you want to print on the page? You don't have print() or echo() statements.
  10. You have a while loop that will always equal to true because $PageCount == $NumberPages (both are 0). The value of $PageCount never got changed because the if-statement never returns true, $PageCount is not less than $NumberPages, therefore that block of code never gets run and nothing will change the $PageCount.
  11. Don't have a space between < and =. Instead, use this: <=.
  12. It looks like you're trying to put a form value into the ACTION attribute of the <FORM> tag. You don't need to do that. Instead, use HIDDEN fields. Not tested... <input type="hidden" name="action" value="clanregister"> <input type="hidden" name="cupID" value="myValueHere"> Then remove the extra values you have in your ACTION attribute and only have the page name there.
  13. At the end of a freelance job, do you typically send your client a paper to have them sign it stating that you have completed your job? I'm worried that clients might either ask for small changes or ask for advice that will take up time to do. When I mean small, I mean too small to be mentioned on the initial agreement. If not, how do you handle closing of freelance projects? Thoughts?
  14. Set the usertypeid into the $_SESSION variable the same way you set the username. Assuming that the usertypeid is in the same table as your username... Not tested... //Get the username from the database $query = "SELECT usertypeid FROM user WHERE username='{$username}'"; $result = mysql_query($query); //Assign the username into the $_SESSION $row = mysql_fetch_array($result, MYSQL_ASSOC); $_SESSION['usertypeid'] = $row['usertypeid']; //Do something depending on the usertypeid switch($_SESSION['usertypeid']) { case 1: { //Do something break; } case 2: { //Do something else break; } default: { //This is probably a usertypeid that we do not support or the result we're getting from the database is incorrect. break; } }//switch Those are the basics. You'll want to clean your variables before running a MySQL statement or use Pear MDB2.
  15. It does not work as you expect because you're doing a select statement inside the loop, so you're getting the same result each time you loop. You'll want to get the data you want outside of the loop, then run the results inside the loop. Not tested... <?php $id_string = ''; //variable to hold concatenated IDs $result= mysql_query("SELECT DISTINCT nid FROM xx WHERE type='xx' ORDER BY RAND() LIMIT 3"); //get the distinct results limited by 3 rows of data //loop each one while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id_string .= $row['nid'];//put the value from the database into my string variable } ?> <table width="294" height="26" border="0"> <tr> <td width="95" align="left" valign="top"><?php print $id_string; ?></td> </tr> </table> <?php $i++; } ?>
  16. Personally, I like to collect some or all this data: datetime when the error occurred filename where the error occurred class and function where the error occurred category of the error (database, bad input, logic, etc) if this occurred in Pear::MDB2, then record the Pear error message error level (critical, low, etc) I put all those into an object and that gets passed to an error handling object that looks at the error level and decides if it should send an email to me, log it into a file, or insert the error message into a database.
  17. I don't know about the performance aspect, but unless you're initalizing over 1million variables, the think the performance is negligible. What's more important is how you're going to use it. You say static variables, do you mean constants or do you mean static variables inside a class? The question is, should these values ever change? In an application, the database username/password should not change (your code should not have the ability to change it once it's set), so that should remain a constant. Think of it like that.
  18. In many cases, these names will get imported into programs such as MS Outlook, which will separate First and Last Name. When you import these names, the required format will have the names separated. In other cases, you might want to generate usernames based on the name: Cloud Strife will be cstrife1. It's not always correct to have regular expressions separate the names out because in the end, it's still a best guess. If you separate the fields, it's the user's responsibility to get their name correctly. If you take in full name and guess which name is first and last, that will be your responsibility. It's better to have the user to take on that responsibility; they're used to it anyway. There's a cultural difference in how we write names. In the US, we write FirstName LastName. In some other countries, they write LastName Firstname.
  19. That's correct, there is no right way. However, the most common organizational structure I've seen is to have: javascript css includes I use JavaScript libraries that I download online, jQuery, Spry, etc. I like to have a folder for each version. I do this so I can keep each version separate from each other in case I need to upgrade. /javascript/spry/spry_version1/ /javascript/spry/spry_version2/ If I update my own files, I won't create new folders for versions. I'll just let Subversion take care of versioning at that point.
  20. The best advice I can give you is to keep this mindset; anything that can change will change. Make sure it's scalable. Your code needs to be decoupled enough so that it can adapt to change. Therefore, as you lay out your folders, name your variables, and design your tables, keep in mind the long term aspect of your actions. Keep your business code separate from your other code. This is code that models the logic and rules set forth; the business logic and it can be directly interfaced with your database tables. Therefore, no gui code goes in there. Utility classes can go in this area. What I usually do is I have: business classes: user, groups, authentication, etc utilitiy classes: error handling classes, notification classes (email, log to file, log to database)
  21. I'm not clear on your situation but it looks like you're trying to use a captcha. The idea is that when you generate the form page, you also generate a keyword. This keyword is stored in some location, such as a session variable and you also generate an image out of the keyword to be displayed on the form. Additionally, you'll have the text field for th user to type the word in. When the user submits to the form, the next page that processes it will compare that value that the user entered with the keyword that is stored in the session variable. If it matches, all as well and you can proceed. If it doesn't match, go back to the form page. That check should probably go into your insert.php page.
  22. Since there's no natural way to do captions, you can wrap DIVs around each element to apply the text underneath the image. <div class="box"> <img src="pony.jpeg"> <div class="caption">This is my pony</div> </div> Then put five of those in a single DIV for each row. You'll have to add some styles to make it the way you want but this will give you an idea.
  23. I would go with DIVs but if it's mean to be tabular data, even as images, then tables aren't so bad. DIVs will give the most flexibility though. Have your PHP wrap around a new DIV after five images. Use modulous (%5) and if it returns 5, then create a new DIV section.
  24. I suggest you create a new table that links both those tables together. That way, you have only product information in a product table, only customer information in a customer table, and another table to determine who has what. This also will provide the many-to-many relationship you will want. For example, it's possible that a customer may have more than one product. Similarly, a product can be purchased by many customers. [product] product_id product_name product_description [customer] customer_id firstname lastname email [customer_product] customer_product_id customer_id product_id
  25. You do the same thing, just add another INNER JOIN clause. SELECT * FROM city INNER JOIN packages ON packages.city_code = city.city_code INNER JOIN hotel ON tableIAmJoiningOn.field = hotel.hotelField WHERE city.city_id='$id';
×
×
  • 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.