Below shown code after fetching data from database not listing the result?

<?php 
                                $answer = $listcareer['bigcontent'];

                                $bigcontent = substr($answer,0,10);
                                print_r($bigcontent);
                                exit();
                                        ?>

Dani AI

Generated

Quick checklist and targeted debugging for : the usual reasons substr appears to “do nothing” are not a bug in PHP but one of these — the value is empty/NULL, the row was fetched as an object instead of an array, the string contains only invisible/control bytes (BOM, NUL, whitespace), or the text is UTF-8 multibyte and you need a multibyte-safe function. was right to ask about the query/field name; confirm the fetch mode and that the column actually contains printable text.

Steps to inspect the actual data (run these before truncating):

error_reporting(E_ALL);
ini_set('display_errors', 1);

var_dump($row);                     // entire fetched row
var_dump(isset($row['bigcontent'])); // exists?
var_dump(gettype($row['bigcontent']));
var_dump(strlen($row['bigcontent']));
var_dump(mb_strlen($row['bigcontent'], 'UTF-8')); // requires mbstring

If var_dump shows NULL or zero length, the problem is before substr (query/fetch). If the length is nonzero but output looks blank, inspect the first bytes (BOM or control chars) with a hex dump (for example, bin2hex).

If text is UTF-8, use the multibyte-safe truncation:

$short = mb_substr($text, 0, 10, 'UTF-8');
var_dump($short);

If your fetch returns an object (see ), use ->bigcontent instead of array syntax. Also be cautious truncating HTML — use an HTML-aware truncator or strip_tags() first to avoid breaking tags.

If these checks still show nothing, paste the var_dump output (row structure plus length values). That makes it straightforward to identify whether the issue is a wrong field name, fetch style, or invisible bytes.

Recommended Answers

All 2 Replies

hi Jiby_1 , please show your query and also make sure that the field name is spelled correct.

Member Avatar for Member #120589
$answer = $listcareer['bigcontent'];
echo "Content of \$answer = $answer <br />";
$bigcontent = substr($answer,0,10);
echo "Content of \$bigcontent = $bigcontent";
exit();
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.