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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:07:25+00:00 2026-05-24T17:07:25+00:00

i am tying to do this by a function. i want every item found

  • 0

i am tying to do this by a function. i want every item found in the db to be echoed out as a list

eg. item1
item2
item3
item4

i know im missing something but it is puzzling me. for now im only seeing one list and upon
refresh another item shows up replacing the other. plz help and thanks

function get_list() {
 $id = mysql_real_escape_string(@$_GET['id']); 
$get_list = array();
$bar = mysql_query(" SELECT  bar.* FROM bar WHERE bar.b_id = '$id' ORDER BY rand()");
 while($kpl = mysql_fetch_assoc($bar)){
 $get_list[] = array( 'videoid' => $kpl['videoid'],
                'name' => $kpl['name'],
                'description' => $kpl['description'],
                'type' => $kpl['type'],
                'bev' => $kpl['bev'],           
);
}
foreach ($get_list as $get_list);
return $get_list;
}
?>
<?php
$gkp_list = gkp_list();
foreach ($gkp_list as $gkp_list);
if (empty($gkp_list)){ echo 'no video'; }
else { 
echo '<p>$gkp_list['name']. '<br/></p>';}
?>
  • 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-24T17:07:25+00:00Added an answer on May 24, 2026 at 5:07 pm

    There are some major syntax problems there.

    function get_list() {
        $id = mysql_real_escape_string(@$_GET['id']); 
        $get_list = array();
        $bar = mysql_query(" SELECT  bar.* FROM bar WHERE bar.b_id = '$id' ORDER BY rand()");
        while($kpl = mysql_fetch_assoc($bar)){
            $get_list[] = $kpl;         
        }
        return $get_list;
    }
    
    $gkp_list = get_list();
    if (empty($gkp_list)) {
        echo 'no video';
    } else {
        foreach ($gkp_list as $gkp_item) {
            echo '<p>' . $gkp_item['name']. '<br/></p>';
        }
    }
    ?>
    
    1. The purpose of foreach is to loop over an array and do something with each value. Don’t use foreach if you’re working with the array as a whole (in this case, returning it)
    2. Foreach doesn’t have a semicolon at the end, it typically has an opening curly brace ({).
    3. You don’t need to manually copy all of the array indexes in the while loop, because all of the indexes are the same.
    4. The string for the output was formatted wrong, you have to be careful. Use a syntax-highlighting editor.
    5. The two variable names in foreach must be different. One refers to the array, and one refers to the value of that key.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Help me out, gurus /* * In this function, I want the static variable
I'm trying to call a function that contains jQuery code. I want this function
I'm trying to find any reference for this function, but I haven't found anything.
I'm trying to find out where this function comes from. Any one have any
I'm trying to figure out how to write this function: template <typename Bound> Bound::result_type
was trying to add this gesture function to my first program, and almost every
I have a list of images and I want to wrap every 2 images
I am trying to use this function from a COM API which enables the
I'm trying to compile this function from Learn You a Haskell for Great Good
This function of mine keeps on failing an autograder, I am trying to figure

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.