SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Store SQL output to the variable

    Hi i tried to store the time difference into the variable in PHP. However, it doesnt seen to work.

    $timequery =" TIMEDIFF('{$start}','{$end}')";

    $dur =mysql_query($timequery)or die('Query failed: ' . mysql_error());


    I am pretty sure that query does the job. But How can I store in into a variable $dur.

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    You just are not calling it correctly, from the manual:
    PHP Code:
    <?php
    $result 
    mysql_query("SELECT id,email FROM people WHERE id = '42'");
    if (!
    $result) {
        echo 
    'Could not run query: ' mysql_error();
        exit;
    }
    $row mysql_fetch_row($result);

    echo 
    $row[0]; // 42
    echo $row[1]; // the email value
    ?>
    mysql_fetch_row - check the other fetch_* options too

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it returns 0 when i execute it actually.

    I tried many fetch.. but the $row[0] is always 0, and $row[1] is nothing.

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    $timequery =" TIMEDIFF('{$start}','{$end}')";

    Is that your entire sql statment? Did you just try putting some real values in and send it into your your database - leave PHP out of it for a bit.

    Have you got a valid sql statement?

  5. #5
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh sorry, I was putting datediff so that it returns 0.

    Thanks for great help!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •