We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 12294
    • 30 Posts
    Hi,

    I’m sorry to be asking all these questions!

    Currently I am passing the following variable from my chunk to my snippet: [!tax? &param1=`[+price_net+]`]

    Then within my main snippet I am trying to convert that variable into a float, and search within my database:

    <?php
    echo $param1;

    $converted = (float)$param1;
    echo $converted;

    if($converted === ’123.00’) echo ’Float’; /*This isn’t printing out so I’m assuming its not converting properly?*/

    $sql = "SELECT * FROM catalogue_items WHERE price_net = ’".$converted."’" ;
    $result=mysql_query($sql);

    while ($row = mysql_fetch_array($result))
    {
    $name = $row[’name’];
    $price_net = $row[’price_net’];
    }

    echo ’<FORM METHOD=POST>’;
    echo ’Name
    ’;
    echo ’<input type="text" name="name" value="’ .$name. ’ ">
    ’;
    echo ’Price Net
    ’;
    echo ’<input type="text" name="price_net" value="’.$price_net.’" >
    ’;
    echo ’<input type=submit name="submit" value="Update"></p>’;
    echo ’</FORM>’;
    ?>

    Hope that was somewhat clear!

    Any help would be appreciated - I’m tearing my hair out now!

    Hollie
      • 4172
      • 5,888 Posts
      why do you want to convert it?
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 12294
        • 30 Posts
        I want to convert it because when I don’t it still doesn’t pull anything out of the database, so I’m assumng that there incompatable types?

        I might be wrong though!

          • 4172
          • 5,888 Posts
          normally the type doesn’t matter.

          What do you want to do with that script?
          I see you try to get items which have a given price.
          Then you are looping thrue all items and you store them again and again into the same var.

          then you have a form where you echo some fields from the last item??

          Are you sure this is what you want?

          btw. you can use modx-db-api-functions in evo

          see: http://wiki.modxcms.com/index.php/API:DBAPI

          <?php
          $result=$modx->db->select('*','catalogue_items','price_net="'.$param1.'"');
          
           while ($row = $modx->db->getRow($result))
           {
              print_r($row);
           }


          or

           
          <?php
          $result=$modx->db->select('*','catalogue_items','price_net="'.$param1.'"');
           $rows=$modx->db->makeArray($result);
           print_r($rows); 
          

            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 12294
            • 30 Posts
            I can see one of my errors now was going for something generic like the price, when searching through the database. I wondered what you meant when you said it was looping through so thanks for pointing that out! So I’ve changed that to the ID number of the item.

            The link and examples you provided have been very helpful as well, and I think I’ll be able to get it working now!

            Thanks

            Hollie grin