Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 163419
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:33:51+00:00 2026-05-11T11:33:51+00:00

$genre = array( ‘Action’, ‘Adventure’, ‘Fantasy’ ); $selectGenre_sql = ‘SELECT genreID FROM genres WHERE

  • 0
$genre = array(     'Action',     'Adventure',     'Fantasy' ); $selectGenre_sql = 'SELECT genreID FROM genres WHERE dbGenre = ?';  if ($stmt->prepare($selectGenre_sql)) {     // bind the query parameters     $stmt->bind_param('s', $genre);     // bind the results to variables     $stmt->bind_result($genres);     // execute the query     $stmt->execute();     $array1 = array();     while ($stmt->fetch()) {         $array1[] = $genres;     } } 

The code above gets the value from genreID when dbGenre is equal to $genre. And then store the results in an array. But it’s not working because $genre is an array, so I need to loop through it to get a different value from genreID each time.

The ‘genres’ table contains two columns: genreID (INT) and dbGenre (VARCHAR)

I just need each genreID (that is a number)… Let’s say when dbGenre is equal to Action, then store the genreID in an array1, and then loop the $genre array to get the genreID for the next value and store it again in array1.

How can I fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:33:52+00:00Added an answer on May 11, 2026 at 11:33 am

    You can’t bind an array to an SQL parameter. You can use a parameter in SQL in place of a single literal value. Not a list of values, or an expression, or a column name or table name.

    To solve the task in your case, you can use either of two solutions:

    First solution: loop over $genre array, bind each value one at a time and execute the SQL query for each value.

    $stmt->prepare($selectGenre_sql); $genre = array(); foreach ($gengre as $genreID) {     $stmt->bind_param('s', $genreID);     $stmt->execute();     $stmt->bind_result($genres);     while ($stmt->fetch()) {         $genre[] = $genres;     } } 

    Second solution: execute the query once, with multiple parameters, one for each value in the array. This requires some tricky code to build a variable number of ? placeholders in the SQL query, separated by commas.

    $selectGenre_sql = 'SELECT genreID FROM genres WHERE dbGenre IN ('  . join(',', array_fill(0, count($genre), '?')) . ')'; 

    Also you need to get tricky calling bind_param() with a variable number of arguments based on the elements in your $genre array:

    $stmt->prepare($selectGenre_sql); $temp = array(); foreach ($genre as $key => $value) {     $temp[] = &$genre[$key]; }  array_unshift($genre, str_repeat('i', count($genre))); call_user_func_array(array($stmt, 'bind_param'), $genre);  $stmt->execute();  $stmt->bind_result($genres);  $array1 = array(); while ($stmt->fetch()) {     $array1[] = $genres; } 

    You might want to consider using PDO_MYSQL because it’s easier to bind parameters from an array. The MySQLi interface is pretty awkward for this case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 141k
  • Answers 142k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Modal Dialogs A modal dialog is a dialog that blocks… May 12, 2026 at 8:11 am
  • Editorial Team
    Editorial Team added an answer You are calling this operation exactly every 5000 milliseconds. So… May 12, 2026 at 8:11 am
  • Editorial Team
    Editorial Team added an answer // checkbox click event handler $('input:checkbox.liChk').live('click', function () { //… May 12, 2026 at 8:11 am

Related Questions

$genre = array( 'Action', 'Adventure', 'Fantasy' ); $selectGenre_sql = 'SELECT genreID FROM genres WHERE
I need to retrieve data from several rows and then insert the results into

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.