Re: Populating an array from mysql db

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



on 28/8/03 1:09 pm, jeffrey_n_Dyke@Keane.com at jeffrey_n_Dyke@Keane.com
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] > '0000-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 "<p>This course booking runs for 0 days</p><p>";
 }
  else if ($result2 == 1)
  {
    echo "<p>This course booking runs for <b>1</b> day on the following
date:</P><p>";
  }
  else {
    echo "<p>This course booking runs for <b>$result2</b> days on the
following dates: </p><p>";
  }

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</span><br>");
    }
} 

print_dates($bookdate);

?>

Which does what I need. The tricky bit was the //loop

cheers
-- 
Mike Karthauser 
Managing Director - Brightstorm Ltd

Email       >> mikek@brightstorm.co.uk
Web         >> http://www.brightstorm.co.uk
Tel         >> 0117 9426653 (office)
               07939 252144 (mobile)

Snailmail   >> Unit 8, 14 King Square,
               Bristol BS2 8JJ

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux