Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/MYSQL - Possible to use php variable inside of mysql field value?
    text
    copied!<p>I am trying to get a variable to display, when used as part of a value inside of a mysql table.</p> <p>To explain my problem, i am going to use a simple example my script would contain something like this:</p> <pre><code>$variable = 'cool'; </code></pre> <p>The value inside of the mysql field would be something like this:</p> <pre><code>This is '.$variable.' wow </code></pre> <p>When i echo this value, it displays as:</p> <pre><code>This is '.$variable.' wow </code></pre> <p>I want it to display as:</p> <pre><code>This is cool wow </code></pre> <p>Here are the two queries i am working with:</p> <pre><code>$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.'" &amp;&amp; (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']); $linkDesc = ($row['desc']); $linkDomain = ($row['domain']); $pageContent .= ' &lt;li&gt;&lt;a href="'.$linkAd.'" target="_tab"&gt;'.$linkDesc.' '.$linkDomain.'&lt;/a&gt;&lt;/li&gt; '; } } </code></pre> <p>Basically, I want to use</p> <pre><code>$model </code></pre> <p>as part of the value inside of the desc field. When</p> <pre><code>$linkDesc </code></pre> <p>is echoed, this will be part of the outcome when</p> <pre><code>$pageContent </code></pre> <p>is echoed. It should display the text along with the value of</p> <pre><code>$model </code></pre> <p>, not just display</p> <pre><code>'.$model.' </code></pre> <p>As it currently does...</p> <p>To view an example of this, you can check out <a href="http://www.free4blackberry.com/downloads/9800/apps.php" rel="nofollow">http://www.free4blackberry.com/downloads/9800/apps.php</a> 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</p> <pre><code>$linkDomain </code></pre> <p>If you read the text of the link you will clearly see my problem.</p> <p>What am i missing here guys?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload