Solved

php and mysql query

Posted on 2001-08-21
1
696 Views
Last Modified: 2008-02-01
I want to know how do get the results from this query

mysql> SELECT PERIOD_DIFF(20010101,20010110) as days;

to a variable in my php script

I am have no problems connecting to my database or query tables in my database but i don't know how to the the results of this query to a variable in my script.

This is what I have so far:
<?PHP
$login="mylogin";
$pass ="mydbpass";
$db=mysql_connect("localhost",$login,$pass);
mysql_select_db("mydb",$db);
$sql = "SELECT PERIOD_DIFF(20010101,20010110) as days";
$result=MySQL_query($sql,$db);

//This is where I am stuck
$diff_days = //result from mysql query
echo "$diff_days<br>";

?>";


Please Help!
0
Comment
Question by:onestar
1 Comment
 

Accepted Solution

by:
KestasS earned 50 total points
ID: 6410005
Just use function mysql_fetch_array (more info in www.zend.com)

For example you can fill select options:
<select name="cmbOwner">
    <? while ($myrow = mysql_fetch_array($rstOWNER)) {  
           echo"<option>";
          echo $myrow["name"];
       echo "</option>"  ;}   ?>
    </select>


In your case it will be :
<? echo $myrow["days"]; ?>

Good luck !

Kestas

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
designing in object programming 12 79
MySql and Apache/PHP Error Reporting 2 28
Cpanel file manager 8 25
Logic behind "best rated" calculation 11 22
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question