ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
The correct answer depens on what your cell looks like when you type in 3 and 4. If red and blue are the only possible colors you could use something like: $value % 2 === 0 ? 'blue' : 'red' If the colors keep changing: $colors = array('red', 'blue', 'orange', .., 'purple'); print $colors[$value - 1];
-
Drop the whole ((()()()()((()(((()))) thing it makes your code unreadable anyway $f = $_FILES['file']; $imageSize = getimagesize($f['tmp_name']); if (preg_match('/image\/(jpg|jpeg|gif|png)/', $imageSize['mime'])) { if (UPLOAD_ERR_OK !== $f['error']) { echo "Return Code: " Additionally you could do: function isValidImage($imagePath) { $imageSize = getimagesize($imagePath); return preg_match('/image\/(jpg|jpeg|gif|png)/', $imageSize['mime']); } Then you can use: $f = $_FILES['file']; if (isValidImage($f['tmp_name'])) {
-
Yes. Don't use a while.
-
No worries just make sure you keep active on the forum. Help other people! It will increase your learning speed (something I didn't knew when I first started) This tip is based on: "Learn from mistakes of others as you may not make them all yourself". This wil help and guide you in your future career as in "been there, done that". Equally true: by remaining active on the forum you will learn to spot errors more quickly in your own code because you have the advantage of looking at million lines of bugged code every day
-
About this: ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/png")) //&& ($_FILES["file"]["size"] < 900000000) && ($ext == "jpg" || "png" || "gif")
-
Never ask if their is a better or easier way of doing something because their always most likely is (this is especially true for people balancing between novice and intermediate) It could be something like: // this example however misses proper validation plus testing $user = $userTable->find($request->getParameter('id')); $form = new UserForm(); $form->populate($user); if ($request->isPost() && $form->isValid($request->getPost())) { $user->updateUserData($form->getValues()); // validate, filter & assign data $user->save(); // update row } $view->form = $form; You may also notice that this example has 2 states: retrieving the data and storing the data you could separate this process so you would only query the db 2 times instead of 3 times like it is now. Now back to your original question, the solution lies within your UPDATE satement which is incorrect and should have been: $querychange = mysql_query ("UPDATE users SET fname='$fname', lname='$lname', location='$location', dob='$bday', about='$about', favgames='$favgames' WHERE username='$user'");
-
Try: $imageSize = getimagesize($tmp_name); // $tmp_name = $_FILES['attribute-name']['tmp_name'] if (preg_match('/image\/(jpg|jpeg|gif|png)/', $imageSize['mime'])) { // your cool stuff here }
-
Note: Uses my previous post as a starting point You need a little Math (cartesian|polar coördinate system) to accomplish this you use the coördinates of the player and calculate the name of the tile the player is standing on for example 125-125-250-250.png (all tiles are 125x125) and the player's coördinates are for example 137,195 Code example to clearify the map name: list($x1, $y1, $x2, $y2) = explode('-', pathinfo('125-125-250-250.png' PATHINFO_FILENAME)); Then this becomes easy: SELECT * FROM players WHERE x BETWEEN $xmin AND $xmax AND y BETWEEN $ymin AND $ymax AND NOT id = $playerid
-
Maybe you also want to consider a more performant solution then storing 2.5M rows in your db.. For example consider the map to be virtual virtual (if that exists) This way you don't store 2.5M rows and only PHP knows the boundry of your map 5k² then when a player travels store his coördinates along with his character data and load the corresponding image (auto-generated or picked from an images directory) This will give you an enormous increase in performance.
-
Hello, For a new project have I got the following situation: A customer has an existing CMS system that grew over the years. Additional desktop programs where written to allow for easier, quicker editing (VB app that interfaces with the CMS db) Problem: The customer asked us to write a new CMS system that fully integrated their workflow. So, only the CMS system is going to be replaced and thus the existing database structure can not be modified nor can it's data be copied as the VB apps would become obsolete (unless these would be updated to which is unlikely as the budget will not allow it) Now I don't believe I need to write a new CMS from scratch as it's class structure allows for much flexibility and my current solution uses a Factory Method- and Façade pattern. Where the Façade contains all the database calls (not sure this is a good thing) and the Factory Method instantiates the appropriate Façade depending on the underlying database structure. The Façade itself would use the CMS specific models and take the necessary steps to retrieve the required data which is why I choose for the Façade pattern. Do you know any better solution then this one?
-
Hi, I have installed WampServer 2.0i (latest release) and xdebug 5.3vc6 PHP Version: 5.3.0 Apache Version: 2.2.11 PHPInfo: Compiler: MSVC6 (Visual C++ 6.0) Debug Build: no Thread Safety: enabled When I add zend_extension="/absolute/path/to/ext/php_xdebug.dll" to my php.ini then the server crashes and when I comment out the line everything works fine. Any suggestions?
-
SELECT * FROM dealer_table ORDER BY category_id Altough I assume this is the default behavior if you don't specify any 'order by' rule
-
[SOLVED] Creating 2 instance of class and accessing next result set
ignace replied to Curlyfreak's topic in PHP Coding Help
When you develop your application to be seperated amongst different layers/tiers to be independently developed of each other doesn't mean you will have a class named after the tier/layer. The same misconception exists amongst the MVC pattern where people believe you have 3 classes: Controller, View and Model while each usually contains multiple classes in each tier. is because of include 'DataAccessLayer.class.php'; use include_once() because you didn't include it: //include 'CustomException.class.php'; // when I include this file it gives error solve the previous 2 and this should work. -
[SOLVED] replace strings from another mysql table and then echo
ignace replied to dezkit's topic in PHP Coding Help
ORDER BY server_id -
Why not just let $types hold all extra variables in an array: select('fields', 'table', 'where', 'limit', array(..)); Afterwards check on type: if (is_array($types))
-
If you use __autoload this is not an issue. storing an object in a session means the object gets auto-magically serialized and un-serialized - you can also control that using the __sleep and __wake methods within the class itself. That is if you load it (declare it) before session_start() in both cases. Like I said here:
-
Don't forget that when you use custom objects in sessions you need to load them before session_start on each request otherwise it won't be able to re-create the custom object as it can't find the class definition
-
Help with this function ... or EngInSite editor!
ignace replied to Johnain's topic in PHP Coding Help
Please post lines 40-50 from db_lib.php -
<form> Required bit rate <select name="bitrate"> <option value="">128kbps</option> <option value="">192kbps</option> <option value="">240kbps</option> <option value="">320kbps</option> </select><br /> Required listener ammount <select name="listeners"> <option value="">up to 100</option> <option value="">up to 200</option> <option value="">up to 400</option> <option value="">400+</option> </select><br /> Auto DJ? <select name="dj"> <option value="">Yes</option> <option value="">No</option> </select> <button type="submit" name="calculate">Calculate</button> </form> Add the price between " in the value="" for each. if (isset($_POST['calculate'])) { $bitrate = floatval($_POST['bitrate']); $listeners = floatval($_POST['listeners']); $dj = floatval($_POST['dj']); print $bitrate + $listeners + $dj; } Note: This is an example and should not be used in production.
-
SELECT `ID`, `title`, `content`, `articleDate`, `pdfDoc`, date_format(articleDate, '%M %Y') as monthYear from articles ORDER BY monthYear, articleDate DESC $current = null; while ($row = mysql_fetch_assoc($result)) { if ($current !== $row['monthYear']) { $current = $row['monthYear']; echo '<dt>', $row['monthYear'], '</dt>'; } echo '<dd>', $row['title'], '</dd>'; } I modified your query so that it orders by monthYear first and articleDate afterwards (thus all monthYear will be grouped together). Afterwards I added a $current which will hold the current monthYear (August 2009 first, September 2009 second, ..) and print it once.
-
When you submit a checkbox it will send the value in the attribute value if and only if it is checked. <?php while ($row = mysql_fetch_assoc($result)): ?> <input type="checkbox" name="company_code[]" value="<?php print $row['company_code']; ?>" <?php ((isset($_POST['company_code']) && in_array($row['company_code'], $_POST['company_code'])) ? ' checked="checked"' : ''); ?>> <?php print $row['company_code']; ?> <?php endwhile; ?>
-
Have you tried this?
-
[SOLVED] Adding Quanity To Databaseless shopping cart
ignace replied to TheJoey's topic in PHP Coding Help
if (!isset($_SESSION['shopping_cart'])) { $_SESSION['shopping_cart'] = array(); } -
Use \n only instead of \r\n
-
Problems with sending an email in PHP using the Mail module
ignace replied to alancgmty2099's topic in PHP Coding Help
Is there a require_once or something similar above the class Mail_Smtp definition?