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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:20:20+00:00 2026-05-15T08:20:20+00:00

hello i have a problem that’s maybe difficult to descripe, i have an application,

  • 0

hello i have a problem that’s maybe difficult to descripe,

i have an application, that simulates a pizza store. i have a page “bestellungen” (“orders”)
in which i have some javascript.(the head,javascript and body i declare in page.php, from which the other (“sub”)pages “extends”.

right now, everything works, but now, i want to add to the javascript some php code. (in the “main” page.

in the page “bestellungen” (“orders”) i read from the database

$sql="Select * FROM pizzen_arten";
        $data=$this->_database->query($sql);    //alle daten in data gespeichert


        while($reihe = $data->fetch_array()){   

            $lfdnr=$reihe[2];                       
            $this->pizza_name[$lfdnr]   =$reihe[0];
            $this->pizza_preis[$lfdnr]  =$reihe[1];
            $this->pizza_id[$lfdnr] =$reihe[2];

        }

then in the same page i add all pizzas

foreach ($this->pizza_id as $tmp)   //alle pizzen durchgehen über id, (id in tmp speichern)
{
//echo " überall wo " ist ein \ davor
    echo "<img src=\"pizzen/pizza-".$this->pizza_name[$tmp].".png\" width=\"50\" height=\"50\" alt=\"Pizza ".$this->pizza_name[$tmp]."\" id=\"".$this->pizza_name[$tmp]."\" onclick=\"hinzu('".$this->pizza_name[$tmp]."')\" /> ".$this->pizza_name[$tmp]." ".$this->pizza_preis[$tmp]." &euro;"; 
    echo "<p/>";                                                                                                                                //vor variable " string beenden . für "+" dann var, dann string weiter
        //this das aktuelle obj, der schleife,  davon pizzaname (ist ein array! kein attribut), an der stelle tmp
}

the method “hinzu(id)” is declared in “page.php”

function hinzu (pizza)
{

    NeuerEintrag = new Option(pizza, pizza, false, false);
    document.getElementById("warenkorbfeld").options[document.getElementById("warenkorbfeld").length] = NeuerEintrag ;

ETO;



    foreach ($this->pizza_id as $tmp)
    {

        if ($this->pizza_name[tmp]==pizza)  //array durchgehen gucken, wann der übergabe parameter ==einem pizzanamen
            echo "gesamtbetrag=gesamtbetrag"+$this->pizza_preis[$tmp];
    }

    /*if (pizza=="Margherita")
    {
        gesamtbetrag = gesamtbetrag + 4;
    }

    if (pizza=="Salami")
    {
        gesamtbetrag = gesamtbetrag + 4.50;
    }

    if (pizza=="Hawaii")
    {
        gesamtbetrag = gesamtbetrag + 5.50;
    }*/

    echo <<< ETO

    document.getElementById('gesamtbetrag').innerHTML=gesamtbetrag ;

}

at first the method was without php-code, now by using php-code it doesn’t work.

i suggest there might be a problem with “$this” or “pizza” but i’m not quite sure wether i implemented the php code right.

thanks in advance

  • 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-15T08:20:21+00:00Added an answer on May 15, 2026 at 8:20 am

    You can’t simply mixup JavaScript and PHP code Like this. JavaScript Code is executed in the Users Browser and the PHP code is executed on your server. So you have to make clear which code is to be executed on you server. In PHP you do this with the PHP Tags <?php & ?>:

    function hinzu(pizza) {
      NeuerEintrag = new Option(pizza, pizza, false, false);
      document.getElementById("warenkorbfeld").options[document.getElementById("warenkorbfeld").length] = NeuerEintrag ;
      <?php foreach ($this->pizza_id as $tmp): ?>
        gesamtbetrag=gesamtbetrag + <?php= $this->pizza_preis[$tmp] ?>;
      <?php endforeach; ?>
      document.getElementById('gesamtbetrag').innerHTML = gesamtbetrag;
    }
    

    or if I’m interpreting your heredoc strings correctly:

    echo <<<ETO
      function hinzu(pizza) {
        NeuerEintrag = new Option(pizza, pizza, false, false);
        document.getElementById("warenkorbfeld").options[document.getElementById("warenkorbfeld").length] = NeuerEintrag ;
    ETO;
    foreach ($this->pizza_id as $tmp) {
      echo "gesamtbetrag=gesamtbetrag+" . $this=>pizza_preis[$tmp];
      // The important differnces:   ^  ^ 
    }
    echo <<<ETO
      document.getElementById('gesamtbetrag').innerHTML = gesamtbetrag;
    }
    ETO;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have a problem with c# Arrays. I need a array to store
Hello we have an SQL server application running over a low bandwith connection. We
Imagine I have the following: inFile = /adda/adas/sdas/hello.txt # that instruction give me hello.txt
Hello I have problem to put together animations of two separate objects to second
i have problem with libhid . i found that there 2 way 4 accessing
Hello I am a Java web app developer I have a problem, I would
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Hello I have a number of crystal reports in my VS2008 project. I am
I have done this: $ z() { echo 'hello world'; } How do I
If I have data in the following format id subid text 1 1 Hello

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.