Jump to content

[SOLVED] Can this be turned into a function


Voodoo Jai

Recommended Posts

I have this piece of code that is used a number of times within my page so I would like to turn into a function can it be done.

<?php 
//***********************************************************************************************
// if listing type is either Standard or Superior then show row OPENING HOURS
//***********************************************************************************************
if ($row_away['List_Type'] == 3 || $row_away['List_Type'] == 5 ) 
{
echo"<table width=\"749\" border=\"0\">";
echo "<tr>
   <td align=\"center\">
   <strong>
   Opening Hours
   </strong>";

   echo"<table border=\"0\">
   <tr>
      <td width=\"50\" align=\"left\">
     Mon
  </td>";

  $a = $row_away['Mon_hr_1'];
  
  if ($a <> NULL) 
  {
     echo"<td width=\"60\" align=\"right\">";
     echo $row_away['Mon_hr_1']. "-". $row_away['Mon_min_1'];
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $row_away['MonHrAmPm'];
	 echo "</td>";

	 echo"<td width=\"30\" align=\"center\">";
	 echo "to";
	 echo "</td>";

	 echo"<td width=\"60\" align=\"right\">";
	 echo $row_away['Mon_hr_2']. "-". $row_away['Mon_min_2'];
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $row_away['Mon2HrAmPm'];
	 echo "</td>";

	 echo"<td width=\"60\" align=\"right\">";
     echo $row_away['Mon_hr_3']. "-". $row_away['Mon_min_3'];
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $row_away['Mon3HrAmPm'];
	 echo "</td>";

	 echo "<td width=\"30\" align=\"center\">";
	 echo "to";
	 echo "</td>";

	 echo "<td width=\"60\" align=\"right\">";
	 echo $row_away['Mon_hr_4']. "-". $row_away['Mon_min_4'];
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $row_away['Mon4HrAmPm'];
	 echo "</td>";
  }
  else
  {
     echo"<td width=\"535\" align=\"left\">";
     echo "Closed";
	 echo"</td>";
  }
  echo"</tr>";
  echo"</table>";
  echo"</td>
  </tr>
  </table>";
   }
?>

 

I have tried to create one but I think I'm on the wrong track, heres my creation

 

<?php 
function OpenTime($ListType, $Day, $Hr1, $Min1, $Hr1AmPm, $Hr2, $Min2, $Hr2AmPm, $Hr3, $Min3, $Hr3AmPm, $Hr4, $Min4, $Hr4AmPm)
{
//***********************************************************************************************
// if listing type is either Standard or Superior then show row OPENING HOURS
//***********************************************************************************************
if ($ListType == 3 || $ListType == 5 ) 
{
echo"<table width=\"749\" border=\"0\">";
echo "<tr>
   <td align=\"center\">
   <strong>
   Opening Hours
   </strong>";

   echo"<table border=\"0\">
   <tr>
      <td width=\"50\" align=\"left\">
     $Day
  </td>";

  $a = $Hr1;
  
  if ($a <> NULL) 
  {
     echo"<td width=\"60\" align=\"right\">";
     echo $Hr1. "-". $Min1;
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $Hr1AmPm;
	 echo "</td>";

	 echo"<td width=\"30\" align=\"center\">";
	 echo "to";
	 echo "</td>";

	 echo"<td width=\"60\" align=\"right\">";
	 echo $Hr2. "-". $Min2;
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $Hr2AmPm;
	 echo "</td>";

	 echo"<td width=\"60\" align=\"right\">";
     echo $Hr3. "-". $Min3;
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $Hr3AmPm;
	 echo "</td>";

	 echo "<td width=\"30\" align=\"center\">";
	 echo "to";
	 echo "</td>";

	 echo "<td width=\"60\" align=\"right\">";
	 echo $Hr4. "-". $Min4;
	 echo "</td>";

	 echo"<td width=\"50\" align=\"left\">";
	 echo $Hr4AmPm;
	 echo "</td>";
  }
  else
  {
     echo"<td width=\"535\" align=\"left\">";
     echo "Closed";
	 echo"</td>";
  }
  echo"</tr>";
  echo"</table>";
  echo"</td>
  </tr>
  </table>";
   }
}
OpenTime($row_away['List_Type'], "Mon",
         $row_away['Mon_hr_1'], $row_away['Mon_min_1'], $row_away['MonHrAmPm'], 
         $row_away['Mon_hr_2'], $row_away['Mon_min_2'], $row_away['Mon2HrAmPm']
 $row_away['Mon_hr_3'], $row_away['Mon_min_3'] $row_away['Mon3HrAmPm']
 $row_away['Mon_hr_4'], $row_away['Mon_min_4'], $row_away['Mon4HrAmPm']);
?>

 

I think the problem is the HTML code within the function.

 

Hope someone can give some help without laughting to much

 

VoodooJai

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.