Skip to main content

Posts

Showing posts from January 30, 2012

Jquery Drag and Drop Issues

I am having a problem with bringing Jquery over to iPad. I made a drag and drop puzzle using Jquery, and on my computer it works fine. When I try to move that over to the iPad, the drag and drop functions cease to work. I have tried many a third party fix for this problem with no avail. Does anyone know how to solve this problem on iOS5? Or is there a better way to code it in HTML5 that works or a Jquery solution I do not know of? Any tutorials on the issue would be appreciated as well. Thanks.

Gathering segmented data via jQuery with FOR loops

Here's my code (what I'm stuck on is after the jump) <script language="JavaScript" type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script> <script type="text/javascript"> var countThisMany = 4; //how many data-id's I want to count per "section" of images var finalString = ""; //blank var to be used later, must be defined here. </script> <img src="foo.jpg" data-id="id1" data-item="1" /> // just a bunch <img src="foo.jpg" data-id="id2" data-item="2" /> // of images with <img src="foo.jpg" data-id="id3" data-item="3" /> // data-* usage to <img src="foo.jpg" data-id="id4" data-item="4" /> // store two bits <img src="foo.jpg" data-id="id5" data-item="5" /> // of information &l

How to extract relative URL from argument values from request string?

I have a request url / string var like http://ip_or_url:4773/image_renderer.service?action=resize&from_format=png&from_url=http://ip_or_url:4773/my_file.user.file&to_format=jpg&w=1920&h=1200 It looks terribly scary. I wonder how to extract from_url=http://195.19.243.13:4773/my_file.user.file argument pair from it and then extract relative file url from that pair value my_file.user.file ?

get the true type prototype vs constructor?

I wanted to see the real type of [] . I always thought that i can use the apply method or the constructor . so i tried : [].constructor ->(showed me) function Array() { [native code] } and [].constructor.constructor ->(showed me) function Function() { [native code] } and Object.prototype.toString.apply([]) ->(showed me) "[object Array]" questions 1) Whom to believe ? 2)why line 2 is different ?

In javascript "If mobile phone"

I was thinking of doing something with the jQuery.browser but this only returns which browser you're in and if its a webkit etc etc. So i basically want to turn off certain js files from even loading if you're on a mobile device? I assume you can do it but how?

Exclude a certain number from this regex

I have this regex that test for an input with max length of 5. My problem is I want to exclude the single digit of 2. If string contains only number "2", it should fail. How do I exclude number 2 in this regex? /^([a-zA-Z,\d]){1,5}$/ 13425 - Match 03277 - Match 2 - Fail.

The best way to write Javascript / jQuery

I'm not new to web dev but I was just wondering if you guys have some advice for me to improve: Always when I write js or jQuery I write all the code like this in the <head> on my page: <script> $(document).ready(function() { //All my functions and animations goes here… }); </script> Now, when I look around the web I see that most people have their functions and animations in a separate ".js"-file. And they often create classes aswell. How does that work? What is the advantage of creating classes and have your functions in a separate file? Thanks, VG

Including base64 gzipped stylesheets/images in javascript?

I know you can include css and images, among other file types, which have been stored in base64 form within a javascript file. However, those are decently huge... and gzipped, they shrink down a LOT, even with the ~33% overhead from base64 encoding. Non-gzipped, images are data:image/gif;base64, data:image/jpeg, data:image/png, and css is data:text/css;base64. What mime type can/should I be using, then, to include css or image data URIs which are gzipped? (Or if gzip+base64 can't work, is there any other compression I can do to bring down the string's size, while still keeping the data stored within the javascript?) ..edit.. I think the question is being misunderstood. I am not asking if I should include gzipped base64 strings within javascript. Yes, I know it's best, in most cases, to gzip the javascript and other files on the server end. But that is not applicable for a userscript; a userscript has no server, and consists of only a single file. Firefox allows a @re

HTML5 JavaScript canvas animation class method called within function

I am having trouble drawing an animation on a HTML 5 canvas inside a loop. I have created a javascript animation function/class that stores frames and duration information and provides a get function to getFrame()[returns image] sub-function to retrieve the relevant frame. This works perfectly fine so i haven't included the full script. If anyone wants or needs it i will send to you. When i call the following code it displays the animation as intended. canvas.drawImage(tile1a.getFrame(),50,60); canvas.drawImage(tile1a.getFrame(),50,90); canvas.drawImage(tile1a.getFrame(),50,120); //etc This isn't very efficient as i want to draw a lot of tiles is column so it would be better to use a for loop. Therefore i tried the following code but the page just keeps crashing. for (i=1;i<=10;i++) { canvas.drawImage(tile1a.getFrame(),FIELD_WIDTH,i*30); } However, i then tried the following which worked: var temp = tile1a.getFrame(); for (i=1;i<=10;i++) {

jQuery JSON to Javascript

I am modifying a jQuery calendar and want to change this code: function getEventData() { var year = new Date().getFullYear(); var month = new Date().getMonth(); var day = new Date().getDate(); return { events : [ { "id":1, "start": new Date(year, month, day, 12), "end": new Date(year, month, day, 13, 30), "title":"Lunch with Mike" }, { "id":2, "start": new Date(year, month, day, 14), "end": new Date(year, month, day, 14, 45), "title":"Dev Meeting" }, { "id":3, "start": new Date(year, month, day + 1, 17), "end": new Date(year, month, day + 1, 17, 45), "title":"Hair cut" }, { "id":4, "start": new Dat

Iframe full height in a wordpress page problems (without scroll bar)

Am trying to get this code <iframe src="http://www.play-asia.com/paOS-38-19-0,,none,0,0,0,0,trans,000000,left,0,0-49-en-76-5-70-dhf7-6-2-78-2i-90-f8z9-33-iframe_banner-40-6-44-100%2525.html" style="border-style: none; border-width: 0px; border-color: #FFFFFF; padding: 0px; margin: 0px; scrolling: vertical; frameborder: 0;" scrolling="vertical" frameborder="0" width="100%25" height="1428"></iframe> To fill the page (height wise) and also without the scroll bar ive tryed and tryed to use css without any luck Anyone have any ideas how/if I do do this? Thanks

how to disable data retrieval on jqgrid load

jqgrid is used to show stock status from server. Data is retrieved in json format using controller in url parameter: url: 'Grid/GetData' Getting data (even 0 rows) takes some time. This causes noticeable delay on page load. How to disable GetData controller call on initial jqgrid load? On initial load empty grid should appear, without rows. Data should retrieved if such command is issued by user: search criteria is entered enter is pressed in search toolbar refresh button in jqgrid toolbar is pressed.

Where and how the iBooks page flipping effects is programmed?

As far as I can read, ibooks format is similar to epub format http://iphoneincubator.com/blog/apple-events/thoughts-on-ibooks-author , a bunch of html/js files. But where/how the page flipping is programmed ? I have downloaded iBooks Author on my mac http://itunes.apple.com/fr/app/ibooks-author/id490152466?mt=12 , when testing on iPad iBooks 2, I can't get this flipping page effect whereas when I download iBooks from official library it has that page flipping effect. So could I modify the html/js generated by iBooks Author by hand to get that effect ? If yes how because I can't find any documentation searching the Internet.

Need help controlling audio object volume in iE8

I'm very much a noob at this but I've got my .wav files playing sound effects and even overlapping when I need them to in Safari, Chrome, IE and FireFox but the only problem I still have is I can't set the volume in IE8. It just plays at the same loud level of the original file. Here is the code I have (with things I've tried commented out). this.load = function( audiofile ) { var i; for ( i=0; i<overlapMax; i++ ) { var object = null; if ( ie8 ) { object = document.createElement('div'); var iesound = ''; // adding volume here didn't do anything // iesound = iesound + '<object id="'+soundID+'track'+i+'" type="audio/x-wav" volume=2 data="'+audiofile+'" width="200" height="16">'; iesound = iesound + '<object id="'+soundID+'track'+i+'&

MVC 3: Communicating between partial view and view via JavaScript

I have a page that lists users (List.vbhtml), and each user has an 'Edit' link. The edit link makes an Ajax request: @Ajax.ActionLink("Edit", "Edit", "Player", New With {.id = currentItem.PlayerId}, New AjaxOptions() with { .UpdateTargetId="edit"}) The Edit method in my controller returns a partial view (_Edit) which contains a form. After the form has been submitted, I want to hide the edit form (not a problem), and then reload the list of users. This is what I am struggling with. How do I let the parent view (List.vbhtml) know I should reload the list (which would be done using a Ajax Get request)? I can't do this from the Edit partial view, because the Edit partial view shouldn't know about the List view, only the other way around (List view knows about the partial view). My current solution is to raise a custom event when the edit is complete in _Edit.vbhtml, and capture it in List.vbhtml: $(document).trigger('Pe

How to make div suddenly show if JavaScript is disabled even if page has already been opened

I know how to display content if JavaScript is disabled, but what I want to do is make a div suddenly appear even if the page is open at the time of JavaScript being disabled. The page is opened. The user goes to browser settings and disables JavaScript. A div shows without refreshing the page. How can I do this? I've seen other sites do this but I looked at their JavaScript files and didn't find anything in it. Thanks in advance!

why is "this&rdquo; pointer scope in javascript restricted?

Scope or visibility of the this pointer which is called w.r.t a div is restricted to the function to which it was intended to and not to its NESTED functions. But,all the local variables of that function are visible in the nested functions -- why does this happen??.. getting the this pointer via calling the function with <function name>(this) on a div -- doesnt this mean even the this pointed also is a local variable in the <function name> In short, here's the code which confused me.. <html> <script type="text/javascript" > function tst1(){ setTimeout( function (){ alert(this.id) }, 2000) } function tst2(){ var elem = this setTimeout( function (){ alert(elem.id) }, 2000) } </script> <style type="text/css"> .test{ margin: 40px 100px; background-color: green; width: 200px; line-height: 40px; text-align: center; height: 40px; } </styl

cooliris.embed.setFeedURL - How to make it work

I am new at javascript, and am trying to make a photo dynanmic wall based upon search criteria. I make the feed xml with php, then need to use the cooliris.embed.setFeedURL to display the photos chosen. I have made too many attempts to put all the code here. Does anyone have a simple example including the script and html that I can model my code on. Here is my last futile attempt: <script type="text/javascript"> var cooliris = { onEmbedInitialized : function() { alert("cooliris.embed is now available"); cooliris.embed.setFeedURL("http://www.properties.com/site/include/temp/11c44b80a6a2f848eb9646b5b3e5df43.xml&numRows=2&showEmbed=false&showChrome=true&style=black"); } } </script> Cooliris displays, no pictures. The feed file works when hardcoded. Thanks for any help.

facebook iframe app; php sdk getUser() returns valid id on page one but not for any other page

I have a facebook iframe app which correctly logs in and authorizes the app, but getUser() only works on the first page. As soon as a user clicks a link to a new page within the iframe, getUser() returns 0. What's strange is that this same code works for another app... I do all the clicking I want and getUser() returns a valid ID. The app that doesn't work: https://apps.facebook.com/celestial_glory/ The one that does (same codebase): https://apps.facebook.com/uprisingstlouis/ Here's the code I am using: require_once ('fb/facebook.php'); // snip... set $app_id, $secret, and $canvas_page // first, try normal facebook getUser(). If that works, awesome. $facebook = new Facebook(array( 'appId' => $app_id, 'secret' => $secret, )); $signed_request = $_REQUEST['signed_request']; // Get User ID $user = $facebook->getUser(); if ($user != '0') return 'fb=' . $user; // works once // getUser() didn't work. Try

Distinguish new vs existing exceptions

I am creating a PHP application and I want to display the number of times an error has occurred. The problem that I am trying to figure out is if an error has already been reported or if its new using the following values: Message (ie: Attempted to divide by zero.) Stack trace (ie: at componentNETapp.Form1.btnTrackExceptionsUn_Click(Object sender, EventArgs e) ...) Source (ie: componentNETapp) Target site (ie: Void btnTrackExceptionsUn_Click(System.Object, System.EventArgs)) Thanks

Some form values not getting submitted after using .replaceWith()

Let's say I have this form: <form action="submit" method="post"> <select name="category" id="categorylist"> <option value="love">Love</option> <option value="magic">Magic</option> <option value="custom">Custom</option> </select> <textarea name="content">SomeContent</textarea> <input type="submit"> </form> I wanted to change the select into an input when I select custom so I came up with this: $(function(){ $('#categorylist').change(function(){ $(this).replaceWith('<input type="text" name="category">'); }); if( $('#categorylist').val() == 'custom' ) $('#categorylist').replaceWith('<input type="text" name="category">'); }); But when the select is changed into an input, $_POST['category'] is

mysql row turning into attributes

I need help with an <input> . Some times when I call for the var to be inserted into the value="" part of the <input> it makes every word into an attribute. For example my tag will look like this <input type="hidden" name="article" this="" is="" the="" article="" text="" /> and the call to the <input> is this echo '<input type="hidden" name="article" value="'.$row['article'].'" />'; below is the actual code CODE: echo '<input type="hidden" name="date_added" value="'.$row['date_added'].'" />'; echo '<input type="hidden" name="id" value="'.$row['id'].'" />'; echo '<input type="hidden" name="article" value="'.$row['article'].'" />'; echo

Needing to expand this regex URL/mail parser a bit further

function make_clickable($text) { $ret = ' ' . $text; $ret = preg_replace("#(^|[\n ])([\w]+?://[\w]+[^ \"\n\r\t<]*)#ise", "'\\1<a href=\"\\2\" >\\2</a>'", $ret); $ret = preg_replace("#(^|[\n ])((www|ftp)\.[^ \"\t\n\r<]*)#ise", "'\\1<a target=\"_blank\" href=\"http://\\2\" >\\2</a>'", $ret); $ret = preg_replace("#(^|[\n ])([a-z0-9&\-_\.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret); $ret = substr($ret, 1); return($ret); } Problems: http://www.google.com , http://www.google.com ; http://www.google.com . http://www.google.com : http://www.google.com ? (http://www.google.com) as well as make sure that other domains lik

Using an array (or xml) to program a function

Ultimate Goal Is to make something like Magento offers - basically a logic builder, and as shown by this post on Stackoverflow: jQuery (or any web tool) Nested Expression Builder So far I have made jQuery to build a tree and get the data that I want the builder to use, check, and set. Now I just need to parse the checks and add it into various places in a script I'm making - but I am unsure how to process it dynamically so that these checks can be performed, which will lead to some actions occurring/data being changed automatically. Maybe we can call this dynamic expression processing? Original Post Forgive me, I know what I would like to do, but have little idea how to do it - so I'm looking for some inspiration. I have allowed a multidimensional array to be generated, and the array would contain certain 'commands' and logic functions, and when a condition is true it is executed. In it's most basic form, the array would contain a set of if statements,

Limiting download speeds with PHP

I have this code here, however i want to limit the speed the user can download at, how would i implement this into this code; header("Content-type: application/force-download"); header("Content-Transfer-Encoding: Binary"); header("Content-length: ".filesize("uploads/$filename")); header("Content-disposition: attachment; filename=\"$origname"); readfile("uploads/$filename"); Thanks! This is what i tried; $download_rate = 100; $origname = get_file_name($file[0]); header("Content-type: application/force-download"); header("Content-Transfer-Encoding: Binary"); header("Content-length: ".filesize("uploads/$filename")); header("Content-disposition: attachment; filename=\'$origname'"); $local_file = "uploads/$origname"; // flush content flush(); // open file stream $file = fopen($local_file, "r"); while (!feof($

Is it possible to have IF statement in an Echo statement in PHP

Thanks in advance. I did look at the other questions/answers that were similar and didn't find exactly what I was looking for. I'm trying to do this, am I on the right path? echo " <div id='tabs-".$match."'> <textarea id='".$match."' name='".$match."'>". if ($COLUMN_NAME === $match) { echo $FIELD_WITH_COLUMN_NAME; } else { } ."</textarea> <script type='text/javascript'> CKEDITOR.replace( '".$match."' ); </script> </div>"; I am getting the following error message in the browser: Parse error: syntax error, unexpected T_IF Please let me know if this is the right way to go about nesting an IF statement inside an echo. Thank you.

imagesx() and imagesy() error when creating tumbnail

I want to create thumbnail image for top posts automaticly. So I decided to resize current image of post with small sizes for using it as tumbnail using this - resize-class.php class and wrote the code like this: // Include the class include("resize-class.php"); $top_posts = mysql_query("In this query I select top posts - the most viewed posts of the day") while ($row = mysql_fetch_array($top_posts)){ $post_id = $row['post_id']; // defining the ID of the post as variable $post_image = $row['post_image']; //defining the image of the post as variable //save image $resizeObj = new resize($post_image); // Initialise - load image $resizeObj -> resizeImage(260, 210, 'exact'); // resizing $post_image with 'exact' option $resizeObj -> saveImage('images/'.$post_id.'.jpg', 80); // saving thumbnail of $post_image to the storage } But returns the errors in loop like this: Warning: imagesx() ex

Posting Data to Amazon using curl

when we enter a keyword (search term) in amazon kindle book store, search brings a list of books back. I am trying to scrap the above said amazon kindle book search, i have some basic/usage idea of CURL in php, but i have never posted variables using curl. I tried at my level. but havent succeeded yet. the only thing i know is i should post "key-word" variable to amazon and should grab the result. The problem with this step is that the key-word is submited to the form and only a part of the page is refreshed everytime key-word is entered. can somebody help me telling the step required? which data i will need to post icluding key-word? how can i know about the header /user agent required for this? what information will be required for this process? which elements will be posted ? I have tried using fiddler but as i am new to it, i am not getting the concepts. The link i want to parse is amazon.com Guideline please, if i get the what need

How to detect Outgoing links (apache,php..)

I'm developing a website, but stuck at some point, where i needed to detect outgoing links on my website, and either forbid the links, or accept that, i don't know how facebook is doing this, but they can do it through facebook.com/l.php that if the link is marked spam, users will get notified about it. I don't know if that's a php or htaccess, it worked in php using the DOMDOCUMENT, but it's not a real solution for this.

Is it preferred to assign POST variable to an actual variable?

I've just completed my registration form for my website and for the action page where all the SQL takes place I've just skipped assigning the POST variable to actual ones, like this... $username = $_POST['username']; Instead I've just been using the POST variables throughout the PHP page. Are there any risks or errors that can be met whilst practicing? Also, excuse me if I am using incorrect terminology...

For loop while parsing xml in php?

I am trying to create a for loop that will parse out different elements of xml doc using php. It parses when I put the number of the entry in the line: $s = $xml->entry[0]->children($namespaces['s']); However I tried to replace the number with "i" to count through each of the entries in the xml doc and I get an error (Fatal error: Call to a member function children() on a non-object in /home/content/c/a/s/cashme/html/buylooper/xml.php on line 10). How do I resolve this? <?php $url = 'xml-file.xml'; $xml = simplexml_load_file($url); $namespaces = $xml->entry->getNameSpaces(true); for ($i = 0; $i <= 10; $i += 1){ $s = $xml->entry[i]->children($namespaces['s']); $title = $s->product->title; //print echo $retailer; } ?>

How do you dynamically set the upload target path when using an AJAX based file uploader?

I'm trying to implement Valum's file uploader (improved by Ben Colon https://github.com/bencolon/file-uploader ) and I'm running into a problem. Previously, my upload.php had the upload target set in accordance to certain input fields. See here: //Directory where files are stored if ($grade == '9') { $target = "storage/g9/"; } elseif ($grade == '10') { $target = "storage/g10/"; } elseif ($grade == '11') { $target = "storage/g11/"; } elseif ($grade == '12') { $target = "storage/g12/"; } $target = $target . $_POST['snumber'] . "." . $extension; move_uploaded_file($_FILES['upload']['tmp_name'], $target); Now, with an AJAX based file uploader it starts uploading before you even hit submit so PHP doesn't get a chance to pickup the input fields to decide what the upload path is going to be, it can only go to a predefined one. To see how the AJAX file uploader does

Omit repeated values in mysql query so the json file has only one of each

This is the query part of my json.php which is the source file of my jquery ui autocomplete input $term = trim(strip_tags($_GET['term']));//retrieve the search term that autocomplete sends $qstring = "SELECT nombre as value FROM ingredientes WHERE nombre LIKE '%".$term."%'"; $result = mysql_query($qstring);//query the database for entries containing the term while ($row = mysql_fetch_array($result,MYSQL_ASSOC))//loop through the retrieved values { $row['value']=htmlentities(stripslashes($row['value'])); //$row['id']=(int)$row['id']; $row_set[] = $row;//build an array } echo json_encode($row_set);//format the array into json data The problem is that file my return result as: [{"value":"one"},{"value":"one"},{"value":"ones"},{"value":"ona"}] So the word will be suggested twice. How can I prevent that?

Undefined Constant MYSQLI_ASYNC - Non blocking queries in PHP

I understand that mysqlnd allows non blocking queries. However, I'm trying: // goes without saying this code works correctly when second parameter is ommitted $link->query($myQuery, MYSQLI_ASYNC); The error I get is:"Notice: use of undefined constant MYSQLI_ASYNC assumed 'MYSQLI_ASYNC' " and ensuing errors. PHP Version: 5.3.5-1 ubuntu7.4 I don't know if I actually have mysqlnd installed/activated, and I can't find a good resource on how to tell if it is. Help?

Determining source of method call at runtime

I'm wondering if there is a "better" way to do this: class Foo { final public function bar() { if (is_subclass_of(get_called_class(), __CLASS__)) { throw new Exception(); } } } class Bar extends Foo { public function baz() { parent::bar(); // shouldn't be allowed } } Essentially, I want certain methods in my parent class to prohibit child classes from calling them. This needs to be bullet-proof, which I doubt this is, so if you know how this could be circumvented, that's what I'm interested in knowing (along with how to prevent it, if possible). Edit: For everyone suggesting private methods, this is not an option, as I need the interface to remain public to be externally accessible. Sorry, I guess I assumed that would be obvious.

Count data from table SQL

my query: "SELECT id FROM user_follow WHERE user_id IN(3,6) AND follow_id NOT IN(3,6) GROUP BY follow_id"; and it show : [users] => Array ( [0] => Array ( [id] => 20 ) [1] => Array ( [id] => 9 ) [2] => Array ( [id] => 19 ) ) I need to count data (in this example query must give back 3 as result) I tried COUNT(id) but result was not good for me. result : [0] => Array ( [count(id)] => 1 ) I tried SELECT count(1) result : [0] => Array ( [count(1)] => 1 ) [1] => Array ( [count(1)] => 2 ) [2] => Array ( [count(1)] => 1 ) Still not not one number (3). I want someth

This function is only working sometimes

function getYoutubeVideoId($url) { $urlParts = parse_url($url); if($urlParts === false) return false; if(isset($urlParts['host']) && strtolower($urlParts['host']) === 'youtu.be') return ltrim($urlParts['path'], '/'); if(isset($urlParts['query'])) { parse_str($urlParts['query'], $queryParts); if(isset($queryParts['v'])) return $queryParts['v']; } return false; } This function works great.. unless you use youtu.be/* without http:// Why does it not work if it is just youtu.be or www.youtu.be ?

How do I select only the root domain from $_SERVER["HTTP_REFERER"];?

I want to have a 404 page that can detect if a user has come to that page either via my site, via my shortened URL or via another site, and I am making it using PHP. I am slowly getting to grips with PHP and this may well be a simple question, but I am quite tired to be honest and have no caffeine in my system, and I am wanting to tie up any loose ends in my portfolio as soon as possible. I have found the $_SERVER['HTTP_REFERER']; PHP variable gives me the entire URL, which is a start. Is there a way that this can give me only the root domain, either via another variable or a function, bearing in mind that some referrers may be using http:// and some https:// (so simply starting from the seventh character would not always work)? That way, I can match the URL based on two (or more) predefined addresses and produce the content that relates to that domain.

Edit mysql record db with php

i am trying to edit a mysql database record , there is seem to be an issue with my code here is the code from page editVisitor.php <? while($row=mysql_fetch_array($result)) { ?> <? $message=stripslashes($row["userUserName"]); $msg_id=$row["useId"]; ?> <li><a href="editUserDetails.php?edit=<?php echo $msg_id; ?>" > <?php echo $message; ?></a> <a href="#" id="<?php echo $msg_id; ?>" class="delete_button">X</a></li> <?php } ?> this is my code in editUserDetails.php that open new page with all fields to update the record : <?php $connection= mysql_pconnect("localhost","root","123") or die (mysql_error()); $db= mysql_select_db("reservebox",$connection) or die (mysql_error()); $selectdata="SELECT * FROM user WHERE useId =" . $edit . "&quo

PHP if else - proper use of "else&rdquo;

A professor told me long ago to use else when "chaining" multiple conditions in a series (I was still learning). Now that I've been tinkering with several frameworks and CMS years later, I find it quite amusing that what I was taught to do isn't necessarily so. I was taught to use else in between a series of conditions: function double(param){ if(param==1){ return param+=1; } else if(param==2){ return param+=2; } else{ return false; } } Nowadays, I seem to see this, which I was warned long ago NOT to do: function double(param){ if(param==1){ return param+=1; } if(param==2){ return param+=2; } return false; } This sample code might not work, but the idea is there: Is it necessary to use else in between every condition? If so (or not so), what should I look out for when using either way? There must be something that caused my professor to tell me such thing.

Is there a way with PHP to access a file on a server and save only the first half of the file?

I want to give users a preview of certain files on my site and will be using scribd API. Does anyone know how I can access the full file from my server and save the file under a different name , which I will then show to users..Can't think of a way to do this with PHP for .docx and image files...Help is much appreciated.

Fetch_array alternative for PHP prepared statements

UPDATE $stmt = $this->db->prepare(" SELECT u.id, u.fname, u.lname, u.mname, u.type, u.email, u.salt, u.pass, u.salt, u.approved, u.ban, u2.status FROM `users` AS u LEFT OUTER JOIN `log` AS u2 ON u2.user_id = u.id WHERE u.email = ? LIMIT 1") or die($this->db->error); $stmt->bind_param("s", $_POST['email']) or die($stmt->error); $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows == 0) { die($this->ajax->respond(7)); } $result = $stmt->get_result(); $data = $result->fetch_array(MYSQLI_BOTH); Trying to fetch array but getting following error for last line Fatal error: Call to a member function fetch_array() on a non-object Can't get it work. Please help