Search This Blog

22 October 2021

PHP ARRAY

 GROUP BY ARRAY AND INCLUDE ROW VALUES TO THIS ARRAY

 public function getProducts($id='')

{

$this->db->select("pi.image as image,p.product_name,p.id as productId,p.product_code,p.price,p.product_size,c.c_name as category_name,p.status");
$this->db->from("products as p");
$this->db->join('product_images as pi','pi.product_id=p.id','left');
$this->db->join("category as c", "c.id=p.category_id", "left");
$this->db->where('p.status', 1);
    if(!empty($id)){
        $this->db->where('p.id',$id);
      }
$results = $this->db->get()->result();
$productArray = $imageArray = array();
        foreach($results as $key=> $row)
 
{
                 $productId = $row->productId;
                  if (!isset($productArray[$productId])) {
                 $productArray[$productId] = (array) $row;
                 $productArray[$productId]['images'] = [];
             }
           $productArray[$productId]['images'][] = $row->image;
}
return $productArray;
}


   OutPut :



GROUPBY ARRAY LIKE CATEGORY


foreach($permissions as $row)
{
   
    $name = $row['name'] ?? 'N/A';

    $categoryArray[$name][] = $row;

    if (!isset($
categoryArray[$name])) {
       $
categoryArray[$name] = [];
     }

}

Output : like 

Fruits:
    0->Apple
    1->orange
    2->mango
Flowers:
   0->jasmine
   1->sunflower


 

08 September 2021

Node JS using CRUD with MySql

 

Node JS

 

Node js Using CRUD Operation With Mysql DB

Prerequisites:

1.     Nodejs

2.     Expressjs

3.     Mysql

4.     EJS

5.     Body Parser

Steps:

·        Create Directory Mkdir node_crud

·        Npm init –y  Type this command automatically  Created Package.json

·        Then Install Dependencies

·        Npm install –save express ejs body-parser mysql nodemon

·        Switch root directory create index.js or else whatever you want file name

·        Write some codes in index.js file

 

Index.js:

const express=require('express');

const mysql=require('mysql');

const bodyparser=require('body-parser');

const ejs=require('ejs');

const path=require('path');

const session = require('express-session');

const app = express();


const conn=mysql.createConnection({

    host:'localhost',

    username:'root',

    password:'',

    database:'test'

});


conn.connect(function(error){

if(!error){

console.log("conncetion succesfully");

}else{

    console.log(error);

}

})



app.set('views', path.join(__dirname, 'public'));

app.set('view engine','ejs');

app.use(bodyparser.json());

app.use(bodyparser.urlencoded({ extended: false }));


app.use(session({secret:"Helloworld@123;"}));



app.get("/",(req,res)=>{

    var sql="select * from booking";

   // var cnt=req.session.cnt++;

    var query=conn.query(sql,(err,rows)=>{

        res.render('index',{           

            data:rows,

           //pagecnt:cnt

        });

    });


})


app.get("/signup",(req,res)=>{

    res.render('signup');

    })



app.get("/login",(req,res)=>{

res.render("login");

});


app.post("/authenticate",(req,res)=>{

var name=req.body.title;

var no=req.body.mobile_no;

var sql="select * from booking where Title='"+name+"' and mobile='"+no+"'";

var query=conn.query(sql,(err,result)=>{

    if(result.length > 0 ){

req.session.username=name;        

res.send("Valid Credentials welcome Mr/Ms  "+req.session.username); 

    }else{

        res.send("Not Valid Credentials");

    }

})

});


app.post("/register",(req,res)=>{

var title=req.body.title;

var mobile=req.body.mobile_no;

var start=req.body.start;

var end=req.body.end;

var sql="insert into booking values(NULL,'"+title+"','"+mobile+"','"+start+"','"+end+"')";

var query=conn.query(sql,(err,result)=>{

    res.redirect("/");

})


});





app.post("/update",(req,res)=>{

    var title=req.body.title;

    var mobile=req.body.mobile_no;

    var start=req.body.start;

    var end=req.body.end;

    var id=req.body.id;

    var sql="update booking set Title='"+title+"',mobile='"+mobile+"',Start='"+start+"',End='"+end+"' where Id='"+id+"'"

   

    var query=conn.query(sql,(err,result)=>{

        res.redirect("/");

    })

    

    });


app.get("/edit/:id",(req,res)=>{

var id=req.params.id;

var sql="select * from booking where Id='"+id+"'";

var query=conn.query(sql,(err,records)=>{

    res.render("edit",{

        user_details:records

    })

    //res.send(records);

})

});


app.get("/delete/:id",(req,res)=>{

 var id=req.params.id;

 var sql="delete from booking where Id='"+id+"'";

var query=conn.query(sql,(err,results)=>{


res.redirect("/");

});

});



app.listen(2000,()=>{

    console.log("running");

})

// HTML files

Index.ejs:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>

    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>

    

</head>

<body>


    <div class="container">

        <h2 class="text-center">Crud Using Nodejs</h2>

        <br>

        <br>

        

        <a href="/signup" class="btn btn-success">Register</a>

        <a href="/login" class="btn btn-info">Login</a>

        <table class="table table-responsive table-striped">

          <thead>

            <tr>

              <th>Title</th>

              <th>Mobile</th>

              <th>Start</th>

              <th>End</th>

              <th>Action</th>

              <th>Action</th>

            </tr>

          </thead>

          <tbody>

            <% data.forEach(function(row){%> 

            <tr>

              <td><%= row.Title %></td>

              <td><%= row.mobile %></td>

              <td><%= row.Start %></td>

              <td><%= row.End %></td>

              <td><a href="/edit/<%= row.Id %>" class="btn btn-info">Edit</a></td>

              <td><a href="/delete/<%= row.Id %>" class="btn btn-danger">Delete</a></td>

            </tr>

            <% }); %>

          </tbody>

        </table>

      </div>

      

   

    

        

    

</body>

</html>


Register.ejs:

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap Example</title>

  <meta charset="utf-8">

 

</head>

<body>


<div class="container">

  <h2>Signup form </h2>

  <form action="/register" method="post">

    <div class="form-group">

      <label for="email">Title:</label>

      <input type="text" class="form-control" id="email" placeholder="Enter Title" name="title">

    </div>

    <div class="form-group">

      <label for="pwd">Mobile:</label>

      <input type="number" class="form-control" id="pwd" placeholder="Enter Mobile" name="mobile_no">

    </div>

     <div class="form-group">

       <label>Start</label> 

       <input type="date" name="start" class="form-control" />

     </div>

     <div class="form-group">

        <label>End</label> 

        <input type="date" name="end" class="form-control" />

      </div>

    <button type="submit" class="btn btn-primary">Submit</button>

  </form>

</div>


</body>

</html>


Edit.ejs:

<!DOCTYPE html>

<html lang="en">

<head>

  <title>Bootstrap Example</title>

  <meta charset="utf-8">


</head>

<body>


<div class="container">

  <h2>Update form </h2>

  <form action="/update" method="post">

    <div class="form-group">

      <label for="email">Title:</label>

      <input type="hidden" name="id" value="<%= user_details[0]['Id'] %>" />

      <input type="text" value="<%= user_details[0]['Title'] %>" class="form-control" id="email" placeholder="Enter Title" name="title">

    </div>

    <div class="form-group">

      <label for="pwd">Mobile:</label>

      <input type="number" value="<%= user_details[0]['mobile'] %>" class="form-control" id="pwd" placeholder="Enter Mobile" name="mobile_no">

    </div>

     <div class="form-group">

       <label>Start</label> 

       <input type="date" name="start" value="<%= user_details[0]['Start'] %>"  class="form-control" />

     </div>

     <div class="form-group">

        <label>End</label> 

        <input type="date" name="end" value="<%= user_details[0]['End'] %>" class="form-control" />

      </div>

    <button type="submit" class="btn btn-primary">Publish</button>

  </form>

</div>


</body>

</html>



File Directory Structure:
       Root
          Node_modules
          index.js
          package.json
          Public
               edit.ejs
              index.ejs             
              register.ejs
              
Then Run Node index.js

 

 

 

 

 

 

09 December 2019

Publishing Android App in Google PlayStore Ionic

Publishing Android Application In Google Playstore


first step release the build App  Open the  Command Prompt the change directory for your project directory and Switch your Ionic project App Directory 

second step you need to add android platform to add and run the command in command prompt it will take some times reason for download the repository the if you want to check if platform automatically added under project Directory 

$ionic cordova platform add android

third step you create  unsigned APK  or release apk  open command prompt run this command it will take some time

$Ionic Cordova build android –prod –release

fourth step You will  Create Keystore file --> open the command prompt 

Run this Command

$keytool -genkey -v –keystore your_keystore_name.keystore -alias alias_name -keyalg  RSA -keysize 2048 -validity 10000

Sign the unsigned apk with jarsigner tool  run this command prompt

$jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore your_keystore_name.keystore  platforms\android\app\build\outputs\apk\release\  app-release-unsigned.apk alias_name

Zip Align tool is used to optimize the APK

this zipalign tool is located your appdata/local/android  sdk build tools so exaple my 
directory path :

C:\Users\test\AppData\Local\Android\sdk\build-tools\27.0.1\Zipalign.exe  copy this zipalign.exe its a execute java file Then paste into your Ionic project  Directory
(or) another method is available for zipalign command copy this "C:\Users\test\AppData\Local\Android\sdk\build-tools\27.0.1\Zipalign.exe" path 
right click the computer select the properties open the window select advanced system setting open the popup select the tab for advanced then click the environment variables button select path --> edit paste it the path then okie save it then check run the command for zipalign its working fine this method is permanently 


$zipalign -v 4 platforms\android\app\build\outputs\apk\release\app-release-unsigned.apk your_app.apk


Google play console case $25 USD

Click Create Application   and Fill the Description of App and Providing Screen Shots and Additional Info then Upload the signed APK that was generated  and Publish the App

 


Jquery or Javascript Start Exam Time

 <script> function startTimer() {      var date = "<?php echo $date ?>"; // dynamic date      var time = "<?...