Buy Sell Discuss UK Domain Names at AcornDomains.co.uk affiliate window

Today's Drop Dates are: 19-02-2012 or 26-02-2012   All times are GMT. The time now is 12:42:54 PM.
Domain Name Sales Domain Software Calculate UK Domain Drop Dates Domain Registration NameDrive Domain Parking Subscribe to our Domains For Sale newsletter
Go Back   Domain Forum Acorn Domains Buy Sell Auction UK Domains > Website Design and Promotion > Website Design > Scripts and Coding
Connect with Facebook

Scripts and Coding PHP, MySQL, scripts

Closed Thread
 
LinkBack Thread Tools Display Modes
Old 13-08-2010, 05:38:11 PM     #1 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,586
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

php array

A bit more help needed...

I have a table with a column called date. Dates in this column are in the format MonthDay, examples: Jan31, Feb2, Apr9, Jul27.

I need to query the table for all dates in a month to get an array that looks like this:

$events = array(1,7,8,17,18,23);

So far I have:

$month='Feb'; (or whatever month is given to the variable)
$query = "SELECT date FROM table WHERE date LIKE '$month%'";
$events = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)) {
echo substr($row['date'], 3) . ',';
}
}


This echos the results with a comma, but there is a trailing comma which is not needed, and also I am trying to force this into an array, but I think there must be a more natural way of retrieving this array.

Basically the rest of my script works well if it is given an array like this:
$events = array(1,7,8,17,18,23);

Any help appreciated.
woopwoop is offline  
Old 13-08-2010, 08:36:28 PM     #2 (permalink)

 
Skinner's Avatar
 
Join Date: Jul 2008
Location: Manchester
Posts: 2,507
Skinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond reputeSkinner has a reputation beyond repute

Check the number of rows in the result, then include a counter, and if the counter = num_rows don't include the ',' bit on there.

Thats a quick way of doing it.

What you call $row is already an array, your just looping through it, why not perform your array actions on that ?
__________________
Browse:
Skinner is offline  
Old 13-08-2010, 09:22:26 PM     #3 (permalink)

 
woopwoop's Avatar
 
Join Date: Jan 2007
Posts: 1,586
woopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond reputewoopwoop has a reputation beyond repute

Thanks Skinner -

I got a bit of help on another forum which seems to be holding up (fingers crossed):

PHP Code:
$month='Feb';
$query "SELECT date FROM table WHERE date LIKE '$month%'";
$result mysql_query($query) or die(mysql_error());
$events = array();
while(
$row mysql_fetch_array($result)) {
   
$events[] = substr($row['date'], 3);

woopwoop is offline  
Closed Thread



Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Domain Name Community Replies Last Post
UK Counties list grantw General Board 30 14-12-2008 08:56:44 PM
PHP include in a Smarty Template admin Scripts and Coding 1 13-05-2008 06:37:26 AM
PHP variable help purg General Board 4 04-03-2008 02:30:21 PM

Web Hosting from UK2 from just 99p


All times are GMT. The time now is 12:42:54 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.6.0 RC 2
All content on Acorn Domains is member generated and is not moderated before posting. All content is viewed and used by you at your own risk and AD does not warrant the accuracy or reliability of any of the information. The views expressed are those of the individual contributors and not necessarily those of AD. Please contact us to report any issues or send a PM to "Admin".