Jump to content

How to make an array from a variable


bruckerrlb

Recommended Posts

Hey Guys,

 

I've been checking the php manual for how to do this without success, so I thought I"d post here. I'm trying to put mysql data into an array, which would be the following:

<?php 
$sql_license = "SELECT products.product_id as product_id, products.product_name as product_name , license.license_numbers as l_number, license.company_id as l_company_id
					FROM products
					LEFT JOIN license ON products.product_id = license.product_id
					WHERE license.company_id = '$id'";
$result1 = mysql_query($sql_license); 
while($thequery = mysql_fetch_array($result1)) {

$prod = $thequery['product_id'];
$b = array($prod);

echo "<h1>$prod</h1>";
// This spits out 3 numbers, which is exactly what I'm looking for, but when I put it into a foreach statement, I get Invalid argument supplied for foreach() 

//So, then I tried to use this variable
$b = array($prod);
//but it just puts out the text array three times

?>

 

I'm trying to get this array into a foreach statement to no avail, just can't figure out arrays here, how can I turn the data from $prod into an array?

 

The overall foreach statement looks like this

  <?php  foreach($b as $key => $value)
{
  ///Get All Products that don't have licenses    
   		$sql_license = "SELECT * FROM products";
      		$result_license = mysql_query($sql_license);        
      			while($row_license = mysql_fetch_array($result_license))
			{ 
  					$prod_name = $row_license['product_name'];
				$prod_id = $row_license['product_id'];
  ?>
   <tr>
   		<?php	if($product_id != $prod_id) { ?>

         <td class="row1"><?php echo $prod_name; ?></td><td class="row1"><input type="text" name="product<?php echo $prod_id; ?>" /></td>
         
  </tr><?php } }
  
} }

Link to comment
https://forums.phpfreaks.com/topic/197255-how-to-make-an-array-from-a-variable/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.