Help with simple sql query

Heya,

I’ve written a query, which works when I run it in phpmyadmin.
But I just can’t get it to work when I write it in PHP.

The query is following:
[php]SELECT MIN(created) FROM ost_ticket WHERE status= “open” AND helptopic = “Faktura” AND work IS NULL ORDER BY created DESC[/php]

What I need is to print the earliest date (the field created).

Can anyone help me?

Thanks in advance!

I think all you need to do is take off the single quotes and you’ll be good to go.

[php]SELECT MIN(created) FROM ost_ticket WHERE status= “open” AND helptopic = “Faktura” AND work IS NULL ORDER BY created DESC[/php]

Thanks alot for your reply!
I tried your tip but it doesn’t seem to work anyway, probably something wrong with my code.

Here it is:
[php]<?php
mysql_connect(‘localhost’, ‘usrname’, ‘pw’) or die(mysql_error());
mysql_select_db(“dbname”) or die(mysql_error());

$sql = mysql_query(‘SELECT MIN(created) FROM ost_ticket WHERE status= “open” AND helptopic = “Faktura” AND work IS NULL ORDER BY created DESC’);
while($info = mysql_fetch_array($sql)) {
echo $info[‘created’]."
";
}
?>[/php]

Update, I think i’m in the right direction.
Now I got the date printed, but theres some “junk” before and after it. :slight_smile:
When I view the page, it shows the text Array ( [MIN(created)] => 2013-06-26 11:39:50 )
I just want it to show it like 2013-06-26 11:39:50

Any tips on how I can get there?

My current code:

[php]<?php
mysql_connect(‘localhost’, ‘usrname’, ‘pw’) or die(mysql_error());
mysql_select_db(“db”) or die(mysql_error());

$query = mysql_query(‘SELECT MIN(created) FROM ost_ticket WHERE status = “open” AND helptopic = “Faktura” AND work IS NULL ORDER BY created DESC’);

$array=mysql_fetch_assoc($query);
print_r($array);

?>[/php]

GOT IT!

Thanks for your help!

[php]<?php
mysql_connect(‘localhost’, ‘usr’, ‘pw’) or die(mysql_error());
mysql_select_db(“db”) or die(mysql_error());

$query = mysql_query(‘SELECT MIN(created) FROM ost_ticket WHERE status = “open” AND helptopic = “Faktura” AND work IS NULL ORDER BY created DESC’);

$array=mysql_fetch_assoc($query);
foreach($array as $v) echo $v, PHP_EOL;

?>[/php]

No problem, I just put one piece of your puzzle in the right place and you did the rest :slight_smile:

Sponsor our Newsletter | Privacy Policy | Terms of Service