CNGHL Posted November 8, 2015 Share Posted November 8, 2015 Hi There, I am having trouble with a link, I am trying to put two variable into a single link but I cannot seem to get it to work right, the following code gives me a white screen error so its not very helpful, when doing the coding in Notebook ++ the . .$row['ColorID'] is a different shade then the rest of the script so I am assuming I missing a semi colon or " or ' a long the way, any help would be wonderful echo "<td width='100'><div align='center'><a href=\"Part_Color.php?PartID=".$row['PartID'].'&Color_ID=" . $row['ColorID'] . "" style="text-decoration:none;">'.$row['PartID']."<br>"; Quote Link to comment https://forums.phpfreaks.com/topic/299364-php-link-with-two-variables-in-a-row/ Share on other sites More sharing options...
QuickOldCar Posted November 8, 2015 Share Posted November 8, 2015 An easy way to do it is double quotes outside and all singles within, at concatenation use double quotes and a decimal point. Or you can go through using backslashed double quotes. echo "<td width='100'><div align='center'><a href='Part_Color.php?PartID=".$row['PartID']."&Color_ID=" . $row['ColorID'] ."' style='text-decoration:none;'>".$row['PartID']."<br />"; Quote Link to comment https://forums.phpfreaks.com/topic/299364-php-link-with-two-variables-in-a-row/#findComment-1525969 Share on other sites More sharing options...
benanamen Posted November 8, 2015 Share Posted November 8, 2015 (edited) If you use the curly syntax you wont have to do all that variable escaping and concatenation and you will avoid the problem beginners usually have especially if your editor does not have syntax highlighting. echo "<td width=\"100\"><div align=\"center\"><a href=\"Part_Color.php?PartID={$row['PartID']}&Color_ID={$row['ColorID']}\" style=\"text-decoration:none;><br>{$row['PartID']}<br>";?> Edited November 8, 2015 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/299364-php-link-with-two-variables-in-a-row/#findComment-1526011 Share on other sites More sharing options...
mac_gyver Posted November 8, 2015 Share Posted November 8, 2015 a slightly more dynamic slant on doing this - // dynamically build the query string part of a url, from whatever part(s) it is made of - $q = array(); $q['PartID'] = $row['PartID']; $q['Color_ID'] = $row['ColorID']; // add any other key/value pairs here.... $qs = http_build_query($q,'','&'); // build urlencoded query string, with properly encoded & $label = htmlentities($row['PartID'],ENT_QUOTES); // use html entities on any content // this is just the <a></a> link part of what you are outputting, which appears to be incomplete/broken in your code echo "<a href='Part_Color.php?$qs' style='text-decoration:none;'>$label</a>"; 1 Quote Link to comment https://forums.phpfreaks.com/topic/299364-php-link-with-two-variables-in-a-row/#findComment-1526033 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.