Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2006-03-20 02:15:07

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: last updated on ...

do u mean inside the bracket?

No, after: DESC limit 1" (right after it you started the comment //I'm assuming...).

Offline

#14 2006-03-20 02:27:04

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

hmm, Parse error: syntax error, unexpected ‘;’ in /home/.cambyses/systrum/systrum.net/test.php on line 13

this what i have now …

<code>
$query = “select LastMod from textpattern order by LastMod DESC limit 1”;
</code>

Offline

#15 2006-03-20 05:29:45

variaas
Plugin Author
From: Chicago
Registered: 2005-01-16
Posts: 402
Website

Re: last updated on ...

systrum: I just tested this code and it works on my system. Give it a try and let me know if you’re still get parse errors (note that I changed the section for connecting to the database back to your original code):

<code>
<?php
//Connect to the database
$dbhost = ‘******’;
$dbuser = ‘*****’;
$dbpass = ‘******’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);
$dbname = ‘public02’;
mysql_select_db($dbname);
//Get the data
$query = “select LastMod from textpattern order by LastMod DESC limit 1”; //I’m assuming you want the last time an article was modified
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
//Output the results
echo “Last Modified:{$row[‘LastMod’]}
“;
//Close the connection
mysql_close($conn);
?>
</code>

Offline

#16 2006-03-20 06:17:50

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

I think i’m connecting ok, but after googling, there may be a prob with the way the db is setup. any hints?

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/.cambyses/systrum/systrum.net/last_mod.php on line 12
Last Modified:

Offline

#17 2006-03-20 13:35:36

variaas
Plugin Author
From: Chicago
Registered: 2005-01-16
Posts: 402
Website

Re: last updated on ...

systrum: So I guess I should provide better programming practices. That error usually means that there was nothing returned by the query. Before outputing the results of the query you should make sure that there actually was something returned by the query. So output the data with a check like this:
<code>
if($row = mysql_fetch_array($result){
echo “Last Modified:{$row[‘LastMod’]}”;
}
else{
echo “No data was returned”;
}
</code>

If nothing is returned it means that there is an issue with the query. Try using rss_db_admin to ensure that the query actually returns something.

Offline

#18 2006-03-20 23:29:44

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

variaas – i played around a little with my setup and it works!
i polulated a new db and tried it out … the script works well.

thanks a million for the chunk of php, the help, and your patience.

Last edited by systrum (2006-03-20 23:30:26)

Offline

#19 2007-04-11 22:11:52

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

is it at all possible to edit this code so that it displays most recently posted date and excerpt?
the output would display in a non txp environment.

<code>
<?php
//Connect to the database
$dbhost = ‘******’;
$dbuser = ‘*****’;
$dbpass = ‘******’;
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’);
$dbname = ‘public02’;
mysql_select_db($dbname);
//Get the data
$query = “select LastMod from textpattern order by LastMod DESC limit 1”; //I’m assuming you want the last time an article was modified
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
//Output the results
echo “Last Modified:{$row[‘LastMod’]}
“;
//Close the connection
mysql_close($conn);
?>

</code>

Last edited by systrum (2007-04-11 22:35:31)

Offline

#20 2007-04-11 22:19:20

variaas
Plugin Author
From: Chicago
Registered: 2005-01-16
Posts: 402
Website

Re: last updated on ...

$query = “select Title from textpattern order by Posted DESC limit 1”;

you can replace “Title” with any of the following:

Body, Body_html, Excerpt, or Excerpt_html

Offline

#21 2007-04-19 14:45:30

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

Apologies for the persistent questions but the code posted earlier does not seem to be working as i would like it to.

i edited the settings so that it outputs excerpts … the changes are below

<code>
$query = “select Excerpt from textpattern order by Exerpt DESC limit 1”;
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
//Output the results
echo “Last Modified:{$row[‘Excerpt’]}”;
</code>

i am finding that it is not outputting the most recent excerpts all the time.
sometimes it will do so, but posting another item after it will often result in the previous excerpt still being displayed.

i tried playing with the settings, changing them to ASC and increasing the limit, with no desired effects.
i am wanting the most recent excerpt to display.
there are no probs with displaying LastMod, but changing the setting to display Body, Title etc also do not display consistent most recently posted items either.

perhaps I need to change a Mysql setting? can anyone point me in the right direction?
(if at all possible it would want to display most recently posted Excerpt and lastMod at the same time.)

Offline

#22 2007-04-19 15:01:21

variaas
Plugin Author
From: Chicago
Registered: 2005-01-16
Posts: 402
Website

Re: last updated on ...

Hey systrum,

First off, my advice is to better aquaint yourself with SQL. Here’s a great tutorial site http://www.w3schools.com/sql/default.asp.

So here’s the correct query:
<code>
$query = “select Excerpt from textpattern order by Posted DESC limit 1”;
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
//Output the results
echo “Last Modified:{$row[‘Excerpt’]}”;
</code>

Previously you were ordering the results by the Excerpt.

Offline

#23 2007-04-19 15:12:48

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

doh! thank you so much

Offline

#24 2007-04-20 19:31:05

systrum
Member
Registered: 2004-08-28
Posts: 44

Re: last updated on ...

i have one final question related to sql date conversion
i have edit the code to output ‘Except’ and ‘Posted’,
but ‘Posted’ displays the date …

2007-04-11 16:15:58

whereas i would like it to display

11 April 2007

i know i need to convert the Posted string back to a timestamp, and found something on a forum that might help to do that below…

<code>
<?php
$myinput=‘12/15/2005’;
$sqldate=*date*(‘Y-m-d’,strtotime($myinput));
echo $sqldate;
?>
</code>

my question is how to make this fit to work with the code variass provided?
i am almost there.

Offline

Board footer

Powered by FluxBB