473,671 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Get MySQL function clean-up and support required

13 New Member
OK,
Well I've got this script and I'd like to implement this function into it where a function retrieves a specified amount of data from a specific mysql database, rearranges a part of it, and outputs the result to another specified varible. this is what i've got so far (please ignore the long-winded variables, they are just for explanations):
[PHP]function RearrangeDate ($input-data/time, $the-way-it-should-be-arranged-e.g.-D/m/y-(not implemented)) {
$date = substr($timedat e, 0, 10);
$year = substr($date, 0, 4);
$month = substr($date, 5, 2);
$day = substr($date, 8, 2);
$newdate = $day . "/" . $month . "/" . $year;
output $newdate
}

function GetWP ($amount-of-rows-to-output) {
$sql =
"SELECT `post_date`, `post_title`
FROM `wp_posts`
WHERE (post_type = 'post' AND post_status = 'publish')
ORDER BY `wp_posts`.`pos t_date` DESC
LIMIT 0,$amount-of-rows-to-output";
$query = mysql_query($sq l);
$array = mysql_fetch_row ($query);
$timedate = $array[0];
RearrangeDate($ timedate, d/m/y);
$text = $newdate . " - " . $array[1];
output $test
}[/PHP]
What it does is retrieves the mysql row and renames the variables (which once it is integrated into a function it wouldn't have to do). Then it passes the date/time variable to another function which strips the time and rearranges the date from American date to a specified format. Then the RearrangeDate function outputs the new arrangement and the GetWP function outputs the final variable arranged in a readable way.
But this script only retrieves the first row and doesn't output the result properly. Can anyone fix this horrific script (as I only have basic PHP knowledge) and point out any areas where it would need a cleanup?
Oct 1 '07 #1
5 1703
code green
1,726 Recognized Expert Top Contributor
But this script only retrieves the first row
That is what you asked for unless you have multiple calls on the function GetWP()[PHP]$array = mysql_fetch_row ($query);[/PHP] What does the following mean?
and doesn't output the result properly
Oct 1 '07 #2
Motoma
3,237 Recognized Expert Specialist
In the current state of the code, you are only retrieving one row of data. You will need to create a loop if you want to retrieve multiple rows.

You have not set a value to $newdate at the point in your code where you assign a value to test. You likely mean to return the value in RearrangeDate, and store the returned value in your $test variable.
Oct 1 '07 #3
atyndall
13 New Member
opps.

[PHP]output $test [/PHP]
is ment to be
[PHP]output $text[/PHP]
Oct 1 '07 #4
Motoma
3,237 Recognized Expert Specialist
opps.

[PHP]output $test [/PHP]
is ment to be
[PHP]output $text[/PHP]
And does it work now?
Oct 1 '07 #5
atyndall
13 New Member
No, but after fiddling around a bit I got it all to work the way I wanted it to, its posted below for anyone who whats to use it. GetWPData(); retrives data from wordpress tables and can be passed a table name and limit how many varibles or strings. RearrangeDateTi me(); rearranges a array of specified date and times to another specified way.

[PHP]function GetWPData ($tablename, $limit) {
$sql = "SELECT `post_date`, `post_title` FROM `wp_posts` WHERE (post_type = 'post' AND post_status = 'publish') ORDER BY `wp_posts`.`pos t_date` DESC LIMIT 0,$limit";
$query = mysql_query($sq l);
$num = mysql_numrows($ query);
$i=0;
while ($i < $num) {
$table = mysql_result($q uery,$i,"$table name");
$tablearray["$i"] = $table;
$i++;
}
return $tablearray;
}

function RearrangeDateTi me ($var) {
$i=0;
foreach ($var as $td) {
$date = substr($td, 0, 10);
$time = substr($td, 11, 8);
$y = substr($date, 0, 4);
$M = substr($date, 5, 2);
$d = substr($date, 8, 2);
$h = substr($time, 0, 2);
$m = substr($time, 3, 2);
$s = substr($time, 6, 2);

$format = "$d/$M/$y $h:$m";
// $d = day, $M = month, $y = year. $h = hours, $m = minutes, $s = seconds.

$array["$i"] = $format;
$i++;
}
return $array;
}[/PHP]

Enjoy!
Oct 2 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
10272
by: francescomoi | last post by:
Hi. I'm trying to build 'MySQL-python-1.2.0' on my Linux FC2: ---------------------------------- # export PATH=$PATH:/usr/local/mysql/bin/ # export mysqlclient=mysqlclient_r # python setup.py clean # python setup.py build running build running build_py
0
1487
by: jackiu | last post by:
------=_NextPart_000_0001_01C35286.10843160 Content-Type: multipart/alternative; boundary="----=_NextPart_001_0002_01C35286.10843160" ------=_NextPart_001_0002_01C35286.10843160 Content-Type: text/plain; charset="big5" Content-Transfer-Encoding: base64
6
3270
by: TonyB | last post by:
I'm running the zip'd version of PHP (PHP 5.1.2 zip package) downloaded from here: http://www.php.net/downloads.php. PHP won't connect with MySQL. >From docs and threads, it seems enabling PHP/MySQL connectivity on a Windows XP machine requires three configuration edits. These are: 1. In php.ini, enable php_mysql.dll by uncommenting "extension=php_mysql.dll". 2. In php.ini, set "extension_dir" to the folder containing
0
1262
by: Comcast | last post by:
I'm trying to do an install of mysql on a Sun Ultra 10 machine running Solaris 10 (1/06) which is a completely clean, fresh install. I can get the packaged (with Solaris 10) version of mysql (4.0.something) running easily. I do have version 5.0.15-standard installed and running on another machine. It appears that between 5.0.15 and 5.0.22 someone has made a decision to change the locations that the files are sent to and nobody has...
1
5275
by: PowerLifter1450 | last post by:
I've been having a very rough time installinig mySQL on Linux. I have been following the instructions form here: http://www.hostlibrary.com/installing_apache_mysql_php_on_linux Everytime I get to #./configure it goes through all of the preparing tables and starting mysqlServer and daemon, but than immediaetly says "mysql ended" -- I try to do #make right after anyway, but I get the error "No targets specified and no makefile found" -- Any...
0
8393
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8917
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8821
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8598
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8670
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6229
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4225
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2812
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1809
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.