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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:18:15+00:00 2026-06-09T20:18:15+00:00

I’m trying to grasp OOP and I decided to build a site that accesses

  • 0

I’m trying to grasp OOP and I decided to build a site that accesses a sql database.
It’s been working out great so far I have several tables, but I’ve run into a snag

I access the database and create an object array with

$Dog_array = $sth->fetchAll(PDO::FETCH_CLASS, 'Dog');

Simplified but my class looks like this.

class Dog {
     private $name;

     function get_name {
     return $this->name;
    } 

list that build my table

function edit_table($Dog) {

echo "<table><tr><form action='update.php' method ='post'>";
echo "<input type='hidden' name='id' value='" . $id ."'>";

echo "<td>". $Dog->get_id() ."</td>";
?>
<td><input type='text' name='rname' value="<?php echo $Dog->get_rname(); ?>"></td>
<td><input type='text' name='cname' value="<?php echo $Dog->get_cname(); ?>"></td>
<td><input type='text' name='dob' value="<?php echo $Dog->get_dob(); ?>"></td>
<td><input type='radio' name='gender' value='male' <?PHP if($Dog->get_gender() == 'male'){ echo "checked=\"checked\""; } ?> /> Male
<input type='radio' name='gender' value='female' <?PHP if($Dog->get_gender() == 'female'){ echo "checked=\"checked\""; } ?> />Female</td>
<td><input type='text' name='sire' value="<?PHP echo "builddropdown" ?> "></td>
<td><input type='text' name='dam' value="<?PHP drop_menu() ?>"></td>
<?php

if ($Dog->get_available()) {
    $checked = "checked=\"checked\"";
} else {
    $checked = NULL;
echo "<td><input type=\"checkbox\"" . $checked . "name=\"available\" value=\"TRUE\"/></td>";

if ($Dog->get_display()) {
    $checked = "checked=\"checked\"";
} else {
    $checked = NULL;
}
echo "<td><input type=\"checkbox\"" . $checked . "name=\"display\" value=\"TRUE\"/></td></tr></table>";
?>
<input type='submit' value='change image'/></form>
<FORM METHOD="LINK" ACTION="upload.php">
<INPUT TYPE="submit" VALUE="Change Image Thumb">
</FORM>
<input type='submit' value='change image'/></form>
<FORM METHOD="LINK" ACTION="upload.php">
<INPUT TYPE="submit" VALUE="Change Image Thumb">
</FORM>
    <?php
    }
?>
<input type='submit' value='update'/></form>
<FORM METHOD="LINK" ACTION="index.php">
<INPUT TYPE="submit" VALUE="Back">
</FORM>
<?php 
}

?>

My drop down

function drop_menu() {

?>
<form name ="dropdown">
<select ="alldogs">
<?php
        foreach ($Dog_array as $Dogs) { 
        ?>
        <option value="<?php echo $Dogs->get_id() . "\">" . $Dogs->get_rname();   ?></option>
<?php } ?>
</select>
</form>
<? }

My drop down menu creates a list of all of the dogs.

I get the error Invalid argument supplied for foreach

I get why I get the error I just don’t know how to clean this up so I don’t have to pass my Object array into my edit_table function so I can pass it into drop down function
.
I thought about creating a child class but the menu is built from an array of the objects not one object so I don’t know how to make this work either. New to forum posting, so feel free to recommend some corrections in how I ask for help.

  • 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-09T20:18:16+00:00Added an answer on June 9, 2026 at 8:18 pm

    It’s a problem with the arrage $Dog_array scope.
    You need to pass the $Dog_array to the drop_menu function.

    <?php
    function drop_menu($Dog_array) {
    
    ?>
    <form name ="dropdown">
    <select ="alldogs">
    <?php
    foreach ($Dog_array as $Dogs) { 
    ?>
    <option value="<?php echo $Dogs->get_id() . "\">" . $Dogs->get_rname();   ?>></option>
    <?php } ?>
    </select>
    </form>
    <? }
    

    And whenever you need to call the function, pass the array normally.

    Also you can pass by reference

    <?php
    function drop_menu(&$Dog_array) {?>
    

    In this case any manipulation to the array inside the function will impact the original array directly.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.