atyndall Posted October 5, 2007 Share Posted October 5, 2007 This is my code: <?php $image_info = array( 'image' => '500150bg.gif' ); 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, $format) { $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); $array["$i"] = $format; $i++; } return $array; } function RearrangeTime ($var, $format) { $i=0; foreach ($var as $td) { $time = substr($td, 11, ; $h = substr($time, 0, 2); $m = substr($time, 3, 2); $s = substr($time, 6, 2); $array["$i"] = $format; $i++; } return $array; } function MakeArray () { $i=0; while ($i < $num) { $text["$i"] = $td_format["$i"].' - '. $p_title["$i"]; $i++; } return $text; } // ########## START OPTIONS ########## // Time Options $h = $lt[tm_hour]; // DON'T EDIT $m = $lt[tm_min]; // DON'T EDIT $s = $lt[tm_sec]; // DON'T EDIT $t = "$h:$m"; // Local/Post Time Format, $h = hours, $m = minutes, $s = seconds. $tz = '__REMOVED__'; // Your nearest timezone chosen from the list at www.php.net/timezones date_default_timezone_set("$tz"); $lt = localtime(time(), true); // DON'T EDIT $ld_format = "d/m/Y"; // Local Date Format, d = days, m = months, Y = years. $d = date($ld_format); // DON'T EDIT $pd_format = "$d/$m/$y"; // Post Date Format, $d = day, $m = month, $y = year. $td_format = "$d $t"; // Time-Date Format, $d = date, $t = time. // MySQL Options $username = '__REMOVED__'; // Database Username. $password = '__REMOVED__'; // Database Password. $server = '__REMOVED__'; // Database server (most likely localhost). $db = '__REMOVED__'; // Database Name. // Display Options $num = 4; // Number of Wordpress Articles to show. // ########## END OPTIONS ########## mysql_connect($server,$username,$password); @mysql_select_db("$db") or die('Unable to select database'); $p_d = RearrangeDate(GetWPData('post_date',$num),$pd_format); $p_t = RearrangeTime(GetWPData('post_date',$num),$t); $p_title = GetWPData('post_title',$num); $text = MakeArray(); //mysql_close(); $image_text = array( array( 'x' => 17, 'y' => 49, 'color' => array(0, 0, 0), 'font' => -5, 'text' => "Latest Articles (as of $td_format):" ), array( 'x' => 17, 'y' => 65, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[0] ), array( 'x' => 17, 'y' => 80, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[1] ), array( 'x' => 17, 'y' => 95, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[2] ), array( 'x' => 17, 'y' => 110, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[3] ), array( 'x' => 17, 'y' => 124, 'color' => array(0, 0, 0), 'font' => -2, 'text' => "All times are $tz time." ) ); require('dynamic_gd_image.php'); ?> It returns a result like this: When it should return a result like this: Can anyone see what is wrong with my code? Any problems than need to be fixd, any ways the code can be made more efficient? Thankyou, atyndall93 (AKA Mr. PHP Newbie) Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/ Share on other sites More sharing options...
heckenschutze Posted October 5, 2007 Share Posted October 5, 2007 Learn how to indent, it's very hard to read. Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-362204 Share on other sites More sharing options...
atyndall Posted October 5, 2007 Author Share Posted October 5, 2007 it was indented but for some reason the forum software reset the indentions. Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-362207 Share on other sites More sharing options...
atyndall Posted October 5, 2007 Author Share Posted October 5, 2007 Happy now? <?php $image_info = array( 'image' => '500150bg.gif' ); 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, $format) { $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); $array["$i"] = $format; $i++; } return $array; } function RearrangeTime ($var, $format) { $i=0; foreach ($var as $td) { $time = substr($td, 11, ; $h = substr($time, 0, 2); $m = substr($time, 3, 2); $s = substr($time, 6, 2); $array["$i"] = $format; $i++; } return $array; } function MakeArray () { $i=0; while ($i < $num) { $text["$i"] = "$td_format[$i] - $p_title[$i]"; $i++; } return $text; } // ########## START OPTIONS ########## // Time Options $h = $lt[tm_hour]; // DON'T EDIT $m = $lt[tm_min]; // DON'T EDIT $s = $lt[tm_sec]; // DON'T EDIT $t = "$h:$m"; // Local/Post Time Format, $h = hours, $m = minutes, $s = seconds. $tz = 'Australia/Perth'; // Your nearest timezone chosen from the list at www.php.net/timezones date_default_timezone_set("$tz"); $lt = localtime(time(), true); // DON'T EDIT $ld_format = "d/m/Y"; // Local Date Format, d = days, m = months, Y = years. $d = date($ld_format); // DON'T EDIT $pd_format = "$d/$m/$y"; // Post Date Format, $d = day, $m = month, $y = year. $td_format = "$d $t"; // Time-Date Format, $d = date, $t = time. // MySQL Options // Display Options $num = 4; // Number of Wordpress Articles to show. //$text_format = ''; // ########## END OPTIONS ########## mysql_connect($server,$username,$password); @mysql_select_db("$db") or die('Unable to select database'); $p_d = RearrangeDate(GetWPData('post_date',$num),$pd_format); $p_t = RearrangeTime(GetWPData('post_date',$num),$t); $p_title = GetWPData('post_title',$num); $text = MakeArray(); mysql_close(); $image_text = array( array( 'x' => 17, 'y' => 49, 'color' => array(0, 0, 0), 'font' => -5, 'text' => "Latest Articles (as of $td_format):" ), array( 'x' => 17, 'y' => 65, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[0] ), array( 'x' => 17, 'y' => 80, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[1] ), array( 'x' => 17, 'y' => 95, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[2] ), array( 'x' => 17, 'y' => 110, 'color' => array(0, 0, 0), 'font' => -4, 'text' => $text[3] ), array( 'x' => 17, 'y' => 124, 'color' => array(0, 0, 0), 'font' => -2, 'text' => "All times are $tz time." ) ); require('dynamic_gd_image.php'); ?> Can I now please have someone actually answer my question and not comment on my indenting skills Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-362208 Share on other sites More sharing options...
darkfreaks Posted October 5, 2007 Share Posted October 5, 2007 try using '' instead of `` Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-362209 Share on other sites More sharing options...
heckenschutze Posted October 5, 2007 Share Posted October 5, 2007 Use spaces instead of tabs, seriously. `wp_posts`.`post_date` should be `wp_posts.post_date` or something. Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-362210 Share on other sites More sharing options...
atyndall Posted October 7, 2007 Author Share Posted October 7, 2007 *bump* hello? anyone with any suggestions??? Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-363655 Share on other sites More sharing options...
JasonLewis Posted October 7, 2007 Share Posted October 7, 2007 hold on... your first post says this: It returns a result like this: When it should return a result like this: what do the results look like? Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-363678 Share on other sites More sharing options...
MasterACE14 Posted October 7, 2007 Share Posted October 7, 2007 Happy now? Can I now please have someone actually answer my question and not comment on my indenting skills a attitude like that isn't going to get much of a response. your first post says this: It returns a result like this: When it should return a result like this: what do the results look like? are the results are image? or text? Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-363737 Share on other sites More sharing options...
JasonLewis Posted October 7, 2007 Share Posted October 7, 2007 i think he is using images because at the very bottom it mentions GD... require('dynamic_gd_image.php'); Quote Link to comment https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/#findComment-363948 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.