Jump to content

684425

Members
  • Posts

    66
  • Joined

  • Last visited

Posts posted by 684425

  1. Thank you for your reply.

    For some invalid URLs i have created a class in php

    class Bootstrap{
    	private $controller;
    	private $action;
    	private $request;
    
    	public function __construct($request){
    		$this->request = $request;
    		if($this->request['controller'] == ""){
    			$this->controller = 'home';
    		} else {
    			$this->controller = $this->request['controller'];
    		}
    		if($this->request['action'] == ""){
    			$this->action = 'index';
    		} else {
    			$this->action = $this->request['action'];
    		}
    	}
    
    	public function createController(){
    		// Check Class
    		if(class_exists($this->controller)){
    			$parents = class_parents($this->controller);
    			// Check Extend
    			if(in_array("Controller", $parents)){
    				if(method_exists($this->controller, $this->action)){
    					return new $this->controller($this->action, $this->request);
    				} else {
    					// Method Does Not Exist
    					echo '<h1>Method does not exist</h1>'; // This line can be changed, redirect to a method that exists
    					return;
    				}
    			} else {
    				// Base Controller Does Not Exist
    				echo '<h1>Base controller not found</h1>'; // This line can be changed, redirect to a base controller that exists
    				return;
    			}
    		} else {
    			// Controller Class Does Not Exist
    			echo '<h1>Controller class does not exist</h1>'; // This line can be changed, redirect to a controller class that exists
    			return;
    		}
    	}
    }

    For the rest of invalid URLs an error message "Not found is thrown". I am thinking of handling this via htaccess because i am failed to find a solution for handling this via php.

  2. I have URLs of my project on my localserver like localhost/shareboard/users/login in which (users is my sub directory and login is php file named login.php)

    I am already using the following htaccess rules for this

    Options +FollowSymLinks
    RewriteEngine on
    RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

    Is there a way of removing sub directory only from URLs without changing above htaccess? or some other idea that gives result as localhost/shareboard/login

    (In my php code i am using the above address in hyperlinks as

    <a href="<?php echo ROOT_URL; ?>users/login">Login</a>

    And the following lines are added in my config.php file

    define("ROOT_PATH", "/shareboard/");                // I am using this one for linking files
    define("ROOT_URL", "http://localhost/shareboard/"); // and using this one in hyperlinks

    Please guide me if there is a possible solution for what I want to do. Thanks🙂

  3. Following a tutorial on udemy, i tried to learn the very basics of mvc structure. I built the same project on my local server and it worked without giving me any error. but when i tried it on live server. its not working as it should. not showing any error. I tried to figure out the problem and found that for every page loading, it stops at the same line in my main.php file.

    <?php require($view); ?>

    starting from the above line. it stops. i came here to share my problem but i am unable to upload my files here. if there is a way to upload and share my files, please guide. zip file size of the whole project is 31.6 kb

  4. I have created a session array on one page and stored some values as

    $_SESSION['users'] = array(
      "id"      => $row['id'],
      "fname"   => $row['ufname'],
      "lname"   => $row['ulname']
    );

    and then on another page I have some more values for the same session array

      "boss"      => $row['bossid'],
      "tasks"     => $row['tasks'],
      "timeframe" => $row['tframe']

    I want to add these values into session array both keys and values.

    is there any way of doing this? Please help

  5. I have date stored in database in any of the given forms 2020-06-01, 2020-05-01 or 2019-04-01

    I want to compare the old date with current date 2020-06-14

    And the result should be in days.

    Any help please?

    PS: I want to do it on php side. but if its possible to do on database side (I am using myslq) please share both ways🙂

  6. 7 hours ago, Barand said:

    If you don't want to take our advice, you could resort to 

    
    SELECT h1.emp_id
         , h1.pay
         , h1.hours1
         , h2.hours2
         , h3.hours3;
    SELECT *
    FROM 
        (
            SELECT e.emp_id
                 , e.pay
                 , ot.hours1 as hours
            FROM employeex e
                 JOIN
                 employeex e2 ON e.time1 = e2.emp_id
                 JOIN
                 overtimex ot ON e2.grade = ot.rank
        ) h1
        JOIN
         (
            SELECT e.emp_id
                 , e.pay
                 , ot.hours2
            FROM employeex e
                 JOIN
                 employeex e2 ON e.time2 = e2.emp_id
                 JOIN
                 overtimex ot ON e2.grade = ot.rank
        ) h2 ON h1.emp_id = h2.emp_id
        JOIN
         (
            SELECT e.emp_id
                 , e.pay
                 , ot.hours3
            FROM employeex e
                 JOIN
                 employeex e2 ON e.time3 = e2.emp_id
                 JOIN
                 overtimex ot ON e2.grade = ot.rank
        ) h3 ON h1.emp_id = h3.emp_id
     WHERE h1.emp_id = 67;  

     

    Sir, I am following your advice. I have normalized my database and now I am working on app to remove errors that is why my reply is late🙂

  7. SELECT
        tbl1.pay AS bpay,
        tbl2.grade AS t1,
        tbl3.grade AS t2,
        tbl4.grade AS t3,
        tbl5.hours1 AS d1,
        tbl6.hours2 AS d2,
        tbl7.hours3 AS d3
    FROM
        employees AS tbl1
    LEFT JOIN employees AS tbl2
    ON
        tbl1.time1 = tbl2.id
    LEFT JOIN employees AS tbl3
    ON
        tbl1.time2 = tbl3.id
    LEFT JOIN employees AS tbl4
    ON
        tbl1.time3 = tbl4.id
    LEFT JOIN overtimes AS tbl5
    ON
        tbl2.grade = tbl5.ranks
    LEFT JOIN overtimes AS tbl6
    ON
        tbl3.grade = tbl6.ranks
    LEFT JOIN overtimes AS tbl7
    ON
        tbl4.grade = tbl7.ranks
    WHERE
        tbl1.id = 67

    The above query returns result including red highlighted values which I am trying to remove

    Tables.png

  8. From tables shown in image, I am trying to run a query for employee 67 which return only one row containing id, pay from employee table and from overtime table i want to choose values from columns hours1, hours2, hours3 based on references mentioned in employees table. I have highlighted the values in both tables for which i want to run the query.

    Tables.png

  9. 16 hours ago, benanamen said:

    Op, you would do better to separate the first and last names into their own columns. A simple use case example for using only the last name would be the intro to a letter. As is, you would have to do some code gymnastics just to get the last name only.

    
    Dear Mr. Doe, 

     

    I was not sure whether i should separate them or not, but after your advice i separated them 🙂

  10. 19 hours ago, Barand said:

    Join the table to itself

    
    SELECT emp.name as empname
         , boss.name as bossname
    FROM employee as emp
         LEFT JOIN
         employee as boss
    ON emp.boss_id = boss.id;

     

    Sir, your query worked as expected but last day after posting my problem here i searched for the solution. From w3schools i found one example in SELF JOIN.

    SELECT A.fname AS yourname,
           B.fname AS yourbossname
    FROM employee A,
         employee B
    WHERE A.boss_id = B.id

    Not challenging your knowledge and your experience but just for increasing my knowledge. Do both LEFT JOIN and SELF JOIN are same in working or is there any difference in both?

    PS: if its up to you, which one you would like to prefer?🙂

  11. I have an employees table which stores id as auto increment values, names of employees and boss id chosen from the same table. I want to run a query which shows result as

    Hi Jane Doe, your BOSS is John Doe

    But it seems beyond my knowledge. Any help please?

    I have attached image of similar data

    Capture.JPG

  12. 10 hours ago, Barand said:

    Here's one way

    
    <?php
    // $n = 1;
    // $n = 1000;
    $n = 100000;
    
    /*
    for ($i=0; $i<12; $i++) {
        printf("%15d  |  %-20s\n", $n, weird_format($n));
        $n *= 10;
    }
    */
    
    printf("%-20s\n", weird_format($n));
    
    function weird_format($n)
    {
        if (($k = strlen($n)) < 4) return $n;
        $a = substr($n, 0, $k-3);                        // split off the last 3 chara
        $b = substr($n, -3);
        if (!($k%2)) $a = ' '.$a;                        // ensure first section is even no of chars
        $c = str_split($a, 2);                           // split into groups of 2
        return trim(join(',', $c) . ',' . $b);           // join them with commas
    }
    ?>

     

    Thank you for your help. With some modification, it works fine 🙂

  13. 3 hours ago, benanamen said:

    That is an interesting number format I have never seen. Could you please tell us what that is about and what it represents.

    In some countries 123456789 amount of currency of in general, it is counted as (if i am not wrong) one hundred twenty three million, four hundred fifty six thousand, seven hundred and eighty nine. Comma separated format is 123,456,789

    But in some countries (like mine)  the same amount is counted as twelve crore, thirty four lac, fifty six thousand seven hundred and eighty nine. Comma separated format is 12,34,56,789

    As we people are used to the second format that is common here, the thousands separated format mostly confuses us in reading.

  14. In php number format function works like.... 

    number_format("1000000",2); // 1,000,000.00

    is there a way to format numbers like... 10,00,00,000 (from right. No decimal. First comma after 3 digits and then commas after every 2 digits)

  15. <input id="numb" type="number" />
    <input type="submit" onclick="myFunction()" />
    <p id="demo"></p>
    <script>
    function myFunction(){
    var x = document.getElementById('numb').value;
    var regex=/^[1-9]+$/;
    if (x == ""){
    document.getElementById('demo').innerHTML = "Input is Missing";
    }
    else
    if (!x.match(regex)){
    document.getElementById('demo').innerHTML = "Input Incorrect";
    }
    else {
    document.getElementById('demo').innerHTML = "Input OK";
    }
    }
    /*
    if (x == "") {
    document.getElementById('demo').innerHTML = "Input is Missing";
    }
    else if (isNaN(x)) {
    document.getElementById('demo').innerHTML = "Input Incorrect";
    }
    else {
    document.getElementById('demo').innerHTML = "Input OK";
    }
    }
    */
    </script>
    

    When input type is "text" it works fine. but when i change input type to "number" and then if i type letters or letters plus numbers. it says "input missing"

    How can i get correct output while using input type "number"  ?

    Please guide. Thankyou.

  16. Actually the question was asked in a facebook group. and my answer there was...

    You ignored variable $p in second code and directly called an output of $i so it became $i = 2; $i++; for php.
    In your 1st code you are trying to do the same thing, but because of only one variable $i on both sides in 2nd line, php ignored #YOU and did it work. 
    1st code
    $i = 2; //declared an assigned a value.
    $i = $i++; //another declaration.
    ------------------------------------
    2nd code
    $i = 2; //declared an assigned a value.
    $i++; // direct increment.
    

    Still i was confused... Thanks dear for reply :)

  17. <a href="get.php?x=news">get1variable</a>
    <a href="get.php?x=news&r=links">get2variables</a>
    <?php
    $title = "Home | page";
    
    if (isset($_GET['x'])) {
        if ($_GET['x'] == "news"){
            $title = "News | Page";
            include "news.php";
            }
            }
        if (isset($_GET['x']) && isset($_GET['r'])) { //not working
            if ($_GET['x'] == "news" && $_GET['r'] == "links"){ //not working
               $title = "Links | Page";
               include "files/links.php";  //confused here, because this i think is to include links.php directly,
    }                                       //but i want links.php to be included in news.php
    }
    echo "<title>$title</title>";
    ?> 
    

    i also tried...

    if (isset($_GET['x'])) {
    if ($_GET['x'] == "news"){
        if(isset($_GET['r'])) { 
            if ($_GET['r'] == "links"){  //this also not working
               $title = "Links | Page";
               include "files/links.php";  //confused here...
    }
    }
    }
    }
    

    Aalso for creating a function i tried to learn how to create functions. but after learning i failed to create a function for this. if someone please guide me in detail for this?

  18. 
    session_start(); 
    $text = rand(10000,99999); 
    $_SESSION["vercode"] = $text; 
    $height = 25; 
    $width = 65; 
      
    $image_p = imagecreate($width, $height); 
    $black = imagecolorallocate($image_p, 255, 255, 255); 
    $white = imagecolorallocate($image_p, 0, 0, 0); 
    $font_size = 14; 
      
    imagestring($image_p, $font_size, 5, 5, $text, $white); 
    imagejpeg($image_p, null, 80); 
    
    

    The code above creates an image with white background. How to change it to create transparent background?

  19. You said it's not working as exactly i want. 

     

    i have an account in skrill, they have given me an account number eg; XX12345678 which they generated automatically for me. and its unique for every registered user.

     

    i want to do the same thing for users of my site.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.