Jump to content

Using ucwords for sql results


wright67uk

Recommended Posts

Hello, im looking to return all of my sql results in proper case / first letter capitalised.

 

I see from the manual you can use

 

<?php
$variable1 = 'my non capitalised text here';
$variable1 = ucwords($variable1); 
echo $variable1; // now my text reads My Non Capitalised Text Here
?>

How can I apply somthing like the above to the results of my query without effecting the rest of my script?

 

Is it the case of doing somthing like;

 

$query = ucwords($query);

 

<?php
$title ="TITLE GOES HERE";
$query = mysql_query("SELECT DISTINCT subtype FROM business WHERE type ='Accommodation' AND confirmed ='Yes' ORDER BY name");
echo mysql_error();
while($ntx=mysql_fetch_row($query)) $nt[] = $ntx[0];
$i = -1;
foreach($nt as $value)
{$i++;
$FileName = str_replace(' ','_',$nt[$i]) . ".php";
$FileUsed = str_replace('_',' ',$nt[$i]);
echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>"  . $nt[$i] . "</a>" . "<br/>";
$FileHandle = fopen($FileName, 'w') or die("cant open file");
$pageContents = file_get_contents("header.php");
fwrite($FileHandle,"$pageContents");}
fclose($FileHandle);
?>

Link to comment
https://forums.phpfreaks.com/topic/238916-using-ucwords-for-sql-results/
Share on other sites

You wouldn't use ucwords on the $query variable. You'll need to use it on the specific $nt variable. I'm guessing here?

echo "<a href='" . str_replace(' ','_',$nt[$i]) . ".php?title=$title&subtype=$FileUsed'>"  . ucwords($nt[$i]) . "</a>" . "<br/>";

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.