PHP MYSQL - Echo mysql value containing a PHP variable? -



PHP MYSQL - Echo mysql value containing a PHP variable? -

i trying variable display, when used part of value within of mysql table.

$variable = 'cool'; mysql field value "this '.$variable.' wow"

when echo value, displays as:

this '.$variable.' wow

i want display as:

this cool wow

what trick here?

@mark sorry im new this

$linkquery3 = 'select model models model_id = "'.$pagemodel.'" '; $sql15 = mysql_query($linkquery3) or die(mysql_error()); if (mysql_num_rows($sql15) == 0) { die('no results.'); } else { while($row = mysql_fetch_assoc($sql15)) { $model = stripslashes($row['model']); } } $linkquery2 = 'select l.link , l.desc , l.domid , d.domain links l inner bring together domains d on d.domid = l.domid l.catid="'.$pagecat.'" && (l.modid="1" || l.modid="'.$pagemodel.'") order domain '; $sql3 = mysql_query($linkquery2) or die(mysql_error()); if (mysql_num_rows($sql3) == 0) { die('no results.'); } else { $pagecontent .= ''; while($row = mysql_fetch_assoc($sql3)) { $linkad = ($row['link']); $linkdesc = ($row['desc']); $linkdomain = ($row['domain']); $pagecontent .= ' <li><a href="'.$linkad.'" target="_tab">'.$linkdesc.' '.$linkdomain.'</a></li> '; } }

what doing here trying echo string database, replace placeholder text specific value. cannot storing string php parser treat in specific way, , expect php treat same way when sees string @ run-time.

here suggest: utilize more straightforward delimiter part of string wish replace, so:

"this :variable: wow"

and utilize str_replace() echo right thing. (you can utilize sprintf() same purpose.)

echo str_replace(':variable:', $variable, $mystring);

(here $mystring contains string database.)

php mysql variables

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -