Forum Moderators: coopster

Message Too Old, No Replies

Formatting data from a database with the substr()..

substr().

         

Verity9802

3:52 pm on Jul 6, 2004 (gmt 0)

10+ Year Member



Hi all,

I'm a newbie and I have a quick question about formatting HTML and PHP. I'm reading data from a database and the code is as follows:

// Fetch each of the query rows
while ($row = @ odbc_fetch_array($result))
{
// Print one row of results
echo "\n<tr>\n\t<td>{$row["TOPIC"]}</td>";
echo "\n\t<td>{$row["MEANDEPTH"]}</td>";
echo "\n\t<td>{$row["VARIANCE"]}</td>";
echo "\n\t<td>{$row["BATTERY"]}</td>";
} // end while loop body

However, I wish to format the data collected from VARIANCE column with the substr() function. I've tried numerous ways of doing this but nothing is working. I'm pretty sure it's all to do with the formating of various tags. The obvious (to me atleast) way to go about doing this would be:

echo "\n\t<td>substr({$row["VARIANCE"]},3)</td>";

Could someone help me with this? I know this is pretty trival but there's surprisingly not much info on how to go about doing this. Thanks again!

James

coopster

4:14 pm on Jul 6, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld, Verity9802!

You could try concatenation.

echo "\n\t<td>" . substr($row["VARIANCE"], 3) . "</td>";

Another option would be to SUBSTRING the data as it is read from your database.

WhosAWhata

4:16 pm on Jul 6, 2004 (gmt 0)

10+ Year Member



echo "\n\t<td>".substr({$row["VARIANCE"]},3)."</td>";

Verity9802

10:09 am on Jul 7, 2004 (gmt 0)

10+ Year Member



Thanks everyone! That worked like a charm. Cheers.

James