Re: [PHP-DB] Populating an array from mysql db
I'd worry about the empty dates after. and use something like. $qry = select date1, date2 from table; $result = mysql_query($qry) or die(mysql_error()); while ($rs = mysql_fetch_row($result)) { //this array could be built a number of ways, one is $bookdate[] = array($rs[0],$rs[1]); } if i've not misunderstood, that should work hth jeff mike karthauser [EMAIL PROTECTED]To: [EMAIL PROTECTED] m.co.uk cc: Subject: [PHP-DB] Populating an array from mysql db 08/28/2003 08:01 AM I have a course booking system that allows the client to add courses and then specify how long they run for. The admin system I have built allows the client to add up to 30 dates for each instance of the course and these are adding to a database row in the form date1, date2, date3, daten etc. What I am trying to achieve now is to extract this data into an array so I can count how many dates have been added and to display the dates. If the course runs for eg. 2 days - values of date1 and date2 would be populated as date1=2003-09-01, date2=2003-09-02 - all other dates would be default to -00-00 and I wish to ignore these. I'm trying to work out how to set up a loop to extract positive dates from my db so I end up with $bookdate[0] = '2003-09-01'; $bookdate[1] = '2003-09-02'; etc Can anyone provide me with some help in this extraction? Thanks in advance. -- Mike Karthauser Managing Director - Brightstorm Ltd Email[EMAIL PROTECTED] Web http://www.brightstorm.co.uk Tel 0117 9426653 (office) 07939 252144 (mobile) SnailmailUnit 8, 14 King Square, Bristol BS2 8JJ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Populating an array from mysql db
From: mike karthauser [EMAIL PROTECTED] I have a course booking system that allows the client to add courses and then specify how long they run for. The admin system I have built allows the client to add up to 30 dates for each instance of the course and these are adding to a database row in the form date1, date2, date3, daten etc. What I am trying to achieve now is to extract this data into an array so I can count how many dates have been added and to display the dates. If the course runs for eg. 2 days - values of date1 and date2 would be populated as date1=2003-09-01, date2=2003-09-02 - all other dates would be default to -00-00 and I wish to ignore these. I'm trying to work out how to set up a loop to extract positive dates from my db so I end up with $bookdate[0] = '2003-09-01'; $bookdate[1] = '2003-09-02'; etc Can anyone provide me with some help in this extraction? With just a short comment on what a horrible, horrible database schema this is, you should be able to use if($date_from_db != '-00-00') { $bookdate[] = $date_from_db; } ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Populating an array from mysql db
on 28/8/03 1:09 pm, [EMAIL PROTECTED] at [EMAIL PROTECTED] wrote: I'd worry about the empty dates after. and use something like. $qry = select date1, date2 from table; $result = mysql_query($qry) or die(mysql_error()); while ($rs = mysql_fetch_row($result)) { //this array could be built a number of ways, one is $bookdate[] = array($rs[0],$rs[1]); } if i've not misunderstood, that should work Thanks for this - I ended up rehashing my query to this: ? $result = mysql_query(SELECT * FROM dates WHERE bookcode = '$bookcode' ORDER BY date1,$db); // loop to populate array $myrow = mysql_fetch_array($result); $i = 1; while ($i = '30') { if ($myrow['date'.$i] '-00-00') { $bookdate[]=$myrow['date'.$i]; } $i++; /* the printed value would be $i before the increment (post-increment) */ } //end loop $result2 = count ($bookdate); if ($result2 == 0) { echo pThis course booking runs for 0 days/pp; } else if ($result2 == 1) { echo pThis course booking runs for b1/b day on the following date:/Pp; } else { echo pThis course booking runs for b$result2/b days on the following dates: /pp; } function print_dates ($bookdate) {foreach ($bookdate as $display_date) { $date = $display_date; $dv[0] = substr($date, 8, 2); $dv[1] = substr($date, 5, 2); $dv[2] = substr($date, 0, 4); $display_date = implode (-,$dv) ; print(span class=\divider\$display_date/spanbr); } } print_dates($bookdate); ? Which does what I need. The tricky bit was the //loop cheers -- Mike Karthauser Managing Director - Brightstorm Ltd Email[EMAIL PROTECTED] Web http://www.brightstorm.co.uk Tel 0117 9426653 (office) 07939 252144 (mobile) SnailmailUnit 8, 14 King Square, Bristol BS2 8JJ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Populating an array from mysql db
From: mike karthauser [EMAIL PROTECTED] Thanks for this - I ended up rehashing my query to this: ? $result = mysql_query(SELECT * FROM dates WHERE bookcode = '$bookcode' ORDER BY date1,$db); // loop to populate array $myrow = mysql_fetch_array($result); $i = 1; while ($i = '30') { if ($myrow['date'.$i] '-00-00') You're making PHP do some extra work here. You're testing to see if one string is greater than another... how can strings be greater than or less than? Why don't you just check for $myrow['date'.$i] != '-00-00' ?? ---John Holmes... -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] Populating an array from mysql db
on 28/8/03 5:00 pm, CPT John W. Holmes at [EMAIL PROTECTED] wrote: Thanks for this - I ended up rehashing my query to this: ? $result = mysql_query(SELECT * FROM dates WHERE bookcode = '$bookcode' ORDER BY date1,$db); // loop to populate array $myrow = mysql_fetch_array($result); $i = 1; while ($i = '30') { if ($myrow['date'.$i] '-00-00') You're making PHP do some extra work here. You're testing to see if one string is greater than another... how can strings be greater than or less than? Why don't you just check for $myrow['date'.$i] != '-00-00' ?? Thanks. I'll make your change. Ta. -- Mike Karthauser Managing Director - Brightstorm Ltd Email[EMAIL PROTECTED] Web http://www.brightstorm.co.uk Tel 0117 9426653 (office) 07939 252144 (mobile) SnailmailUnit 8, 14 King Square, Bristol BS2 8JJ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP-DB] Populating an array from mysql db
On 28 August 2003 17:25, mike karthauser wrote: on 28/8/03 5:00 pm, CPT John W. Holmes at [EMAIL PROTECTED] wrote: Thanks for this - I ended up rehashing my query to this: ? $result = mysql_query(SELECT * FROM dates WHERE bookcode = '$bookcode' ORDER BY date1,$db); // loop to populate array $myrow = mysql_fetch_array($result); $i = 1; while ($i = '30') { if ($myrow['date'.$i] '-00-00') You're making PHP do some extra work here. You're testing to see if one string is greater than another... how can strings be greater than or less than? Why don't you just check for $myrow['date'.$i] != '-00-00' ?? Thanks. I'll make your change. While you're about it, remove the quotes from while ($i = '30') { as well -- saves a conversion from string to integer each time round the loop (well, unless PHP optimises it out of the loop, but why take the chance?!). Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning Information Services, JG125, James Graham Building, Leeds Metropolitan University, Beckett Park, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php