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

  • Home
  • SEARCH
  • 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 6530437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:45:18+00:00 2026-05-25T09:45:18+00:00

The code below won’t work because of this line $params=array($data); . It needs something

  • 0

The code below won’t work because of this line $params=array($data);. It needs something other than $data. Or it needs something to happen with $data prior to this line.

If the line is written as $params=array(“A”, “B”, “C”, “D”); then it works great, but my array is in the $data variable, not written out like that. If there is a way to get the array converted to being written out like that, that would work too.

The end result should show every possible combination (not permutation) of the contents of the array. Like in the example above it shows ABC, BD, etc.

$data = mysql_query('SELECT weight FROM my_table WHERE session_id = "' . session_id() . '"'); 

$params=array($data);

$combinations=getCombinations($params);
function getCombinations($array)
{
    $length=sizeof($array);
    $combocount=pow(2,$length);
for ($i=1; $i<$combocount; $i++)
    {

$binary = str_pad(decbin($i), $length, "0", STR_PAD_LEFT);
        $combination='';
        for($j=0;$j<$length;$j++)
        {
            if($binary[$j]=="1")
                $combination.=$array[$j];
        }
        $combinationsarray[]=$combination;
        echo $combination."&lt;br&gt;";
    }
    return $combinationsarray;
} 
  • 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. Editorial Team
    Editorial Team
    2026-05-25T09:45:18+00:00Added an answer on May 25, 2026 at 9:45 am

    mysql_query() only returns a result resource ID. To retrieve data, you must use one of the “fetch” commands, for example

    $params = array();
    while ($row = mysql_fetch_assoc($data)) {
        $params[] = $row['weight'];
    }
    

    Also, your query is possibly vulnerable to SQL injection. I wouldn’t implicitly trust the value from session_id(). I’m not entirely sure of this but it may simply retrieve the value from the session cookie.

    At the very least, sanitise the value with mysql_real_escape_string(). A more robust solution which would bring your code out of the dark ages would be to use PDO and parameter binding.

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

Sidebar

Related Questions

Is there something wrong with the code below it just won't work, no errors?
With the code below some smilies won't work (the text isn't replaced by a
Anyone have any idea why CGContextFillPath won't work in the code snippet below? I'm
My sentinel in below code won't work. It keeps looping instead of exiting when
The code below gives me this mysterious error, and i cannot fathom it. I
The code below works. But if I comment out the line Dim objRequest As
My code below won't compile. What am i doing wrong? I'm basically trying to
Using the code below, the expected behavior is that the database won't reflect the
(the example code below is self-contained and runnable, you can try it, it won't
This is probably unbelievably basic. In the code below, I have annotated the part

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.