Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7414805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:10:24+00:00 2026-05-29T07:10:24+00:00

I am trying to echo a variable, from a mysql query, like this: <?php

  • 0

I am trying to echo a variable, from a mysql query, like this:

<?php
...//FYI: mysql connection already established
//Table: title 
//col: page | title
//row: html | "$domain_name: Welcome"

$page_id = basename(getcwd());
$domain_name = "Name of My Domain";

$sql = "SELECT title FROM mydatabase.title WHERE page = '$page_id' ";
//The query's result is 1 row
$dbq = mysql_query ($sql);
$dba = mysql_fetch_array( $dbq );
echo $dba["title"];
//it outputs: $domain_name: Welcome", instead of "Name of My Domain: Welcome"
?>

What am I doing wrong?
I am trying to replace the “variable [$domain_name] in the table’s content for it’s php value. -I thought ” (double quotes) are supposed to replace the variable with it’s value.

PS. I am a beginner

EDIT 2/7/2012, 3:14pm: Forgot to mention. The query works OK. $dba[‘title’] has “$domain_name: Welcome” as a value. The problem is, it is not replacing $domain_name

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T07:10:25+00:00Added an answer on May 29, 2026 at 7:10 am

    I thought ” (double quotes) are supposed to replace the variable with it’s value.

    That works only in case when you specify the string in your code. If the string comes from outside – it doesn’t have such magic behaviour.

    So the only solution you could go with is:

    echo str_replace('$domain_name', $domain_name, $dba["title"]);
    

    Or you could go with some sort of template engine like Twig or Smarty and treat your database value as a template, and your variables as the data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an element like this: <div id=foo_<?php echo $id;?> class=hidden></div> I'm trying if
i am trying to pull data from one table, compare columns to a variable,
Trying to get my css / C# functions to look like this: body {
I'm trying to put a mysql query into a function, however when I do
I am trying to pass a php variable to my LinkONCLick4 function, but for
I'm trying to install MySQL on Ubuntu Natty from a shell script. However, I
I'm trying to retrieve the response of this script: <?php require_once(db_connect.php); $get = mysql_query(SELECT
I'm trying to feed data from SQL database to FLEX, using php script in
Hey guys, I'm using smarty and php I am trying to make this function
I'm trying to run mysql queries from a remote server (server B) and then

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.