Jump to content

How to disable href in certain cases?


kingnothing

Recommended Posts

hello this is my first post here ,

i have a website where i display videos

with the option to download it wmv

recently i added a new table to the database

and added a link to download in mp3

<a href='$mp3'>$lang_t202</a>

it works great but the problem is some videos dont have a link for mp3

that makes an empty href leading the vistors to the main page and getting them confused

is there a way to get around this ? disable href if its empty ?

 

 

i tried using this

 

if($mp3 != "")

echo "<a href='$mp3'>$lang_t202</a>";

 

else

echo $lang_t202;[/code]

 

and this is the place where i want to put it

but it dosnt work

i am beginner in all this btw

[code=php:0]$F .= "<div align='center'>
<center>

<table class='xtable' width='100%' id='AutoNumber1f5'>

<tr>
<td style='text-align:center' colspan='3' height='50' width='100%' class='xtr'>$lang_t200</td>
</tr>
<tr>
<td width='30%' width='30%' class='xtr'><img src='$folder/icons/table.gif' border='0' alt='$lang_t44' title='$lang_t44'> $lang_t44 :</td>
<td width='35%' class='xtd'><a href='$url'>$lang_t201</a> | [color=red](I WANT TO ADD IT HERE!!!!!)[/color]
</td>
</tr>

<tr>
<td width='30%' width='30%' class='xtr'><img src='$folder/icons/table.gif' border='0' alt='$lang_t45' title='$lang_t45'> $lang_t45 :</td>
<td width='70%' class='xtd'>$catnamef</td>
</tr>
<tr>
<td width='30%' width='30%' class='xtr'><img src='$folder/icons/table.gif' border='0' alt='$lang_t2' title='$lang_t2'> $lang_t2 :</td>
<td width='70%' class='xtd'>$vis</td>
</tr>

</table>
</center>
</div>";

[/code]

Link to comment
https://forums.phpfreaks.com/topic/207043-how-to-disable-href-in-certain-cases/
Share on other sites

EDIT: I missed an entire section... my bad.... below is the adjusted code to make that right. Sorry about that.

 

I added ended the string belonging to $F then add parts of it at a time Give it a try:

$F .= "<div align='center'>
<center>

<table class='xtable' width='100%' id='AutoNumber1f5'>

<tr>
<td style='text-align:center' colspan='3' height='50' width='100%' class='xtr'>$lang_t200</td>
</tr>
<tr>
<td width='30%' width='30%' class='xtr'><img src='$folder/icons/table.gif' border='0' alt='$lang_t44' title='$lang_t44'> $lang_t44 :</td>
<td width='35%' class='xtd'><a href='$url'>$lang_t201</a> | [color=red]"; 
// NOTICE I ENDED THE STRING HERE... I ADD IN THE IF STATEMENTS to the string

//Do what you already thought of doing right here so it Adds here in right spot
if($mp3 != ""){ $F = $F."<a href='$mp3'>$lang_t202</a>"; }
if($mp3 == ""){$F= $F.$lang_t202;}

//finish adding to the $F string.
$F = $F."
[/color]
</td>
</tr>

<tr>
<td width='30%' width='30%' class='xtr'><img src='$folder/icons/table.gif' border='0' alt='$lang_t45' title='$lang_t45'> $lang_t45 :</td>
<td width='70%' class='xtd'>$catnamef</td>
</tr>
<tr>
<td width='30%' width='30%' class='xtr'><img src='$folder/icons/table.gif' border='0' alt='$lang_t2' title='$lang_t2'> $lang_t2 :</td>
<td width='70%' class='xtd'>$vis</td>
</tr>

</table>
</center>
</div>";

You should really minimize that code

 

<?php
$link = ($mp3 == "") ? $lang_t202 : '<a href="'.$mp3.'">'.$lang_t202.'</a>';

$F = "<div align='center'>
<center>
BLAH BLAH ALL YOUR OTHER HTML HERE
".$link."
REST OF YOUR HTML 
</center></div>";

?>

You should really minimize that code

 

<?php
$link = ($mp3 == "") ? $lang_t202 : '<a href="'.$mp3.'">'.$lang_t202.'</a>';

$F = "<div align='center'>
<center>
BLAH BLAH ALL YOUR OTHER HTML HERE
".$link."
REST OF YOUR HTML 
</center></div>";

?>

 

this is a good idea

thank you all for the help

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.