mcfmullen Posted June 21, 2010 Share Posted June 21, 2010 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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/ Share on other sites More sharing options...
Alex Posted June 21, 2010 Share Posted June 21, 2010 Check out the manual on how to concatenate strings. $phpcode1 = '<a href="' . bloginfo('url') . $url . $item . '&type=' . $table . '">' . $item . '</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1074773 Share on other sites More sharing options...
Andy-H Posted June 21, 2010 Share Posted June 21, 2010 <?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; ?> Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1074774 Share on other sites More sharing options...
mcfmullen Posted June 21, 2010 Author Share Posted June 21, 2010 I receive a Fatal error: Call to undefined function loginfo() and cannot seem to find any information about such a function, I'd like to learn more... Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1074792 Share on other sites More sharing options...
Alex Posted June 21, 2010 Share Posted June 21, 2010 That was a typo.. He meant to type bloginfo() which you had in your original post but left off the b. Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1074793 Share on other sites More sharing options...
mcfmullen Posted June 21, 2010 Author Share Posted June 21, 2010 Silly me, I just realized that as well but you beat me to it! Thank you so much! Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1074794 Share on other sites More sharing options...
mcfmullen Posted June 21, 2010 Author Share Posted June 21, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1074799 Share on other sites More sharing options...
Alex Posted June 21, 2010 Share Posted June 21, 2010 Just compare the two HTML outputs to see what the difference is. Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1075264 Share on other sites More sharing options...
mcfmullen Posted June 22, 2010 Author Share Posted June 22, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1075322 Share on other sites More sharing options...
Andy-H Posted June 22, 2010 Share Posted June 22, 2010 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) . "'"; Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1075328 Share on other sites More sharing options...
gizmola Posted June 22, 2010 Share Posted June 22, 2010 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1075332 Share on other sites More sharing options...
mcfmullen Posted June 22, 2010 Author Share Posted June 22, 2010 Thank you so much everyone! Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1075348 Share on other sites More sharing options...
Andy-H Posted June 22, 2010 Share Posted June 22, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/205366-php-inside-html-inside-php-variable/#findComment-1075599 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.