Archive for November 2013

How to Install Zurb Foundation 5

Think most of the people having difficulties to install Zurb Foundation 5. Ruby Error messages, "compass watch" not working etc. etc. I had the same issue last night but solved it myself.

This is a small guide, how to Install Zurb Foundation 5 properly in Windows 7.

1. Install Git

As per Zurb Foundation docs, the 1st thing is you have to install Git.
https://msysgit.googlecode.com/files/Git-1.8.4-preview20130916.exe

When installing, choose the  2nd option. (Run Git from Windows command prompt)

Then, manually set configure the Windows Path as follows. (System->Advanced System Settings->Environment Variables)

C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

This will not harm anything in your system, so no need to worry.

2. Install Ruby

2nd thing as per the Zurb Foundation Docs.
http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-1.9.3-p484.exe?direct
Choose this version rather than the 2.00 or 2.00 64bit version. And if you installed any other Ruby version, uninstall it. (But remember the gems you have installed before)

Next Next Finish :)

3. NodeJs

Pretty straightforward.
http://nodejs.org/dist/v0.10.22/x64/node-v0.10.22-x64.msi


4. Restart PC

Path to npm will set when you install NodeJs.

5. Install Bower

Go to the command prompt and type "npm install -g bower"

6. Uninstall/ Install Foundation

If you uninstall ruby, the foundation gem also gone. But to make sure, try below.

gem uninstall foundation
gem uninstall zurb-foundation

If it said 0 gem uninstalled, then your foundation gem gone. What we have to do here is to install the new foundation as per the docs.

gem install foundation

7. Install Compass

Dont forget to Install Compass too. :)

gem install compass

8. Create Foundation 5 Project

YOUR_PATH> foundation new MY_PROJECT

9. Watch Sass Changes

YOUR_PATH> compass watch

10. Finish

Enjoy Foundation 5. :)
Monday, November 25, 2013
Posted by Anjana Jayaweera

How to submit a form using jQuery, AJAX and PHP

We can submit a form via jQuery, AJAX and PHP from two methods.
1. Data String
2. JSON

Here, Im using the 1st method and it is the easiest.

// link jquery main

$(function() {

// Your Button ID

$("#submit").click(function() {
 
      /* field names */
      var fld1 = $("#fld1").val();
      var fld2 = $("#fld2").val();
      var fld3 = $("#fld3").attr('checked');
      var fld4 = $("fld4 :selected").val(); 

      var dataString = 'fld1=' + fld1 + '&fld2=' + fld2 + '&fld3=' + fld3 + '&fld4=' + fld4 ;
      //alert (dataString);return false;
        
        $.ajax({
          type: "POST",
          url: "./form-submit.php",
          data: dataString,
          success: function(html) {
             var trimmed = trim(html); 
             if(trimmed == 'success') {
                /* Do what you want to do when its success */
            } else {
                /* Error Message */
            }
          }
        });
        return false; 
    });
});



Here I used a very simple method to post data into PHP. Now lets look at the "form-submit" file

$fld1 = $_REQUEST['fld1'];
$fld2 = $_REQUEST['fld2'];
$fld3 = $_REQUEST['fld3'];
$fld4 = $_REQUEST['fld4'];


/* MySQL Insert commands. At the end, echo "success"; */

echo "success";

Why echo Success?
That is the command we are giving for jQuery file saying that the operation did successfully. If form-submit returned a string different than 'success', then its an error.

PS : in jQuery file, i commented "alert (dataString);return false;". You can uncomment this and see whether your dataString is correctly passing or not. coz of return "false", it will not proceed to ajax call. :)

On a later day, lets see how to achieve this via JSON. :)
Sunday, November 10, 2013
Posted by Anjana Jayaweera

How to read folder names/ file names in PHP

1. How to read folder name in PHP

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

/* Do your magic here */

echo $foldername;

}
Don't forget to add '/*' after your folder name
2. How to read file names in a folder in PHP

$folderpath = "./FOLDER-NAME/*.*";

foreach(glob($folderpath) as $filename){

/* Do your magic here */

echo $filename;

}
Don't forget to add '/*.*' after your folder name

Might you will complain that it is reading the whole path, not the folder/ filename you want to get at the end. So follow this trick. :)

$folderpath = "./FOLDER-NAME/*";

foreach(glob($folderpath, GLOB_ONLYDIR) as $foldername){

$newFolderName = str_replace("./FOLDER-NAME/", '', $foldername);

echo $newFolderName;

}
TaDa !!!!
Thursday, November 7, 2013
Posted by Anjana Jayaweera
Tag : ,

How to use the same MySQL query again and again

Actually, what we going to do is to move the internal row pointer to re-query. For this, Im going to use the mysql function mysql_data_seek().


The internal row pointer is the current row position in a result returned by the mysql_query() function.

$sql    = "SELECT * FROM tbl_data";
$result = mysql_query($sql,$con);

while ($row = mysql_fetch_array($result)) {
   /* Show your data here*/
}

/* Call the result info again*/

mysql_data_seek($result,0); 

//  you can change the 0 into any number. From this, it will control from which row number you want to start the query again.

while ($row = mysql_fetch_array($result)) {
   /* Show your data for the 2nd time */
}
Tuesday, November 5, 2013
Posted by Anjana Jayaweera
Tag : ,

Popular Post

Blogger templates

Labels

- Copyright © My Code Genius by 2 Geniuses -Metrominimalist- Powered by Blogger - Designed by Johanes Djogan -