I am trying to get a variable to display, when used as part of a value inside of a mysql table.
To explain my problem, i am going to use a simple example my script would contain something like this:
$variable = 'cool';
The value inside of the mysql field would be something like this:
This is '.$variable.' wow
When i echo this value, it displays as:
This is '.$variable.' wow
I want it to display as:
This is cool wow
Here are the two queries i am working with:
$linkQuery3 = 'SELECT model FROM models WHERE model_id = "'.$pageModel.'"
';
$sql15 = mysql_query($linkQuery3) or die(mysql_error());
if (mysql_num_rows($sql15) == 0) {
die('No model results.');
} else {
while($row = mysql_fetch_assoc($sql15)) {
$model = ($row['model']);
}
}
$linkQuery2 = 'SELECT l.link , l.desc , l.domId , d.domain
FROM links l
INNER JOIN domains d
ON d.domId = l.domId
WHERE l.catId="'.$pageCat.'" && (l.modId="1" || l.modId="'.$pageModel.'")
ORDER BY domain
';
$sql3 = mysql_query($linkQuery2) or die(mysql_error());
if (mysql_num_rows($sql3) == 0) {
die('No link results.');
} else {
$pageContent .= '';
while($row = mysql_fetch_assoc($sql3)) {
$linkAd = stripslashes($row['link']开发者_Go百科);
$linkDesc = ($row['desc']);
$linkDomain = ($row['domain']);
$pageContent .= '
<li><a href="'.$linkAd.'" target="_tab">'.$linkDesc.' '.$linkDomain.'</a></li>
';
}
}
Basically, I want to use
$model
as part of the value inside of the desc field. When
$linkDesc
is echoed, this will be part of the outcome when
$pageContent
is echoed. It should display the text along with the value of
$model
, not just display
'.$model.'
As it currently does...
To view an example of this, you can check out http://www.free4blackberry.com/downloads/9800/apps.php it is one of my pages on my website, near the bottom of the page, you will see a list of links. The 7th one from the bottom links to en.softonic as
$linkDomain
If you read the text of the link you will clearly see my problem.
What am i missing here guys?
Dude, try to do more simple, your question is too long. But, based on what I understood I think that what you need is store a variable on database field like:
"This is '" .$variable. "' wow"
If true, so when you will save the value you can serialize it before save on database and unserialize when rescue from database, like this:
"INSERT INTO may_table (field) values (" . serialize("This is '$variable' wow") . ")";
$model = unserialize($row['field']);
So when you rescue the value "$model" will return as a php variable.
Note: I put here just a example of how you could use the serialize/unserialize php functions and not the complete script.
I did a test and the works fine on this way:
$c = serialize("This is '$variable' wow");
$variable = "test";
echo unserialize($c); //outputs This is 'teste' wow
Try again please.
Maybe the eval function will work. http://php.net/manual/en/function.eval.php
I don't think that's possible, I don't recommend eval functions but they may help. you can replace the value with str_replace function though...
精彩评论