I inherited a website repair job. I am not very good with arrays and I trying to convert the MySQL date to an easier to read format. I would like to date to be Month-DD-YYYY.

I am able to convert the date when it is not located in an array. But if the date is included in an array I can't figure out how to convert it.

For example the date I wish to convert is located in:


$bid[$cnt]['job_date']

How would I run the conversion script I use on it? The script I use is:


$string = "$date_to_convert";
$stringArray = explode("-", $string);

$date = mktime(0,0,0,$stringArray[1],$stringArray[2],$stringArray[0]);

$convertedDate = date("M-d-Y", $date);

Any help would be greatly appreciated. Here is the full script below. Thanks again for any help.


<?php

// in: $bid_id

// I would like to format the b.job_date in the SELECT statement below.

$bid_qtx = 
"SELECT b.login, b.job_id, b.when_sent, DATE_FORMAT(b.job_date, '%a'), b.job_date,
b.job_fee_type, b.job_fee, b.job_memo, w.hours, w.prid 
FROM jobs_bid AS b LEFT JOIN jobs_web AS w
ON b.job_id=w.id
AND b.job_date=w.DATE
WHERE b.bid_id='$bid_id'
ORDER BY b.job_date;";

$step_qtx =
"SELECT b.step 
FROM jobs_bid AS b 
WHERE b.bid_id='$bid_id' 
GROUP BY b.step;";

if(!($bid_q = mysql_query($bid_qtx))) {

vet_error($bid_qtx);

} else {

$num_bid = mysql_num_rows($bid_q);

if(!$num_bid) {

vet_error("No Bids found.");

} else {

if(!($step_q = mysql_query($step_qtx))) {

vet_error($step_qtx);

} else {

$num_step = mysql_num_rows($step_q);

if($num_step > 1) {

vet_error("There's more than one step!");

for($cnt = 0; $cnt < $num_step; $cnt++) {

list($tstep) = mysql_fetch_row($step_q);

$step_txt .= " $tstep";

}

} else {

list($step_txt) = mysql_fetch_row($step_q);

}

}

for($cnt = 0; $cnt < $num_bid; $cnt++) {

list($tmp_bid_login, $tmp_bid_job_id, $tmp_bid_sent, $bid['day'], $bid['job_date'], $bid[$cnt]['fee_type'], $bid[$cnt]['fee'], $bid[$cnt]['memo'], $bid[$cnt]['hours'], $bid[$cnt]['prid'])= mysql_fetch_row($bid_q);

if(!isset($bid_login)) {

$bid_login = $tmp_bid_login;

} elseif($bid_login != $tmp_bid_login) {

vet_error(__FILE__ . ':' . __LINE__ . "Bid Login Mismatch: $bid_login != $tmp_bid_login");

}


if(!isset($bid_job_id)) {

$bid_job_id = $tmp_bid_job_id;

} elseif($bid_job_id != $tmp_bid_job_id) {

vet_error(__FILE__ . ':' . __LINE__ . "Bid JobID Mismatch: $bid_job_id != $tmp_bid_job_id");

}


if(!isset($bid_sent)) {

$bid_sent = $tmp_bid_sent;

} elseif($bid_sent != $tmp_bid_sent) {

vet_error(__FILE__ . ':' . __LINE__ . "Bid Post Date Mismatch: $bid_sent != $tmp_bid_sent");

}

// $bid_sent, $bid_job_id, $bid_login, are set., $bid is an array...

}

//added h.login and $hosp_login also h.tel_area
//and $hosp_tel_area and other fields after tel_area

$hosp_name_qtx = 
"SELECT h.name, h.login, h.tel_area, h.city, h.tel, h.fax, h.mgr_last_name, h.mgr_first_name,
h.own_last_name, h.own_first_name, h.addr1, h.addr2, h.state, h.zip, j.location
FROM jobs_web AS j LEFT JOIN info_hosp AS h ON (j.hosp_id=h.id) 
WHERE j.id=$bid_job_id LIMIT 1;";

if(!($hname_q = mysql_query($hosp_name_qtx))) {

vet_error($hosp_name_qtx);

} else {

list($hosp_name, $hosp_login, $hosp_tel_area, $hosp_city, $hosp_tel, $hosp_fax,
$hosp_mgr_last_name, $hosp_mgr_first_name, $hosp_own_last_name, $hosp_own_first_name,
$hosp_addr1, $hosp_addr2, $hosp_state, $hosp_zip, $location) = mysql_fetch_row($hname_q);

}

$hosp_email_qtx =
"SELECT email
FROM login
WHERE login='$hosp_login';";

if(!($hospemail_q = mysql_query($hosp_email_qtx))) {
    vet_error($hosp_email_qtx);
} else {
    list($hosp_email) = mysql_fetch_row($hospemail_q);
}

$vet_name_qtx =
"SELECT l.last_name, l.first_name, l.email, i.address_1, i.address_2, i.city, i.state,
i.zipcode, i.tax_id
FROM login as l LEFT JOIN info_doc as i ON (l.login=i.login)
WHERE l.login='$bid_login';";

if(!($vname_q = mysql_query($vet_name_qtx))) {

vet_error($vet_name_qtx);

} else {

list($vet_last, $vet_first, $email, $docAddress1, $docAddress2, $docCity,
$docState, $docZip, $ssn) = mysql_fetch_row($vname_q);

}

echo "<b> Details for Bid ID:</b> $bid_id  <a href=\"./?page=jobs&sub=bid_step_edit&bid_id=$bid_id\">
<b>Step</b></a>: $step_txt<br>";

echo "<table border=1 cellpadding=3 cellspacing=0>

<tr>
<td align=\"center\"><b>Job ID</b></td>
<td align=\"center\"><b>Hospital</b></td>
<td align=\"center\"><b>Vet: L,F (Login)</b></td>
<td align=\"center\"><b>Bid Posted</b></td>
</tr>

<tr>
<td align=\"center\"><a href=\"./?page=jobs&sub=detail_relief&id=$bid_job_id\">$bid_job_id</a></td>
<td align=\"center\">$hosp_name (<a href=\"./?page=users&sub=detail&login=$hosp_login\">$hosp_login</a>)</td>
<td align=\"center\">$vet_last, $vet_first (<a href=\"./?page=users&sub=detail&login=$bid_login\">$bid_login</a>)</td>
<td align=\"center\">$bid_sent</td>
</tr>

</table>

";

echo "<table border=1 cellpadding=3 cellspacing=0>

<tr>

<td align=\"center\"><b>Total Job Dates:</b>$num_bid</td>

</tr>


<tr>

<td align=\"center\">";



for($cnt = 0; $cnt < $num_bid; $cnt++) {

echo $bid[$cnt]['job_date'];



if($cnt < ($num_bid - 1)) {

echo ', ';

}
			}


echo "</tr></table>";

echo "

<form method=\"POST\" action=\"./\">
<input type=\"hidden\" name=\"page\" value=\"jobs\">
<input type=\"hidden\" name=\"bid_id\" value=\"$bid_id\">
<table border=1 cellpadding=3 cellspacing=0>

<tr>
<td align=\"center\"><b>Job Date</b></td>
<td align=\"center\"><b>Job Hours</b></td>
<td align=\"center\"><b>Job Fee (type)</b></td>
<td align=\"center\"><b>Memo</b></td>
<td align=\"center\"><b>Modify Bid</b></td>
<td align=\"center\"><b>Confirm/NOGO</b></td>
</tr>";

for($cnt = 0; $cnt < $num_bid; $cnt++) {

list($tlogin, $tjob, $twhen, $jdate, $jfeet, $jfee, $jmemo, $dhosp) = mysql_fetch_row($bid_q);

echo "
<tr>

<td align=\"center\">" . $bid['day'] . " " . $bid['job_date'] . "</td>
<td align=\"center\">" . $bid[$cnt]['hours'] . "</td>
<td align=\"center\">" . $bid[$cnt]['fee'] . " (" . $bid[$cnt]['fee_type'] . ")</td>
<td align=\"center\">" . $bid[$cnt]['memo'] . "</td>
<td align=\"center\"><input type=\"checkbox\" name=\"bid_date[]\" value=\"" . $bid[$cnt]['job_date'] . "\"></td>
<td align=\"center\"><input type=\"checkbox\" name=\"bid_info[]\" value=\"
Date:" . $bid['day'] . " " . $bid[$cnt]['job_date'] . ",
Hours:" . $bid[$cnt]['hours'] . ",
Fee:$" . $bid[$cnt]['fee'] . " (" . $bid[$cnt]['fee_type'] . "),
Memo:" . $bid[$cnt]['memo'] . "
\" checked></td>
</tr>";

}	


?>


I had to trim the code. I am pretty sure that I didn't cut out anything important.

    Write a Reply...