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
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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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