Take the 2-minute tour ×

I have a bunch of items I list on a page and each of these items have an id associated with them on there link.

For instance, when you hover over the items you get a url of items.php?id=5.

I have my while loop which produces all of the items on this page including the links, how do I carryover that ID into my other code?

Here is my code that brings up all the items.

while ($results = mysqli_fetch_assoc($query)) {
            <img style='width: 200px; height: 200px' src='images/inventory/" . $results['Image'] . "'/>" . 
            "<div class='infoContainer'>" .
            "<a class='productLink' href='selectItems.php?status=active&id=" . $results['ID'] . "'>" . $results['ProductName'] . "</a>" . 
            "<br />" . 
            "<i>Currently Available </i>" . 
            "<i class='quantity'>" . $results['Quantity'] . "</i>" . 
            "</div>" .

Now I simply want to put each items attributes into a dialog box. How do I carryover an id from above to get the right data back?

    <div id="dialog" title="A title">

            $sql = "SELECT * FROM `my_table` WHERE `id` = ";
            $query = mysqli_query($sql) or die(mysqli_error());

            $results = mysqli_fetch_assoc($query);


share|improve this question
Better use ajax to get it done. –  believe me Mar 18 '13 at 14:05
I thought about going that route. Just wanted to see if there was something I was missing maybe. –  wowzuzz Mar 18 '13 at 14:05
While your in the loop create a hidden dialog div with the contents, so when you do what needs to be done reference the id of that div –  Waygood Mar 18 '13 at 14:05
just use JQuery-Ajax or Simply Ajax to load data from another .php and then bind mouse over the links to show a div whose html() will be the data returned by Ajax –  7-isnotbad Mar 18 '13 at 14:09
You should simply construct a string, append the data to it, and load it into dialog. –  Jonast92 Mar 18 '13 at 14:15
add comment

2 Answers

up vote 1 down vote accepted

You should call a javascript function and send id in it.. donot forget to include the jquery files.. this method loads the data using AJAX..

function getData(idtosend){
    $.post('getdata.php', id: idtosend, function (response){

Here is the code of getdata.php file:

//Connect mysql here
$id = mysql_real_escape_string($_POST['id']);
$sql = "SELECT * FROM `my_table` WHERE `id` = $id";
$results = mysqli_fetch_assoc($query);
share|improve this answer
Thanks for helping me piece it together. –  wowzuzz Mar 18 '13 at 14:54
add comment

in PHP you cat use ob_start() - this is output buffer for echo operations.

after save result in variable or array and put it into needful block on page

share|improve this answer
add comment

Your Answer


