Jump to content

Recommended Posts

Trying to make "business name" a link but it makes all 4 rows a link. I have tried moving the closing </a> around but still not working.

 

Thanks for any help.

 

while($row = mysql_fetch_array($result))  {		

	echo "<a href='view-listing.php?contact_id= " .$row['contact_id']. "'/>"   .stripslashes($row['business_name']). "<br/>";
	echo $row['address']. "<br/>";
	echo $row['city']. ', '. $row['state']. ' '.$row['zip']."<br/>";
	echo format_phone($row['phone']);
	echo "<br/><br/>";
}

Link to comment
https://forums.phpfreaks.com/topic/177699-what-is-wrong-with-this/
Share on other sites

The anchor tag is not self closing:

 

<a href="some link" />

This is invalid HTML! Anchor tag does not close itself!

 

<a href="some link">Link text</a>

This is correct HTML. Anchor tag needs a closing tag.

 

By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all?

 

Double quotes tell PHP to parse the string for PHP variables, classes, etc. If you remove all those variables and classes from the string, then you're telling PHP to parse a string that doesn't have anything to parse in it! You're wasting processing cycles parsing a string that you already know has nothing to parse because you've explicitly removed all the PHP from those strings!

 

Use single quotes instead, it saves processing time!

while($row = mysql_fetch_array($result))  {      
      
       "<a href='view-listing.php?contact_id= " .$row['contact_id']. "'/>"   .stripslashes($row['business_name']). "</a><br/>";
      echo $row['address']. "<br/>";
      echo $row['city']. ', '. $row['state']. ' '.$row['zip']."<br/>";
      echo format_phone($row['phone']);
      echo "<br/><br/>";
   }

By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all?

 

Because variables will interpolate within double quotes so you don't have to use concatenation.  This way is cleaner and faster (AFAIK).

 

I actually prefer this format:

 

echo "stripslashes({$row['business_name']})
";

By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all?

 

Because variables will interpolate within double quotes so you don't have to use concatenation.  This way is cleaner and faster (AFAIK).

 

I actually prefer this format:

 

echo "<a href='view-listing.php?contact_id={$row['contact_id']}'>stripslashes({$row['business_name']})</a><br/>";

 

Except that he already concatenated his string as I point out in the post you quoted. Its wasting processing cycles.

By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all?

 

Because variables will interpolate within double quotes so you don't have to use concatenation.  This way is cleaner and faster (AFAIK).

 

I actually prefer this format:

 

echo "<a href='view-listing.php?contact_id={$row['contact_id']}'>stripslashes({$row['business_name']})</a><br/>";

that won't work .. i'm assuming you meant to:

 

echo "<a href='view-listing.php?contact_id={$row['contact_id']}'>".stripslashes({$row['business_name']})."</a><br/>";

By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all?

 

Because variables will interpolate within double quotes so you don't have to use concatenation.  This way is cleaner and faster (AFAIK).

 

I actually prefer this format:

 

echo "stripslashes({$row['business_name']})
";

that won't work .. i'm assuming you meant to:

 

echo "".stripslashes({$row['business_name']})."
";

 

Actually no, I just had a brain lapse and thought you could execute a PHP function in a string.  But yeah, that's the way I would have done it.

 

By the way, if you're using double quotes in PHP and then concatenating your variables to them, why use double quotes at all?

 

Because variables will interpolate within double quotes so you don't have to use concatenation.  This way is cleaner and faster (AFAIK).

 

I actually prefer this format:

 

echo "stripslashes({$row['business_name']})
";

 

Except that he already concatenated his string as I point out in the post you quoted. Its wasting processing cycles.

 

I understand that, I wasn't disagreeing even though it seemed like it.  I was giving an alternative that he may find easier.

 

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.