Shrewd Shrewd - 1 year ago 107
PHP Question

Tooltip with MySQL query

I have problem with tooltip.

I have some rows in table

echo '<td><center>'.$dana['material'].'</td>';
echo '<td><center>'.$zmiennacal.'</td>';

and now its my question, can I do a dynamic tooltip with MySQL query like this

$connect = mysqli_connect(CONNECTION QUERY);
$zapytanie = "SELECT iloscsurmaterialu, Produkt FROM receptaprodukt WHERE surowiec='$mat'"
or die(mysql_error());
$result = mysqli_query($connect, $zapytanie);

while($row = mysqli_fetch_assoc($result))
echo "'.$row['iloscsurmaterialu'].' - '.$row['Produkt'].'";

and take this result in tooltip, in second row in my table where is

I'm trying some scripts but no one works :( (i know that it must be in ajax but I don't know that structure as PHP :P

Thank you in advance, please HELP

Answer Source

To use ajax

//ajax php file
$mat = $_POST['mat'];
$connect = mysqli_connect(CONNECTION QUERRY);
$zapytanie = "SELECT iloscsurmaterialu, Produkt FROM receptaprodukt WHERE surowiec='$mat'";
$result = mysqli_query($connect, $zapytanie);
$title = '';
    echo json_encode(array('success' => false));
while($row = mysqli_fetch_assoc($result))
    $title .= "'".$row['iloscsurmaterialu'].' - '.$row['Produkt']."'";
echo json_encode(array(
    'success' => true,
    'title' => $title

//jQuery post:
$.post( "ajax/get_title.php", {mat: 'somemat'}, function( data ) {
    if(data && data.success){
        var title = data.title;
        $('td').attr('title', title); //note that td is not specific, it will add title to all the tds. You need to select the correct one.
  $( ".result" ).html( data );
}, "json");