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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:47:43+00:00 2026-05-28T06:47:43+00:00

So basicly what I’m trying to accomplish is that foreach row in mysql query

  • 0

So basicly what I’m trying to accomplish is that foreach row in mysql query it prints out the html with the data from that row. Here’s what I have, it keeps giving me an error on my foreach.

<?php

$shots = mysql_query("SELECT * FROM shots") or die(mysql_error());

while($row=mysql_fetch_array($shots))
$data[]=$row;


foreach($shots as $data)

  if (!empty($data)){

  $id = $data["id"];
  $shotby = $data["shot"];
  $passby = $data["pass"];
  $time = $data["time"];
?>


<div class="feedbody">

    <div class="title"><?php echo $shotby; ?></div>
    <div class="feed-data">: gets a pass from <span><?php echo $passby; ?</span> and he takes a shot!</div>
    <img class="dot" src="images/dot.png" />

</div>
<?php
}

}
?>

Or something like that. Can anybody help point me in the right direction. I’ve been trying to find the answer.

EDIT: adding the error as requested.

Warning: Invalid argument supplied for foreach() in /home/content/93/7527593/html/fusionboard/includes/feed.php on line 7
  • 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-28T06:47:44+00:00Added an answer on May 28, 2026 at 6:47 am

    First, if you want to access the data by name (instead of index), you need to include MYSQL_ASSOC as a second parameter to mysql_fetch_array, or use mysql_fetch_assoc.

    Not really sure why you were copying the MySQL results to a second array just to loop through that later – you can loop through the results directly:

    <?php
    $shots = mysql_query("SELECT * FROM shots") or die(mysql_error());
    while($row = mysql_fetch_assoc($shots)) { ?>
    <div class="feedbody">
        <div class="title"><?php echo $row["shot"]; ?></div>
        <div class="feed-data">: gets a pass from <span><?php echo $row["pass"]; ?></span> and he takes a shot!</div>
        <img class="dot" src="images/dot.png" />
    </div>
    <?php } ?>
    

    Update after you posted the error message: the error from your original code was that you first went through and copied each result row into $data, but then in your foreach you tried to loop on $shots (again) and have it call each item $data.

    What you probably wanted to do was have foreach ($data as $item) and then copy the properties from $item.

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

Sidebar

Related Questions

Hi basicly i am trying to use the svm from here . It is
I'm just starting out with HTML and Dreamweaver. Basicly, I'm trying to create a
Basicly i'm trying to create image cropping script, and it's almost done, here is
Basicly I'm making an image gallery that downloads from the web. So - when
I'm new to java and am trying to write a simple program that basicly
i am creating rss reader application with php.it is basicly getting rss url's from
What I'm trying to do is basicly what this photo shows. When I select
You can check page here: http://jsfiddle.net/7JhjN/ Basicly, there is a hell of duplication going
basicly, I'm trying to show the result of a listview (created with QSLite)but in
Ok, basicly, I made a script (that one) that makes a .post to a

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.