Jump to content

Help using implode() after query.


coupe-r

Recommended Posts

Hi All,

 

After a query runs, I want to grab the ID's and separate them with a comma because they will be used in the next query.  What I currently have does not work, although the query is correct.

 

$sql	= "SELECT a.app_id FROM applications a LEFT JOIN tenants t ON a.app_id = t.app_id WHERE t.tenant_id IN (".implode(",", $checked).")";

$result = mysqli_query($connect, $sql);

$checked1 = array();

while($row = mysqli_fetch_array($result))
{
foreach($row['app_id'] as $value1)	{$checked1[] = $value1;}
}

echo implode(",", $checked1);

Link to comment
https://forums.phpfreaks.com/topic/251852-help-using-implode-after-query/
Share on other sites

Thanks for the reply.

 

I'm storing the values as an array, but it should echo the entire array like 1,3,4,5,6,7, or which ever ID's are selected, without using a node.  I want the entire array.

 

Above this code, it works just fine.  I'm using similar code but putting checkbox IDs in the array

 

foreach($_POST['checkbox'] as $value)	{$checked[] = $value;}

 

If I echo that implode, I get (1,3,4,5, etc) which ever boxes I check.

 

Now that I am grabbing the IDs from a $row['app_id'], I think there is an issue with the values getting put into a proper array?

There's no need for your foreach() loop inside your while loop.  In fact I would expect it to not work as $row['app_id'] wouldn't be an array.

while($row = mysqli_fetch_array($result))
{
$checked1[] = $row['app_id'];
}

 

 

That said, can you not just use a JOIN in your first sql query to achieve the desired results?  Seems like it should be possible if your just getting ID's and re-querying.

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.