Jump to content
DontheCat

variable not echoing

Recommended Posts

I have stored some texts in the database associated with a variable name in my database ... I intend to use this in my site as global text using the variable name ...

This is the code I've created in a php file, which I'm 'including' in my webpage .

<div style="display:none"> 
<?php
mysqli_select_db($xxx, $database_xxx);
$query_Recordset1 = "SELECT * FROM text_declares";
$Recordset1 = mysqli_query($xxx, $query_Recordset1) or die(mysqli_error());
$row_Recordset1 = mysqli_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysqli_num_rows($Recordset1);
 ?>
  <?php do { 
      echo '$' . $row_Recordset1['bd_variable'] . ' = "' . $row_Recordset1['bd_desc'] . '"<br>'; 
    } while ($row_Recordset1 = mysqli_fetch_assoc($Recordset1)); 
	echo 'Company Name  =' . $company_full_name   ;
	?>
</div>

When i execute the file, this is the ouput

Quote

$company_full_name = "Some Company Pvt. Ltd."
$company_small_name = "Some Company"
$company_short = "Some"
$total_placements = "30000"
$total_verticals = "35"
$total_emps = "350"
$total_offices = "7"
$total_countries_present = "4"

Notice: Undefined variable: company_full_name in global_text_declares.php on line 13
Company Name =

not able to figure out why the $company_full_name is not showing in the echo.

Many Thanks for the support .

Share this post


Link to post
Share on other sites

The clue is in the error message. The variable $company_full_name has not been assigned a value anywhere.

Share this post


Link to post
Share on other sites

Your first retrieved row is being output correctly while your second one (and later) is being output incorrectly.

Share this post


Link to post
Share on other sites

I think this is what you are trying to do

do {
    ${$row_Recordset1['bd_variable']} = $row_Recordset1['bd_desc'];
} while (...)

echo "$company_full_name - $company_small_name";         //--> Some Company Pvt, Ltd - Some Company

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Many Thanks Barand... 🙋‍♂️

I had tried it with a regular bracket instead of the curly and got a syntax error. 🙂

But I still haven't figured out what you meant here... The 1st row outputs the $company_full_name and i was trying to echo that.

1 hour ago, ginerjm said:

Your first retrieved row is being output correctly while your second one (and later) is being output incorrectly.

Thanks again.... Cheers

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

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.