Solved

php and mysql query

Posted on 2001-08-21
1
693 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now