Variable with href

-1

I need the cell variable Celular: $lnbusca[celular] from to click and appear on the dial screen exampleo <a href="tel:55555"> chamar 5555</a> for the time the user clicks the number on the cellphone's dial screen, so how do I put href within $ lnbusca[] , how do I do it?

<?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
		}
}}
    
  
?>
    
asked by anonymous 19.09.2016 / 04:57

1 answer

3

First of all, we have to fix syntax errors.

Arrays allow numeric or string indices. In your case, you did not specify either.

$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 String interpolation. PHP allows you to place variables within 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 at IDEONE .


Adding% with%

Understanding the previous step, just add whatever you want in strings .

Instead of

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

could do this (note the backslash for 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 interpolation

Interpolation is convenient for putting small details and variables in string , making it easy to read when concatenation is avoided. In your case it does not help much, because there is concatenation in any way. So it would be possible to simplify the code by 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 at IDEONE .


I did not get into the merit of your HTML to be a bit strange, because it fits the question, but I suggest revising anyway     

20.09.2016 / 11:26