0

i have one problem in passing the value in website and i can't pass it through query String.my small piece of php code is.:-

 <div class="menu">
        <div class="sub_menu_header">About us</div>
        <?php 
            $query1="SELECT id,title FROM aboutus_tbl";
            $resulto=mysql_query($query1);
            while ($row = mysql_fetch_array($resulto)) {
        ?>
        <a href="about" class="menuid" id="<?php echo $row['id'];?>"><div class="<?php echo $row['title'];?>" id="sub_menu"><?php echo $row['title'];?>
        </div></a>
        <?php
        }
        ?>
    </div>

then jquery is.:-

<script>
    $(".menuid").click(function() {
        date_time = $(this).attr('id');
        console.log(data);
        $.ajax({
            type: 'POST',
            url: 'about',
            data: {"aboutus_id" : date_time},
            success: function(data){
                alert( data );
            }
        });
    });
    </script>

and my full code is.:-

<?php ob_start(); include('web/header.phtml');?>
<!--main-->
<div class="main_btm">
<div class="wrap">
<div class="main">
    <div class="new_head"><font size="5" color="#FC2B5F">
    <script>
    $(".menuid").click(function() {
        date_time = $(this).attr('id');
        console.log(data);
        $.ajax({
            type: 'POST',
            url: 'about',
            data: {"aboutus_id" : date_time},
            success: function(data){
                alert( data );
            }
        });
    });
    </script>
    <?php
    if (isset($_POST['aboutus_id'])) {
        $id=$_POST['aboutus_id'];
        echo $id;
    }
    else{
        $id=1;
    }
    $que="SELECT title FROM aboutus_tbl WHERE id='".$id."'";
    $re=mysql_query($que);
    $r=mysql_fetch_array($re);
    echo $r[0];
    ?>
    </font></div>
    <div class="menu">
        <div class="sub_menu_header">About us</div>
        <?php 
            $query1="SELECT id,title FROM aboutus_tbl";
            $resulto=mysql_query($query1);
            while ($row = mysql_fetch_array($resulto)) {
        ?>
        <a href="about" class="menuid" id="<?php echo $row['id'];?>"><div class="<?php echo $row['title'];?>" id="sub_menu"><?php echo $row['title'];?>
        </div></a>
        <?php
        }
        ?>
    </div>
    <div class="contant">
    <div class="con_details">
    <?php
        $query="SELECT * FROM aboutus_tbl WHERE id='".$id."'";
        $res=mysql_query($query);
        $result=mysql_fetch_array($res);
        $d1_per=explode("  ", $result['desc1']);
        $d1_lenth=sizeof($d1_per);
        $d2_per=explode("  ", $result['desc2']);
        $d2_lenth=sizeof($d2_per);
        $d3_per=explode("  ", $result['desc3']);
        $d3_lenth=sizeof($d3_per);
        if ($result['sub_title1']) {
    ?>
    <legend><font size="5"><?php echo $result['sub_title1'];?></font></legend>
    <?php
    }
    if ($result['desc1']) {
    for ($i=0; $i < $d1_lenth; $i++) { 
        echo "<p>".$d1_per[$i]."</p>";
    }
    }
    if ($result['sub_title2']) {
    ?>
    <legend><font size="5"><?php echo $result['sub_title2'];?></font></legend>
    <?php
    }
    if ($result['desc2']) {
    for ($i=0; $i < $d2_lenth; $i++) { 
        echo "<p>".$d2_per[$i]."</p>";
    }
    }
    if ($result['sub_title3']) {
    ?>
    <legend><font size="5"><?php echo $result['sub_title3'];?></font></legend>
    <?php
    }
    if ($result['desc3']) {
    for ($i=0; $i < $d3_lenth; $i++) { 
        echo "<p>".$d3_per[$i]."</p>";
    }
    }
    ?>
    </div>
    </div>
</div>
</div>
</div>
<script type="text/javascript">
window.onload = function() {
    $(document).ready(function() {
        $('.<?php echo $result['title']?>').addClass('sub_menu_selected');
    });
}
</script>
<?php include('web/footer.phtml'); ob_flush();?>

in above code i display menu in div tag and tage out side so i can click it.my problem is when i click on menu it must take id of menuid class but it's not working and $_POST['aboutus_id'] not getting any value.

5
  • have you put this code where?
    – Amit Bera
    Aug 27, 2015 at 6:42
  • i have create new link in magento in homepage Aug 27, 2015 at 6:45
  • You have do core php code in magento.it not good.. Also You need to put full url like YourmagentUrl/about.. not about..
    – Amit Bera
    Aug 27, 2015 at 6:47
  • i give answer in brief i have create own module Aug 27, 2015 at 6:48
  • Sorry but this is anything but Magento... Some wrong stuff: use of ob_start ob flush, use of include in templates, use of queries in templates and logic that should be inside a block, model and/or helper (anywhere but templates). Also you have javascript code that can be moved to a js file... This is not how things should be done in Magento.
    – Emi
    Aug 27, 2015 at 7:01

1 Answer 1

1
$(".menuid").click(function() {
    date_time = $(this).attr('id');
    console.log(data);
    $.ajax({
        type: 'POST',
        url: 'about',
        data: {"aboutus_id" : date_time},
        success: function(data){
            alert( data );
        }
    });
});

this should be written inside jQuery(document).ready().since it is
above the element .menuid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.