Project

General

Profile

Bug #463

how to send basic php array to mysql select

Added by Richard Flaherty over 1 year ago. Updated about 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
-
Target version:
-
Start date:
06/21/2021
Due date:
% Done:

0%

Estimated time:

Description

I am trying to fetch a column with PHP and MySQL.

When I search about - "How to array in MySQL IN - it gets either implode or join function.

However, both giving NULL

$dsn = 'mysql:dbname=table34;host=localhost';
$conn = new PDO;

$sql = "SELECT DISTINCT FROM `node_detail`";
$parentdistinct_topicsid = $conn->query($sql)->fetchAll(PDO::FETCH_COLUMN);

$related_topics = $conn->query("SELECT `field_related_topics_target_id` FROM `taxonomy_term__field_related_topics` WHERE `entity_id` = " .
$parentdistinct_topicsid0 ." AND `field_related_topics_target_id` > 22")->fetchAll(PDO::FETCH_COLUMN);

$topicsid_array = $related_topics;
$topicsid_array[] = $parentdistinct_topicsid[0];
$ids = implode("','", $topicsid_array);
$related_articles = $conn->query("SELECT `bootstrapcard` FROM `node_detail` WHERE `parent_id` IN('" .$ids. "')")->fetchAll(PDO::FETCH_COLUMN);

$print_r($related_topics);
This is a simple SELECT stuck in unknown IN with weird implode.

Although implode does not work in my case, I do not understand the purpose of implode. What I know, implode joins the strings, and how can it work?

#1

Updated by Richard Flaherty over 1 year ago

Thanks to this article I can learn more. Expand my knowledge and abilities. Actually the article is very real.
mypascoconnect

#2

Updated by Kentaro Hayashi about 1 year ago

  • Status changed from New to Closed

Also available in: Atom PDF