Unstoppable Domains

PHP variable in XHTML code

Spacemail by SpaceshipSpacemail by Spaceship
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.
.US domains.US domains
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
•••

We're social

Unstoppable Domains
Domain Recover
DomainEasy — Live Options
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back