2014-12-13 11:34 浏览 27


I have a page (menu.php) that retrieves and displays data from a database including name, image, price I want to add a link when i click on the image take me to another page (single Product.php) , so i have only one page and i want its content depending on the image i have clicked

    <div class="row">
    <div class="col-md-9">
    <div class="products-heading">
        <h2>Our Salad</h2>
    </div>  <!-- End of /.Products-heading -->
    <div class="product-grid">
    <div class="row">

                $rc=mysql_query("select * from menu where Item_Catagory = 'Salad'") or die(mysql_error());

                <!--To send item info to single-product page -->

                <div class="col-md-4">
                <div class="products">

                        <a href="single-product.php" >
                            <img src="images/<?php echo $MenuItem['Item_Image']; ?>"  alt="" />
                        <a href="single-product.php">
                            <h4> <?php echo $MenuItem['Item_Name']?> </h4>
                        <p class="price"> <?php echo $MenuItem['Item_Price']?></p>
                        <div class="row lead">
                            <center><div id="stars" class="starrr"></div></center>
                        <a class="view-link shutter" href="#">
                            <i class="fa fa-plus-circle"></i>Add To Cart</a>
                    </div>  <!-- End of /.products -->
                </div> <!-- End Of /.Col-md-4 -->    

        <?php }


    </div>  <!-- End of /.row -->

this is a part of the first page I want to use get method to send the data to the another page, but i do not what is the appropriate method should i use javascript?if yes how?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答 默认 最新

  • 已采纳
    douyu7210 douyu7210 2014-12-13 11:41

    Use id's to send data:

    <a class="view-link shutter" href="Product.php?id="<?= $MenuItem['id'];?>">

    In the other page $dataID = $_GET[id]; than query your DB where id=$dataID

    点赞 评论 复制链接分享
  • dqnhfbc3738 dqnhfbc3738 2014-12-13 12:27

    change <a href="single-product.php">

    to <a href="single-product.php?name=<?php echo $MenuItem['Item_Name']?>">

    An example redirect would now be "single-product.php?name=food"

    In single-product.php you could now retrieve the itemname with $_GET (superglobal). In your script you would get it by $item = $_GET['name'], $item is now equal to 'food'.

    To get information about this particular product "food", you query the database in single-product.php like so: "select * from menu where Item_Name = '".$item."'". Now append the result into your html.

    To do this by ajax you would need to handle all the anchor tags, assuming you are using jQuery the following will do:

            url: this.href,
            method: 'GET',
            success: function(response){
                //here you can append the response to your html
        return false; //prevent browser from redirecting
    点赞 评论 复制链接分享