views:

181

answers:

1

Hello, I am trying to place items dynamically from a mysql database into a shopping cart(jcart). I have a page with 3 divs and all contain a form for the shopping cart(form code below). I am grabbing info from the database and placing it in the form.

The first div is getting the info correctly, but the second div displays the exact same thing and same as the third div(I guess from the php loop). I want each form to populate with the corresponding id from the database, so each div is different. In this case I have three websites 1.Leftlane News 2. MotorAuthority 3. Autoblog in the database. then I have separate databases for each site with the same name, in these db's is the information that populates the shopping cart form for each site.

So, the problem is that I can't get the corresponding div info to display. Is there anyway to grab the info from an id or something and display 1.leftlane News ->leftlane news cart info 2. Motorauthority -> Motorauthority cart info 3. Autoblog -> Autoblog cart info.

here is the the main php file that puts everything together:

<?php

function outputListingsTable()
{
    include("property.php");

    $mysql = new mysqli('localhost', 'root', 'root', 'ajax_demo') or die('you\'re dead');
    $result = $mysql->query("SELECT * FROM explore") or die($mysql->error);

if($result) 
{
        echo "<div id=\"MyContentArea\"> \n";
                                while($row = $result->fetch_object()) 
                                {
                                        $id = $row->id;
        global $siteName;
                                        $siteName = $row->site_name;
        global $siteDescription;
                                        $siteDescription = $row->site_description;
        global $siteURL;
                                        $siteURL = $row->site_url;
        global $sitePrice;
                                        $sitePrice = $row->site_price;

                                        echo "<div id=\"main-info-" .$id. "\" class=\"maini\"> \n";
                                        echo " " . $siteName . " \n";
                                        echo " " . $siteURL . " \n";
                                        echo " <a id=\"link-" . $id . "\" class=\"more-info-link\" href=\"#\">More info</a> \n";      
                                        echo "</div> \n";

         echo "<div id=\"more-info-" .$id. "\" class=\"mi\"> \n";
           echo "    <span class=\"description\">" . $siteDescription . "</span> \n";
         echo "<div id=\"buy-info-" .$id. "\" class=\"mib\"> \n";
           echo "    <span class=\"buy\">This is where you can purchase available property.</span> \n";
         echo " </div> \n";

         echo " <a href=\"http://localhost:8888/mainsite2/detail.php?id=$id\"&gt;More Details</a>";

         echo "<div id=\"buy-info-" .$id. "\" class=\"mib\"> \n";



            echo" <form method=\"post\" action=\"\" class=\"jcart\">";
            echo"  <fieldset>";
            echo"   <input type=\"hidden\" name=\"my-item-id\" value=\"" .$idp. "\" />";
            echo"   <input type=\"hidden\" name=\"my-item-name\" value=\"" .$adType. "\" />";
            echo"   <input type=\"hidden\" name=\"my-item-price\" value=\"" .$adPrice. "\" />";

            echo"   <ul>";
            echo"    <li><strong>" .$adType. "</strong></li>";

            echo"    <li>Price: $" .$adPrice. "</li>";
            echo"    <li>";
            echo"     <label>Qty: <input type=\"text\" name=\"my-item-qty\" value=\"1\" size=\"3\" /></label>";
            echo"    </li>";
            echo"   </ul>";

            echo"   <input type=\"submit\" name=\"my-add-button\" value=\"add to cart\" class=\"button\" />";
            echo"  </fieldset>";      
            echo" </form>";




         echo " </div> \n";

         echo " </div> \n";
                                }
echo "</div> \n";     

    }

}

?>

And here is the property.php page that I am including in the above for leftlane:

<?php
    $mysql = new mysqli('localhost', 'root', 'root', 'leftlane_news') or die('you\'re dead');
    $result = $mysql->query("SELECT * FROM property") or die($mysql->error);

if($result) 
{
                                while($row = $result->fetch_object()) 
                                {
                                        $idp = $row->property_id;       
                                        $adType = $row->ad_type;        
                                        $adAvail = $row->ad_avail;     
                                        $adSold = $row->ad_sold;
                                        $adPrice = $row->ad_price;  
                                }
    }
?>

Any help would be great. Thank you.

A: 

It looks like you are building all 3 divs inside the same loop - which means they will all be given the exact same data. I can't quite get my head around the specifics you have, but you will probably want a loop that more closely resembles:

<?php
while($row = $result->fetchObject())
{
    echo '<div id="' . $row->data . '" >';
    //more stuff
    echo '</div>';
}

That will create a DIV for every row in the result set.

Peter Spain