Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

PHP variable in XHTML code

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
NamecheapNamecheap
Watch

freeflow

Established Member
Impact
13
I have tried many different ways but can't get it to work. :'(

Part of the search.php code:
----------------------------------------------
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["1st_field"];

echo "$title" ;
$count++ ;
}
------------------------------------------

XHTML Code:
------------------------------------------
<img class="himgicon" alt="0" src="graphic/0.png" width="10" height="12" /><a href="http://foxnews.mobi" accesskey="0"> Fox News</a><br />
------------------------------------------


What I would like to do:
------------------------------------------
How can I add the xhtml code around the variable $title = foxnews.mobi? The variable $title is taken from a MySQL Database.

Would it also be possible to replace the 0 in 0.png with a variable called $icon
and Fox News with a variable called $description?
------------------------------------------


Thanks a lot for your help!
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Something like this?

echo "<img class='himgicon' alt='0' src='graphic/" . $icon . ".png' width='10' height='12' /><a href='http://" . $title . "' accesskey='0'>" . $description . " </a><br />";


Not sure if I understood you correctly.
 
0
Close
Wuoshi said:
Something like this?

echo "<img class='himgicon' alt='0' src='graphic/" . $icon . ".png' width='10' height='12' /><a href='http://" . $title . "' accesskey='0'>" . $description . " </a><br />";


Not sure if I understood you correctly.
That solves, i think.
Let me make it more "readable"

PHP:
printf('<img class="himgicon" alt="0" src="graphic/%s.png" width="10" height="12" />', $icon);
printf('<a href="http://%s" accesskey="0">%s</a>', $title, $description);
echo('<br />';
 
0
Close
xrvel said:
That solves, i think.
Let me make it more "readable"
My god, you consider printf 'readable'?
PHP:
echo "<img class='himgicon' alt='0' src='graphic/{$icon}.png' width='10' height='12' /><a href='http://{$title}' accesskey='0'>{$description}</a><br />";
 
0
Close
HTML:
<img class='himgicon' alt='0' src='graphic/<?=$icon?>.png' width='10' height='12' /><a href='http://<?=$title?>' accesskey='0'><?=$description?></a><br />

Assuming quick tags are on. :tu:
 
0
Close
Daniel said:
HTML:
<img class='himgicon' alt='0' src='graphic/<?=$icon?>.png' width='10' height='12' /><a href='http://<?=$title?>' accesskey='0'><?=$description?></a><br />

Assuming quick tags are on. :tu:


I personally don't like doing it that way. It can get a bit slow if you mix HTML and PHP that way, especially if it's a bit bigger site.
 
0
Close
Thanks a lot, it worked! You made my day. The only problem I have now is filling the variables
$icon & $description with data from MySQL. The $title variable is filled with the following code:

// Build SQL Query
$query = "select Link from Web where Category like \"%$trimmed%\""; // EDIT HERE and specify your table and field names for the SQL query

$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);

// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");

// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["Link"];

echo "<img class='himgicon' alt='0' src='graphic/{$icon}.png' width='10' height='12' /><a href='http://{$title}' accesskey='0'>{$description}</a><br />";

$count++ ;
}
 
0
Close
Problem solved.
 
0
Close
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back