[PHP]<?php
$username = '__'; // MySQL Database Username.
$password = '__'; // MySQL Database Password.
$server = '__'; // MySQL Database server (most likely localhost).
$db = '__'; // MySQL Database Name.
$num = 4; // Number of Wordpress Articles to show.
$tz = '__'; // Your Timezone written using the list at http://php.net/timezones
mysql_connect($server,$username,$password);
@mysql_select_db("$db") or die('Unable to select database');
function GetWPData ($columnname, $limit) {
$q = mysql_query("SELECT `post_date`, `post_title` FROM `wp_posts` WHERE (post_type = 'post' AND post_status = 'publish') ORDER BY `wp_posts`.`post_date` DESC LIMIT 0,$limit");
$num = mysql_numrows($q);
$i=0;
while ($i < $num) {
$rows = mysql_result($q,$i,"$columnname");
$array["$i"] = $rows;
$i++;
}
return $array;
}
function RearrangeDate ($var) {
$i=0;
foreach ($var as $td) {
$date = substr($td, 0, 10);
$y = substr($date, 0, 4);
$M = substr($date, 5, 2);
$d = substr($date, 8, 2);
$format = "$d/$M/$y";
// $d = day, $M = month, $y = year.
$array["$i"] = $format;
$i++;
}
return $array;
}
function RearrangeTime ($var) {
$i=0;
foreach ($var as $td) {
$time = substr($td, 11, 8);
$h = substr($time, 0, 2);
$m = substr($time, 3, 2);
$s = substr($time, 6, 2);
$format = "$h:$m";
// $h = hours, $m = minutes, $s = seconds.
$array["$i"] = $format;
$i++;
}
return $array;
}
function StringTogether ($d_arr, $t_arr, $title_arr) {
$i=0;
while ($i < $num) {
$d = $d_arr["$i"];
$t = $t_arr["$i"];
$title = $title_arr["$i"];
$format = "$d $t - $title";
// $d = date, $t = time, $title = title
$array["$i"] = $format;
$i++;
}
$text = implode('<br>', $array);
return $text;
}
mysql_close();
$p_d = RearrangeDate(GetWPData('post_date',$num));
$p_t = RearrangeTime(GetWPData('post_date',$num));
$p_title = GetWPData('post_title',$num);
$text = StringTogether($p_d, $p_t, $p_title);
date_default_timezone_set("$tz");
$lt = localtime(time(), true);
$h = $localtime[tm_hour];
$m = $localtime[tm_min];
$s = $localtime[tm_sec];
$ld = date($ldformat);
$lt_format = "$h:$m"; // Local Time Format
// $h = hours, $m = minutes, $s = seconds.
$ld_format = "d/m/Y"; // Local Date Format
// d = days, m = months, Y = years.
$td_format = "$ld $lt"; // Time-Date Format
// $ld = date, $lt = time.
$td=$td_format;[/PHP]
when I run it I get the following errors:
Warning: mysql_query() [function.mysql-query]: Access denied for user '__'@'__' (using password: NO) in __ on line 20What needs fixing in my script to get everything working? The MySQL username and password were entered and correctly spelt despite what the error messages say and have only been removed for security reasons.
Warning: mysql_query() [function.mysql-query]: A link to the server could not be __ on line 20
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in __ on line 21
Warning: Invalid argument supplied for foreach() in __ on line 33
Warning: mysql_query() [function.mysql-query]: Access denied for user '__'@'__' (using password: NO) in __ on line 20
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in __ on line 20
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in __ on line 21
Warning: Invalid argument supplied for foreach() in __ on line 50
Warning: mysql_query() [function.mysql-query]: Access denied for user '__'@'__' (using password: NO) in __ on line 20
Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in __ on line 20
Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in __ on line 21
Warning: implode() [function.implode]: Bad arguments. in __ on line 78
Can anyone help this newbie programmer?
Thanks :D
atyndall93