Jump to content

Recommended Posts

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:

test1.php

When it should return a result like this:

500150ds.png

 

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)

Link to comment
https://forums.phpfreaks.com/topic/71902-what-is-wrong-with-my-code/
Share on other sites

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

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.