Jump to content

aldo151

New Members
  • Posts

    5
  • Joined

  • Last visited

Posts posted by aldo151

  1. Actually no, this is just adding fields to my query...I already have $sql = "SELECT * FROM orders"; outside of my function if you take a look at the entire code. What I am trying to do is add additional columns to $fields = array('id','type'); .... for example: $fields = array('id','type','etc'); and then have it pass through my function wpquery_select , which its already doing, and then have it add $rows['?'] to display or however I specifiy in my loop, without having me to manually add the columns to echo in the while loop.

    while($row = $results->fetch_assoc()){

    echo $row['id'] . "then" . $row['type']; // <--- I don't want to manually specifiy here the column to display...would like it to be added automatically if I have added columns to my $fields = array('id','type','etc');

    }

  2. Thank you :) but I don't think I'm being clear. Yes I of course I know that, but I would like to specify the colums in my array .... 

    $fields = array('id','type');

    then pass it via my function wpquery_select  which I am doing and have it dynamically return the columns from the database in the while loop.

    I don't want to have it static in the while look like... $row['id].$row[type] and so on. Basically would like to have it, where if I add more column names in the $fields = array('id','type'); its automatically taken care of within the fuction.

  3.  

    Hi there, wanted to see how I would have the columns I specified in 

    $fields = array('id','type');

     

    then be generated dynamically in the while loop and any other field I state in

    $fields = array('id','type');

    then its added to the while loop in the below
     

    include('db.php');
    
    class SelectData{
    
    
    public function wpquery_select($conn,$sql,$fields){
    
    $results = $conn->query($sql);
    
    if($results->num_rows > 0){
    
    	while($row = $results->fetch_assoc()){
    		
    		// How would you process the array $fields which holds all the rows specified and dynamically create echo $row['id'], $row['id'] and so on?
    		
    	}
    	
      }
    
    $conn->close();
    
     }
    
    	
    }
    
    
    
    $select = new SelectData();
    
    $sql = "SELECT * FROM orders";
    
    
    $fields = array('id','type');
    
    
    $select->wpquery_select($conn,$sql,$fields);

    Thank you

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.