Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php and mysql query

Posted on 2001-08-21
1
Medium Priority
?
708 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 150 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

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…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

876 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