Jump to content

PHP inside HTML inside PHP variable


mcfmullen

Recommended Posts

This would be bet explained by giving you the code that WORKS:

<?php
$phpcode1 = '<a href="http://www.cool.com/wp-content/themes/arjuna-x/itemspec2.php?item=Goat&type=animal">Animal</a>';
?>
<?php echo $phpcode1; ?>

 

The output is a URL link called Animals that goes to the wanted dynamic page. What I want though, is to have this same output but with variables used in place of the actual url (so that the url can be truly dynamic for multiple tables).

 

Here's an example of what I'm trying to do:

<?php
$table = $_GET['type'];
$item = $_GET['item'];
$url='/wp-content/themes/arjuna-x/itemspec2.php?item=';
$url2='&type=';
$phpcode1 = '<a href="<?php bloginfo('url'); ?><?php echo $url; ?><?php echo $item; ?><?php echo $url2; ?><?php echo $table; ?>"><?php echo $item; ?></a>';
?>
<?php echo $phpcode1; ?>

Link to comment
Share on other sites

<?php
$table = $_GET['type'];
$item = $_GET['item'];
$url='/wp-content/themes/arjuna-x/itemspec2.php?item=';
$url2='&type=';
$phpcode1 = '<a href="' . loginfo('url') . $url . $item . $url2 . $table . '">' . $item . '</a>';
echo $phpcode1; ?>

Link to comment
Share on other sites

There seems to be a side-effect to the code. It has broken my styling (I.E. font sizes are the same throughout) for the page. Would anyone know why that is? Previous to the change, the styling was fine.

 

Before the change (styling OK):

<div class="post" id="post-<?php the_ID(); ?>">
	<div class="postHeader">
		<center><h2 class="postTitle"><span><a href="http://www.cool.com/wp-content/themes/arjuna-x/itemspec2.php?item=Goat&type=animal">Animal</a></span></h2></center>
		<div class="bottom"><div>
			<span class="postDate"></span>
			<?php if($arjunaOptions['postsShowAuthor']): ?>
			<span class="postAuthor"></span>
			<?php endif; ?>
			<span></span></a>
		</div></div>
	</div>

*Lots of wordpress code for the content*
</div>

 

With the change (the broken styling):

<div class="post" id="post-<?php the_ID(); ?>">
	<div class="postHeader">
		<center><h2 class="postTitle"><span><?php echo $phpcode1; ?></span></h2></center>
		<div class="bottom"><div>
			<span class="postDate"></span>
			<?php if($arjunaOptions['postsShowAuthor']): ?>
			<span class="postAuthor"></span>
			<?php endif; ?>
			<span></span></a>
		</div></div>
	</div>

*Lots of wordpress code for the content*
</div>

 

Link to comment
Share on other sites

I've compared the source code using a file comparision program and no differences are found, which is quite perplexing. I will attempt to figure out a way around it though.

 

I do have one last question though:

 

I have the following MySQL query:

$sql = "SELECT * FROM (.$table LEFT JOIN animalThemes2 USING (Name)) LEFT JOIN animalMethods2 USING (Name) WHERE .$table.Name = '{$item}'";

 

The variable $table contains the word "animal". Is there any way to combine that variable with the Themes2 or Methods2 suffixes?

 

I.E.:

$sql = "SELECT * FROM (.$table LEFT JOIN .$tableThemes2 USING (Name)) LEFT JOIN .$tableMethods2 USING (Name) WHERE .$table.Name = '{$item}'";

 

Obviously the code above doesn't work, otherwise I wouldn't ask...

Link to comment
Share on other sites

You mean like:

$sql = "SELECT * FROM " . $table . " LEFT JOIN " . $table . $Themes2 . " USING (Name) LEFT JOIN " . $table . $Methods2 . " USING (Name) WHERE " . $table . ".Name = '" . mysql_real_escape_string($item) . "'";

 

or:

 

$sql = "SELECT * FROM " . $table . " LEFT JOIN " . $table . "Themes2 USING (Name) LEFT JOIN " . $table . "Methods2 USING (Name) WHERE " . $table . ".Name = '" . mysql_real_escape_string($item) . "'";

Link to comment
Share on other sites

PHP interpolates strings, and I try and make use of that for readability, rather than using concatenation all over the place.

 

$sql = "SELECT * FROM $table LEFT JOIN $table$Themes2 USING (Name) LEFT JOIN $table$Methods2 USING (Name) WHERE $table.Name = '$item'";

 

Link to comment
Share on other sites

PHP interpolates strings, and I try and make use of that for readability, rather than using concatenation all over the place.

 

$sql = "SELECT * FROM $table LEFT JOIN $table$Themes2 USING (Name) LEFT JOIN $table$Methods2 USING (Name) WHERE $table.Name = '$item'";

 

Old habbits die hard lol

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.