Jump to content


Photo

Changing table data's display


  • Please log in to reply
3 replies to this topic

#1 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 24 September 2006 - 10:59 AM

 while ($rows = mysql_fetch_assoc($result))
   {
     echo "<tr>";
     foreach ($rows as $data)

I AM TRYING TO DISPLAY CERTAIN COLUMN VALUES HERE
DIFFERENTLY TO MY TABLE DATA
         
       'UnitPrice' to get a preceding £ sign
       'Qty'  to be preceded with the word "off"      
       'RunningTotal' to get a preceding £ sign
       'Orderdate' to display date("j-M-Y", strtotime('orderdate'))


I tried a case statement built from previos reference, but cannot find which contains the data to modify. Thanks

echo "<td align='left'><b><font face='Arial' size='1'>". $data . "</font></b></td>";

     }
   }
 }else{
   echo "<tr><td colspan='" . ($i+1) . "'>No Results found!</td></tr>";

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 24 September 2006 - 11:30 AM

in that case do something like

<?php
while($rows = mysql_fetch_assoc($result)){
echo "<td>".$row["fieldname"]."</td>\n"
."<td>".$row["another_fieldName"]."</td>\n"
}
?>

Where fieldname is the name of the field in the database
Tell me the problem, I will try tell you the solution

#3 sasa

sasa
  • Staff Alumni
  • Advanced Member
  • 2,804 posts
  • LocationHrvatska

Posted 24 September 2006 - 11:52 AM

try
foreach ($rows as $k => $data) {
	switch ($k) {
		case 'UnitPrice':
		case 'RunningTotal':
		$data = '&pound; '.$data;
		break;
		case 'Qty':
		$data = 'off '.$data;
		break;
		case 'Orderdate':
		$data = date("j-M-Y", strtotime($data));
	}
	echo "<td align='left'><font face='Arial' size='5'>". $data . "</font></td>"; 
}


#4 cyprus

cyprus
  • Members
  • PipPipPip
  • Advanced Member
  • 68 posts

Posted 24 September 2006 - 12:20 PM

Yet again sasa thanks. Just had to swop the "off", ie cart before the horse, but that was minor as it all works, excellent, thanks again




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users