Featured Post Today
print this page
Latest Post

Slug Create Function in PHP. URL Rewriting According to SEO Rules

SEO friendly Slug is very important in Search Engine Optimization. It is used to rewrite your URL as your title.
as if you write title: "My Name Is Sami" And if it is a page. Then
Its URL will be :
www.QWC.me/?page=1 [1 Is Page ID]

If you use title in URL it can be like it
www.QWC.me/?page=my20%name20%is20%sami

But if you use slug function: URL will be SEO friendly like

www.QWC.me/?page=my-name-is-sami

There are many function: I am going to add 2 good functions for it. there is no any personal PHP built in function.

1:
 function slug($str, $replace=array(), $delimiter='-')  
      {  
           if( !empty($replace) )  
      {  
           $str = str_replace((array)$replace, ' ', $str);  
      }  
           $clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);  
           $clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $clean);  
           $clean = strtolower(trim($clean, '-'));  
           $clean = preg_replace("/[\/_|+ -]+/", $delimiter, $clean);  
           $clean = form_validation($clean);  
           return $clean;  
 }  


2:
 function slug2($string){  
   $slug=preg_replace('/[^A-Za-z0-9-]+/', '-', $string);  
   return $slug;  
 }  
0 comments

Get Row Data in Tables from MySQL

This small code is used by Pakistan Floor Mills. Here you can easily understand that how to show rows data from your database to your table in front end.
Use it and learn from it.

insert data form
This code will tell you how to get data from array and how to show in fields.
Setup a database connection with following code.
 -- phpMyAdmin SQL Dump  
 -- version 4.0.4  
 -- http://www.phpmyadmin.net  
 --  
 -- Host: localhost  
 -- Generation Time: Nov 12, 2013 at 06:49 PM  
 -- Server version: 5.6.12-log  
 -- PHP Version: 5.4.16  
 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";  
 SET time_zone = "+00:00";  
 /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;  
 /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;  
 /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;  
 /*!40101 SET NAMES utf8 */;  
 --  
 -- Database: `asia`  
 --  
 -- --------------------------------------------------------  
 --  
 -- Table structure for table `test`  
 --  
 CREATE TABLE IF NOT EXISTS `test` (  
  `sno` int(4) NOT NULL,  
  `packing` varchar(20) NOT NULL,  
  `weight` int(4) NOT NULL  
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;  
 --  
 -- Dumping data for table `test`  
 --  
 INSERT INTO `test` (`sno`, `packing`, `weight`) VALUES  
 (1, 'Ghee 16 kgs', 16),  
 (2, 'Ghee 10 kgs', 10),  
 (3, 'Ghee 5 kgs', 5);  
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;  
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;  
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;  

phpmysql
See this SQL file Image
Get Row Data in Tables from MySQL
Now when you press this button results should be here. like that
code is here check it.

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>BROWSE DATA </title>

 <style type="text/css">
 
 html {
 overflow:auto;
 }
 
 body {
 background-color:#FFFFFF;
 margin:0 auto;
 }
 
  
 #mypopup2
 {
 float: left;
 width: 250px; height: 350px;
 background: #90bade; 
 border: 1px solid #069;
 text-align:center;
 padding:2px;
 margin-top:150px;
 margin-left:50px;
 overflow:auto;
 }
 
 
 #header
 {
 background-color:#3399FF;
 background-position:left center;
 line-height:25px;
 font-size:22px;
 color:#FFFF33;
 font-weight:600;
 border-bottom:1px solid #6699CC;
 padding:10px;
 }
 
 .design12 {
 background-image:url(Images/disk.png);
 background-position:left center;
 background-repeat:no-repeat;
 background-color:#FF9;
 border:1px solid #88de85;
 -webkit-border-radius:7px;
 -moz-border-radius:7px;
 font-size:15px;
 font-weight:700;
 font-family:verdana;
 color:#0d5f83;
 width:100px;
 cursor:hand;
 padding:9px;
 }
 
 .design13 {
 background-image:url(Images/reload_16.png);
 background-position:left center;
 background-repeat:no-repeat;
 background-color:#CF9;
 border:1px solid #88de85;
 -webkit-border-radius:7px;
 -moz-border-radius:7px;
 font-size:15px;
 font-family:verdana;
 font-weight:700;
 color:#0d5f83;
 width:100px;
 cursor:hand;
 padding:9px;
 }
 
 
 .txt
 {
 width:150px;
 font-family:Arial, Helvetica, sans-serif;
 font-size:14px;
 font-weight:300;
 }
 
 td
 {color:#6600CC;}
 
 </style>
    
    <!-- PHP Code START -->

<?php 

 if(isset($_POST['submit']))
 {
  // Connection variables 
  $host="localhost"; 
  $username="root"; 
  $password=""; 
  $db_name="asia";  
  
  // Connect to database 
  $con = mysqli_connect($host, $username, $password); 
  
  // Connect result 
  if(!$con)
  { 
   die('Error Connecting to Database: ' . mysqli_connect_error()); 
  } 
  
  // Database Selection 
  $sel = mysqli_select_db($con, $db_name); 
  
  // Database Selection result 
  if(!$sel)
  { 
   echo ('Error selecting Database: ' . mysqli_connect_error()); 
  } 

    $query  = 'select * from test';
      $result = mysqli_query($con, $query);
    $count = mysqli_num_rows($result);
    $row = mysqli_fetch_array($result);  
    
   if(!$result)
    echo 'select query error or data not found'; 

   }  
   else
   {
 $i = '';
 $count = '';
  $row = array('sno' => '', 'packing' => '', 'weight' => '');
   }
   ?>
 <!-- PHP Code END -->

 </head>
 
 <body>

 <div id="mypopup2" >
 <div id="header"><img src="Images/book_open.png" align="left">Browse Data</div>
 <div style="margin-top:10px;">

 <form name="form1" method="POST" action="#">
 
 <table border="1" cellpadding="1" cellspacing="1" bgcolor="silver" align="center" width="95%" >
    
 
 <th width="20%">Code</th>
 <th width="50%">Product</th>
 <th width="20%">Weight</th>
    <?php 
  if(isset($_POST['submit']))
  {
   $i = 1;
   while($i <= $count)
    {
       echo"<tr>";
     echo "<td>" . $row['sno'] . "</td>";
     echo "<td>" . $row['packing'] . "</td>";
     echo "<td>" . $row['weight'] . "</td>";
     echo "</tr>";
     $row = mysqli_fetch_array($result); 
     $i++;
    } 
  }


   echo "</table><br>";

 ?>
 </table>
 

 <div style="margin-top:125px;text-align:center;margin-top:100px;">
    <input type="submit" name="submit" value="Brow" class="design12">
 <input type="submit" name="button2" value="Clear" class="design13">
    </div>
 </form>
 </div>
 </div>
</body>
</html>

Result Output is :
Get Row Data in Tables from MySQL

Now it is your turn read this code, understand it and align it yourself by using great CSS skills.
0 comments

Echo Rules / Problems in PHP Language

Echo is used to show output results in PHP. But sometimes you get confuse for solving simple problems. like

How to add Conditional Statement within echo statement?
 It is wrong to use if conditional statement within echo statement. You should use ternary operator within echo statement. like
 echo '<li' . ($sel_subject == $subject['id']) ? 'class="selected"' : '' . '>';  

Can we use echo statement within echo statement?
No we can not use echo statement within echo statement. It is bad logic. 

Can we use echo with double or single quotes?
Yes; you can use  echo with double and single quotes like

 echo 'This is Quality Written Codes Blog';  
Output is : This is Quality Written Codes Blog

 echo "This is Quality Written Codes Blog";  
Output is : This is Quality Written Codes Blog

What is concatenation in echo statement? 
Concatenation is sued to connect two quotes blocks. like 

 echo "My Blog Name is " . "Quality Written Codes";  

" . " dot is used to add concatenation.

How to use backslash within echo?
There are two ways to use backslash within echo tag.

You can use single quote if you want to use backslash; like it

 echo 'This is Quality Written Codes Blog And My Name is \ Samee Ullah Feroz \';  
Its output is
This is Quality Written Codes Blog and My Name is \ Samee Ullah Feroz \

If you use double quotes for echo statement. then you need to remember this solutions.
  1. \/ => /
  2. \" => "
  3. \/\/ => //
 echo "This is \"Quality Written Codes\" Blog and my name is \\ Samee Ullah Feroz \\";  
Its output is 
This is Quality Written Codes Blog and My Name is \ Samee Ullah Feroz \

How to use Variables within and with echo?
You can use different methods for it. like 

 $blog = "Quality Written Codes";  
 echo "$blog";  
 echo '{$blog}'  
 echo $blog;  

Read More about it in our previous post : Display of Variables
0 comments

1st PHP, My SQL Project : Blue Prints

Wednesday: 06, Nov, 2013:

/* This section was for Front End */
I created style sheet file and ads my rule.
I checked every piece of code and its different results in Chrome. Chrome is good for codes checking. with F12 Feature => Chrome DevTools.
I started my project with tables. That I can easily make my mind for it.
I created front end 1st of all, with public.css file.

/* This Section was for Back End */
I created a 3 folders in main directory.
  1. includes
  2. stylesheets
  3. images 
  4. javaqueries
I created constants.php file.
I created connection.php file
I created header.php file
I created footer.php file
I created functions.php file

These was separate files. I divided this project in parts.

Wednesday: 07, Nov, 2013:

/* Server Side Work */
Today I worked on #MySql Database. I created widget_corp database and create 3 tables,
Subjects Table
Pages Table
Users Table

I add some values in all above tables. Like
For Subject:
  1. ID
  2. Name
  3. Position
  4. Visible

For Pages:
  1. ID
  2. Name
  3. Subject_id (Subject_id is related to subject table id)
  4. Position
  5. Content

Now I added some values in Pages

/* Back End PHP working */
/* Navigation Work */
Now I need work on navigation. I write a query and call this query in ascending order by position.
then I add a while loop and call to subjects in navigation.
Then i write a query for pages and call them order by position.
then I add an other while loop within pages tags and call them by subject_id.

Saturday: 09, Nov, 2013:
/* Navigation Work */
I worked on bold option. I fetching data from SQL.
I worked on URL : that i can fetch data from there.


/* Body Parts */
I converted all data to functions that i can use variables properly.
Now I create php page for create subjects and create pages.
I am working on that now.

0 comments

Online Database Creation PHP Code with SQL Contribution

Now you don't need to browse PHPMyAdmin for creating database user password by database wizard. You just need to upload this files on your server and create database automatically.

1st file is style sheet file. : stylesheet.css

 @charset "utf-8";  
 /* CSS Document for : http://www.QWC.Me */  
 #dbcreation{padding-left:30%; padding-right:30%; padding-top:10%; padding-bottom:20%;}  
 table{border-top-left-radius:25; border-top-right-radius:25;}  
 th{text-align:center; background-color:#999;}  
 table, th, td, tr, thead, tbody{padding: 10px;}  
 a{text-decoration:none;}  
 .error{color:red;}  
 #dbinstall{border:10; border-color:#999; border-top-left-radius:25; border-top-right-radius:25; border-bottom-left-radius:25; border-bottom-right-radius:25; padding-left:30%; padding-right:30%; padding-top:10%; padding-bottom:20%;}  
 #signupform{text-shadow:#999; padding-left:30%; padding-right:30%; padding-top:10%; padding-bottom:20%;}  

2nd file is Database Values Taken File : create_database.php

 <?php  
      session_start();  
 ?>  
 <!DOCTYPE html >  
 <html xmlns="http://www.w3.org/1999/xhtml" lang="us-en">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <link rel="stylesheet" href="css/stylesheet.css" />  
 <title>Database Creation Process</title>  
 </head>  
 <body>  
   <div id="dbcreation">  
     <table align="center">  
          <thead>  
            <tr><th colspan="2" align="center">Enter Database Detail</th></tr>  
       </thead>  
       <tbody>  
         <form action="install.php" method="post">  
         <tr><td><label id="host">Host: </label></td><td><input type="text" name="host" placeholder="i.e. locahost" required="required" /></td></tr>  
         <tr><td><label id="dbname">Database Name: </label></td><td><input type="text" name="dbname" required="required" /></td>  
         <tr><td><label id="dbuname">User Name: </label></td><td><input type="text" name="dbuname" placeholder="i.e. root" required="required" /></td>  
         <tr><td><label id="dbpass">Password: </label></td><td><input type="text" name="dbpass" required="required" /></td>  
         <tr><td colspan="2" align="center"><input type="submit" name="submit" Value="Create" required="required" /></td></tr>  
         </form>  
       </tbody>  
     </table>  
   </div>   
 </body>  
 </html>  


3rd file is Database installation file : install.php

 <?php  
      session_start();  
 ?>  
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
 <html xmlns="http://www.w3.org/1999/xhtml">  
 <head>  
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
 <link rel="stylesheet" href="css/stylesheet.css" />  
 <title>Database Installation Process</title>  
 </head>  
 <body>  
 <div id="dbinstall">  
   <?php       
                //Get values from create_database.php files  
                if(isset($_POST['submit']))  
                {  
                     echo '<form method="post">  
                     <input type="hidden" name="host" value="'.$_POST['host'].'">  
                     <input type="hidden" name="dbname" value="'.$_POST['dbname'].'">  
                     <input type="hidden" name="dbuname" value="'.$_POST['dbuname'].'">  
                     <input type="hidden" name="dbpass" value="'.$_POST['dbpass'].'">  
                     <input type="submit" name="install" value="Install" align="center">  
                     </form><br/>';   
                     echo 'Welcome to installation process....<br/>  
                     Click install Button to install database.....<br />';  
                }                 
                //if user click on install button then install database on site  
                if(isset($_POST['install']))  
                {            
                     $dbhost = $_POST['host'];  
                     $dbname = $_POST['dbname'];  
                     $dbuname = $_POST['dbuname'];  
                     $dbpass = $_POST['dbpass'];  
                     //connect to mysql server for connecting server : need to give local host and user name  
                     $connect = mysqli_connect($dbhost, 'root');                 
                     //database creation.   
                     $db_create_query = "Create database " . $dbname;  
                     $database = mysqli_query($connect, $db_create_query);  
                     //database creation query error show  
                     if(!isset($database))  
                          {  
                               die("<div class=\"error\">Database creation query error : " . mysqli_connect_error() . "</div>");  
                          }  
                     //database users password query creation  
                     $dbuserpass = "create user " . $dbuname."@".$dbhost. " identified by '".$dbpass."'";  
                     $dbuserpass2 = mysqli_query($connect, $dbuserpass);  
                     //database users password query Error  
                     if(!isset($dbuserpass2))  
                          {  
                               die("<div class=\"error\">Database Username Password query error : " . mysqli_connect_error() . "</div>");  
                          }  
                     //give grant privileges to database user pass  
                     $previleges = "GRANT ALL PRIVILEGES ON $dbname. * TO '$dbuname'@'$dbpass' WITH GRANT OPTION";  
                     $previleges2 = mysqli_query($connect, $previleges);  
                     //check previleges error  
                     if(!isset($previleges2))  
                          {  
                               die("<div class=\"error\">Database Username Password query error : " . mysqli_connect_error() . "</div>");  
                          }                      
                     else  
                          {  
                               echo "Database has been created successfully<br />  
                                         Database Name :" . $dbname. "<br /> Database User Name : ".$dbuname."<br /> Database Password : ".$dbpass;  
                          }  
                }  
                session_destroy();  
      ?>  
 </div>  
 </body>  
 </html>  


I hope you will learn from it. copy code and check it

0 comments
 
Copyright © 2011-2026. Samee Articles - All Rights Reserved
Proudly powered by Blogger