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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:49:02+00:00 2026-06-12T04:49:02+00:00

I am trying to create a PHP function that will echo info from a

  • 0

I am trying to create a PHP function that will echo info from a db. My col names look like banana[1], banana[2], apple[1], apple[2], apple[3], and so on.

The function will select the fruit

function fruits($fruit){

}

and then within that function I’ll loop through the fruits.

How do I echo these?

echo $fruit[$i];

obviously doesn’t work.

Pretty basic, but I can’t figure out. Concatenation kills me.

function ponctuation($section,$sect){

switch($section){
    case 'apple':
        $i=1;
    break;
    case 'banana':
        $i=13;
    break;
}

global $mysql_tablename;
global $FName;
global $Lname;

if(isset($mysql_tablename)){
$result = mysql_query("SELECT * FROM $mysql_tablename WHERE FName='$FName' AND Lname='$Lname'");
    $row = mysql_fetch_array($result);

echo '<form method="post" action="ponctuation.php?'.${$section.$sect}.'_valider">';
echo '<ul>';
$query = mysql_query("SELECT * FROM `ponct_enonces` WHERE `section`='$section' AND `sect`='$sect'");
while($row_q = mysql_fetch_assoc($query)) {
    if($row_q['enon']==0 && $row_q['senon']==0){
        echo '<h2>'.$row_q['enonce'].'</h2>';
    }
    if($row_q['enon']==1){
            echo '<h3>'.$row_q['enonce'].'</h3>';
            echo '<textarea rows="3" cols="100" name="'.$i.'" wrap="physical">' . $row[$section[$i]] . '</textarea>';
    }
    if($row_q['senon']==1){
            echo '<h4>'.$row_q['enonce'].'</h4>';
            echo '<textarea rows="3" cols="100" name="'.$i.'" wrap="physical">' . $row[$section]. '</textarea>';
    }
    $i++;
    }
echo '</ol>';
echo '<input type="submit" name="submit" value="Valider"/>';
echo '</form>';
}

}

The code is a little ugly, and some vars have French names, other have English names.

  • 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-12T04:49:03+00:00Added an answer on June 12, 2026 at 4:49 am

    col names won’t be expanded into PHP array structures for you, e.g.

    SELECT fruit[1], fruit[2], ...., fruit[100]
    

    will give you the equivalent of

    $row = array(
       'fruit[1]' => someval,
       'fruit[2]' => someval,
       ...
    );
    

    if you want to iterate those, you’ll have to get ugly:

    $fruit = array();
    for ($i = 0; $i <= 100; $i++) {
        $fruit[$i] = $row['fruit[' . $i . ']'];
    }
    

    which begs the question of… why? This is a horrible data structure to be using. Properly normalizing it into a ‘fruit attributes’ sub-table would save you this trouble, and also allow you to have n attributes, rather than the fixed 1..100 range or whatever it is you have.

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

Sidebar

Related Questions

I'm trying to create a generic class in PHP that will provide a way
I'm a php noob and trying to create a image resizing script that will
Im trying to create a function, that will return a mysql query, which i
I am trying to create a php file that adds a user and create
I am trying to create a php file that would scan a directory, make
I'm trying to create a PHP form on a website that collects users' name,
Here's an idea. I'm trying to create file from PHP script. File may be
I am trying to create a for loop that will parse out different elements
I'm trying to build a jQuery function that will allow me to produce a
I'm trying to create a php page with fopen() this php file will house

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.