Php variables from sql queries

ok trying to fetch values from queries but doesn’t seem i have everything correct… page just will not load.

Am I doing this correctly? or did a completely fubar it up

$get_data = "SELECT post_id FROM gh_postmeta WHERE meta_key = '_affid_field' limit 25";
        if($result_data = $skacon->query($get_data)){
            while($finish = $result_data->fetch_array()){

                $PostId = $finish['post_id'];
                $Paid = mysqli_query($skacon,"SELECT meta_value FROM gh_postmeta WHERE meta_key = '_paypal_status' AND post_id = '".$PostId."' limit 1");

                if($Paid == 'completed') {

                $AffID = mysqli_query($skacon,"SELECT meta_value FROM gh_postmeta WHERE meta_key = '_affid_field' AND post_id = '".$PostId."' limit 1");
                $product = mysqli_query($skacon,"SELECT meta_value FROM gh_postmeta WHERE meta_key = '_transaction_id' AND post_id = '".$PostId."' limit 1");
                $sale_amount = mysqli_query($skacon,"SELECT meta_value FROM gh_postmeta WHERE meta_key = '_order_total' AND post_id = '".$PostId."' limit 1");
                $date = mysqli_query($skacon,"SELECT meta_value FROM gh_postmeta WHERE meta_key = '_paid_date' AND post_id = '".$PostId."' limit 1");

Ok nevermind figured out the problem. incase anyone needs help with this later on here is the correct way

                $PostId = $finish['post_id'];

                $get_Paid = "SELECT meta_value FROM gh_postmeta WHERE meta_key = '_paypal_status' AND post_id = '".$PostId."' limit 1";
                $result_Paid = $skacon->query($get_Paid);
                $Pre_Paid = $result_Paid->fetch_array();
                $Paid = $Pre_Paid['meta_value'];

                //if($Paid == 'completed') {

                $get_AffID = "SELECT meta_value FROM gh_postmeta WHERE meta_key = '_affid_field' AND post_id = '".$PostId."' limit 1";
                $result_AffID = $skacon->query($get_AffID);
                $Pre_AffID = $result_AffID->fetch_array();
                $AffID = $Pre_AffID['meta_value'];

                $get_product = "SELECT meta_value FROM gh_postmeta WHERE meta_key = '_transaction_id' AND post_id = '".$PostId."' limit 1";
                $result_product= $skacon->query($get_product);
                $Pre_product = $result_product->fetch_array();
                $product = $Pre_product['meta_value'];

                $get_sale_amount = "SELECT meta_value FROM gh_postmeta WHERE meta_key = '_order_total' AND post_id = '".$PostId."' limit 1";
                $result_sale_amount = $skacon->query($get_sale_amount);
                $Pre_sale_amount = $result_sale_amount->fetch_array();
                $sale_amount = $Pre_sale_amount['meta_value'];

                $get_date = "SELECT meta_value FROM gh_postmeta WHERE meta_key = '_paid_date' AND post_id = '".$PostId."' limit 1";
                $result_date = $skacon->query($get_date);
                $Pre_date = $result_date->fetch_array();
                $date= $Pre_date['meta_value'];

I think you could combine that all into one single query.

SELECT meta_value FROM gh_postmeta WHERE meta_key IN (‘_paid_date’,‘xxx’,‘yyy’) AND post_id = ‘“.$PostId.”’

Just add new fields to the IN conditions as they are needed.

Far from the correct way in many ways. I don’t have time to elaborate at the moment. I will come back to this. Perhaps someone else will elaborate in the meantime.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.