Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

PHP variable in XHTML code

Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
SpaceshipSpaceship
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
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
•••
Problem solved.
 
0
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

New in Parking: updated way to act on many domains or inquiries at once
Your domain list and inquiry list now have a bar above and below the list. Check the items you want, then choose an action in the bar...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back