Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code is slow to execute:

Status
Not open for further replies.

mancroft

Programmer
Joined
Oct 26, 2002
Messages
267
Location
GB
Code is slow to execute:

The following code to create a url is very slow to execute so when the url link is clicked on, the page takes several seconds to open. Is there a way to speed this up?

Code:
$theuserid = "3";
$url =  '<a href = edit.php?action=edit&item=';
$url .= "$theuserid";
$url .= ' target=\"_blank\">';
$url .= "$theuserid";
$url .= '</a>';

echo $url;
 
Try to acceess the URL by typing into the address bar of the browser, how long does it take to come back. In this case I think it does deoend on ehat the target URL is doing, PHP wil have no difficulty generating the URL, but remember when you click it the page is in your browser, PHP has finished it wirk.
 
At the moment you have a full page in your browser PHP has finished its work - it is a server side technology. Opening the URL is a client side function.

Recommendation:
Double quote the attributes in the <a> tag.
Code:
$theuserid = "3";
$url =  '<a href = "edit.php?action=edit&item=';
$url .= "$theuserid";
#Note: there's no need to escape the double quotes within a single quoted context
$url .= ' target="_blank">';
$url .= $theuserid;
$url .= '</a>';

echo $url;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top