PHP - MySQL

Discuss coding issues, and scripts related to PHP and MySQL.

  1. » Marius
    Hello,
    I have this Select query, I want to select one row from mysql table, where id = $id, and has x_name or y_name 'yes'.
    $insert_cat =...
    Last post » Admin
    Hi
    The problem is that you didn't separate the conditions with the OR from the id=$id, so to select just the row which has that $id AND 'yes' in any...


  2. » Marius
    Hi
    I have this array, and I want to return it as JSON from a PHP script.
    $ar = array(
    'k0'=> array('a', 'b', 'c'),
    'k1'=> array(1, 2, 3)
    );...
    Last post » MarPlo
    Hi,
    Use json_encode() to encode the data and set the content-type with header('Content-type: application/json');
    Anyway, it works fine if you just...


  3. » Marius
    Hi
    I have two arrays $a1 and $a2 with various elements.
    How can I check which item from $a2 is in $a1? Is there any function, or I have to traverse...
    Last post » Admin
    Hi,
    The array_intersect($a2, $a1) function returns the elements of $a2 which are found in $a1.
    Also, with the in_array() function you can check if...


  4. » Marius
    I have 2 tables with same column names in my database which are supposed to provide content in 2 languages.
    This is how I query for one table (this...
    Last post » MarPlo
    The mysql is confused when you select columns with same name. The solution is to use Alias ( AS ).
    $sql = SELECT en.col1 AS c1en, en.col2 AS c2en,...


  5. » Marius
    Hi
    Does anyone has a php code to display the elapsed time?
    Like: one hour ago, 1 day and 3 hours ago, ...
    Thank you.
    Last post » Admin
    Hi
    You can use the timeElapsed() function, from this example:
    function timeElapsed($t1, $t2 = null) {
    /*...


  6. » Marius
    Why in my database, time is of type Timestamp but has no numeric form: 1402008961, but is of the form: 07/25/2014 12:13:45 ?
    Last post » MarPlo
    Hello
    Timestamp in MySQL is different from Unix Timestamp, which as you know is a number of seconds starting from 1970.
    Timestamp in MySQL is...