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 8575643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:44:24+00:00 2026-06-11T19:44:24+00:00

I have this code which permits me to get some ids $sql_id_att=SELECT DISTINCT att_id

  • 0

I have this code which permits me to get some ids

$sql_id_att="SELECT DISTINCT att_id FROM agenzia_pdv WHERE id_ag='$id_ag'";
$resultuserid_att=mysql_query($sql_id_att) or die(mysql_error());
while ($rows = mysql_fetch_array($resultuserid_att, MYSQL_ASSOC)) {

    $id_att=$rows['att_id'];
    echo $id_att;

}

And this one which i use to do the foreach function

foreach ($id_att as $attivita_id) {

    ?>
<form action="lista_attivita_ag_modifica.php?&id=<?php echo $attivita_id ; ?>" method="post" enctype="multipart/form-data">
 <input type="hidden" name="form_secret" id="form_secret" value="<?php echo $_SESSION['FORM_SECRET'];?>" />
<input type="submit" name="edit" value="<?php echo $row['attivita_da_promuovere']; ?>" />
</form>

<?php
    }

What am i doing wrong here?
It says:
Invalid argument supplied for foreach
But when i print the $id_att it works fine!
Thanks

I have this two arrays:

 $attivita_name[]=$rows['attivita_da_promuovere'
 $id_att[]=$rows['att_id'];

How can i print their contents using foreach, i mean i need to print :

$attivita_name[0]| $id_att[0]
$attivita_name[1]| $id_att[1]
$attivita_name[2]| $id_att[2]
  • 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-06-11T19:44:26+00:00Added an answer on June 11, 2026 at 7:44 pm

    you need to make $id_att as array

    $sql_id_att="SELECT DISTINCT att_id FROM agenzia_pdv WHERE id_ag='$id_ag'";
    $resultuserid_att=mysql_query($sql_id_att) or die(mysql_error());
    
    $id_att = array();
    $attivita_name = array();
    while ($rows = mysql_fetch_array($resultuserid_att, MYSQL_ASSOC)) {
        $attivita_name[]=$rows['attivita_da_promuovere'];
        $id_att[]=$rows['att_id'];
        echo $rows['att_id'];
    }
    
    // then you can iterate $id_att using foreach loop here
    $result_str = "";
    for($i=0 ; $i < count($id_att) ; $i++) {
        $result_str .= $attivita_name[$i] . "|" . $id_att[$i] . "\n";
    }
    echo $result_str;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code which retrieves some data from a sql query and place
I have this code which permits me to insert some dates i've selected in
I have this code here please, which permits me to import data from a
i have this piece of code which permits me to retrieve the information from
i have this quick issue please. I have this code here which permits me
I have this code (which is way simplified from the real code): public interface
I have this code which will include template.php file from inside each of these
I have this code which export data from GridView to csv. It works with
I have this code which depends on this javascript from dynamic drive: http://dynamicdrive.com/dynamicindex16/formdependency.htm Its
I have this code which reads all the files from a directory. File textFolder

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.