0

My table code. it's included the popover button, that I want to show other detail than Name and Country.

  while ($data = mysql_fetch_array($result)) 
           {
           echo "<tr>";
           $Name = $data['Name'];
           $Address = $data['Address']; 
           $Tel = $data['Tel'];
           $Email = $data['Email'];
           $Country = $data['Country'];
           $ManufacturerKey = $data['ManufacturerKey'];
           echo "<td>{$Name}</td><td>{$Country}</td>";
           echo '<td><a href="#" id="detail" class="btn btn-danger" rel="popover" data-content="Test" data-original-title="detail">detail</a></td>';
           echo "</tr>"; 
           }
           echo "</table></center>";
           }

and Javascript:

<script>  
    $(function ()  
    { $("#detail").popover({placement:'left'});  
    });  
</script>

my problem is it's confuse about the id.In the each table row it has same id like "detail".How can I fix that ?? Thanks for all answer.Tell me if you want more code thanks so much.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
DrNutsu
  • 475
  • 2
  • 10
  • 21
  • 3
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://stackoverflow.com/a/14110189/1723893). – NullPoiиteя Jan 05 '13 at 10:39
  • wait , you want to change the id=detail right? – soft genic Jan 05 '13 at 10:59
  • What has Twitter Bootstrap to do with that? And yes, use PDO instead, it's easier to write code for, especially if you're new to PHP. Will save you some time then. – hakre Jan 05 '13 at 11:05
  • @hakre he is using popover of twitter bootstrap – soft genic Jan 05 '13 at 11:07
  • @soft genic I want to specify id in each row of table because i want to show other detail in each row of the table. – DrNutsu Jan 05 '13 at 11:12
  • Well the actual question has nothing to do with bootstrap in specific. Generate an ID per each row, for example `sprintf('row-%d', $data['Id']);` if the table has an Id column, otherwise use a counter. This is really trivial material I'd say. Question should be: What have you tried? Seeing that the ID is duplicated sounds like a good start to find the solution, isn't it? – hakre Jan 05 '13 at 11:14
  • Well by assigning different ids your popover will not gonna work cause you have to make the javasript function for all ids to popover. But i work with popover too you dont need to change id just populate al the elements with id="detail" and you'll see each popover contains its respective detail. Kindly let me know if your issue being resolved withthis – soft genic Jan 05 '13 at 11:25
  • Sorry for my pointless question.Thanks for your answer.:)) – DrNutsu Jan 05 '13 at 13:49

1 Answers1

0

Every tag must have an unique id, this html isn't correct.

You have to use a class selector.

     //add detail in your class
echo '<td><a href="#" id="detail" class="btn btn-danger detail" rel="popover" data-content="Test" data-original-title="detail">detail</a></td>';

Edit : Don't forget to change the id. For example, you can do id="detail'.$data['id'].'" if you have an id.

In your JS (jQuery as he uses bootstrap):

//use class selector instead of id selector
$(function ()  {
        $(".detail").popover({placement:'left'});  
    }); 
Pierrickouw
  • 4,644
  • 1
  • 30
  • 29