Variable with href

Asked

Viewed 1,006 times

-1

I need the cellular variable Celular: $lnbusca[celular] to click and appear on the sample dial screen <a href="tel:55555"> chamar 5555</a> for the time the user click appears the number on the cell phone dial screen, then how do I put the hrefwithin the $lnbusca[], how do I do ?

<?php
include "config.php";
if(isset($_POST['acao']) && $_POST['acao'] == 'bsc'){
	$palavra = strip_tags($_POST['pesquisa']);
	
	$banco = mysql_query("SELECT * FROM agenda WHERE nome LIKE '%$palavra%'");
	
	if(mysql_num_rows($banco) == 0){
		echo "Nenhum dado foi encontrado!";
	}else{
		while($lnbusca = mysql_fetch_array($banco)){
                            
                            //COMECO
                            
                            
                            echo "<table width=1000 align=center>";

echo "<td bgcolor=#ebf3ff><b></b>";
echo "</td>";

echo "<tr>";
echo "<td width=25>";

echo "<font size=1>Codigo: $lnbusca[id_contato]</font>";

echo "</td>";


    echo "<td width=450 bgcolor=#ebf3ff>";
	
    
//echo "<b><a href='agenda-exibir.php?id_contato={$dados['codigo']}'><font color=black size=elvetica>$dados[nome]</font></a><br />";
echo "<b><font color=black size=elvetica>Categoria: $lnbusca[categoria] | "
            . "Cidade: $lnbusca[cidade] | "
            . "Nome: $lnbusca[nome] | "
            . "Celular: $lnbusca[celular] | "
            . "Celular2: $lnbusca[celular2] | "
            . "Telefone: $lnbusca[telefone]  </font></a><br />";

echo "</tr>";
echo "</td>";
   

echo "<td bgcolor=#f8f8fA>";
echo "</td>";
 echo "</tr>";
	   echo "</td>";

echo "</table>";                                //FIMM
		}
}}
    
  
?>

  • Try to be clearer on the question, put some snippet of code you’ve already done. It’s hard to help without the details

  • 1

    it’s to do so <a href="tel:<?php echo $lnbusca['celular']; ?>"> Chamar <?php echo $lnbusca['celular']; ?> </a>

  • I posted the code take a look the problem this here on adding href . " Cellular2: $lnbusca[cellular2] | " gives a look daniel

1 answer

3


First of all, we have to fix the syntax errors.

Arrays allow numeric or string indices. In your case you have not specified either one or the other.

$lnbusca[celular]   // celular não é uma string, tampouco número
$lnbusca['celular'] // Assim está correto como string
$lnbusca[$celular]  // Assim está correto se o índice vier de uma variável

Another problem is the interpolation of String. PHP allows you to put variables inside a string if you use double quotes. However, if you need to specify something more complex, you need to delimit with { }.

In your case, applying the two things mentioned, the code "correct" would be this:

echo "<b><font color=black size=elvetica>Categoria: {$lnbusca['categoria']} | "
    ."Cidade: {$lnbusca['cidade']} | "
    ."Nome: {$lnbusca['nome']} | "
    ."Celular: {$lnbusca['celular']} | "
    ."Celular2: {$lnbusca['celular2']} | "
    ."Telefone: {$lnbusca['telefone']}  </font></a><br />";

See working on IDEONE.


Adding the href

Understood the previous step, just add what you want in strings.

Instead of

"Celular: {$lnbusca['celular']} | "

could do this (note the backslash for the quotation marks href):

"Celular: <a href=\"tel:{$lnbusca['celular']}\"> Chamar {$lnbusca['celular']}</a> | "

Or this, to avoid interpolation and confusion with quotation marks:

'Celular: <a href="tel:'.$lnbusca['celular'].'"> Chamar '.$lnbusca['celular'].'</a> | '


Removing the interpolation

The interpolation is comfortable to put small details and variables in a string, facilitating readability when you want to avoid concatenation. In your case it doesn’t help much, because there is concatenation anyway. Thus, it would be possible to simplify the code using concatenation at all:

echo '<b><font color=black size=elvetica>'
    .   'Categoria: '.$lnbusca['categoria']
    .' | Cidade: '   .$lnbusca['cidade']
    .' | Nome: '     .$lnbusca['nome']
    .' | Celular: '  .$lnbusca['celular']
    .' | Celular2: ' .$lnbusca['celular2']
    .' | Telefone: ' .$lnbusca['telefone']
    .' </font></a><br />';

See working on IDEONE.


I didn’t get into the merit of your HTML being a little weird, because it evades the question, but I suggest you review it anyway

  • 1

    Master I perfect your response very grateful for having responded big hug to you thank you so much..

Browser other questions tagged

You are not signed in. Login or sign up in order to post.