Jump to content

PHP Link with two variables in a row


CNGHL

Recommended Posts

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>";
Link to comment
Share on other sites

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 />";
Link to comment
Share on other sites

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 by benanamen
Link to comment
Share on other sites

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>";
  • Like 1
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.