jim.davidson Posted February 17, 2010 Share Posted February 17, 2010 I'm teaching myself arrays and loops. I'm trying to get dates out of a msql table. I can get what I want but I'm looking for a better way to populate the bus_dates array. Any suggestions will be appreciated. Here's the code $bus_dates = array(); mysql_select_db($database_myData, $myID); $query_getBus = "SELECT * FROM meetings WHERE type = 'Business'"; $getBus = mysql_query($query_getBus, $myID) or die(mysql_error()); $row_getBus = mysql_fetch_assoc($getBus); // $totalRows_getBus = mysql_num_rows($getBus); $counter = 0; $today = date('Y-m-d'); $bus_dates[] = $row_getBus['jan_date']; $bus_dates[] = $row_getBus['feb_date']; $bus_dates[] = $row_getBus['mar_date']; $bus_dates[] = $row_getBus['apr_date']; $bus_dates[] = $row_getBus['may_date']; $bus_dates[] = $row_getBus['jun_date']; $bus_dates[] = $row_getBus['jul_date']; $bus_dates[] = $row_getBus['aug_date']; $bus_dates[] = $row_getBus['sep_date']; $bus_dates[] = $row_getBus['oct_date']; $bus_dates[] = $row_getBus['nov_date']; $bus_dates[] = $row_getBus['dec_date']; // Find the next meeting date for ($counter=0; $counter <12; $counter++) { if ($bus_dates[$counter] >= $today) { echo "<BR>$bus_dates[$counter]"; exit; } } Link to comment https://forums.phpfreaks.com/topic/192417-looking-for-a-more-efficient-way/ Share on other sites More sharing options...
SchweppesAle Posted February 17, 2010 Share Posted February 17, 2010 something like this? $i = 0; while($row_getBus = mysql_fetch_assoc($getBus)) { $bus_dates[$i]['jan_date'] = $row_getBus['jan_date']; $bus_dates[$i]['feb_date'] = $row_getBus['feb_date']; $bus_dates[$i]['mar_date'] = $row_getBus['mar_date']; $bus_dates[$i]['apr_date'] = $row_getBus['apr_date']; $bus_dates[$i]['may_date'] = $row_getBus['may_date']; $bus_dates[$i]['jun_date'] = $row_getBus['jun_date']; $bus_dates[$i]['jul_date'] = $row_getBus['jul_date']; $bus_dates[$i]['aug_date'] = $row_getBus['aug_date']; $bus_dates[$i]['sep_date'] = $row_getBus['sep_date']; $bus_dates[$i]['oct_date'] = $row_getBus['oct_date']; $bus_dates[$i]['nov_date'] = $row_getBus['nov_date']; $bus_dates[$i]['dec_date'] = $row_getBus['dec_date']; $i++; } you'll probably need to tweak the for() construct below it foreach($bus_dates as $bus) { //will iterate through each database entry so $bus['jan_date'] == $bus_dates[0]['jan_date'] on the first run } Link to comment https://forums.phpfreaks.com/topic/192417-looking-for-a-more-efficient-way/#findComment-1013928 Share on other sites More sharing options...
jim.davidson Posted February 17, 2010 Author Share Posted February 17, 2010 Thank you! Link to comment https://forums.phpfreaks.com/topic/192417-looking-for-a-more-efficient-way/#findComment-1013933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.