Jump to content


data from db


  • Please log in to reply
No replies to this topic

#1 Guest_Bsmiffy1_*

Guest_Bsmiffy1_*
  • Guests

Posted 30 June 2006 - 06:52 PM

Hi I'm trying to create a while loop but can't get it right.

I've read my  MySql database record into an array:

   // Should select 9 records 0-8
 
   $mi_sp_rows = ff_select("select * from `#__ta_menuItems` where `Type`=$Type and `Specials`=$Specials and `Hot`=$Hot Order by `Item`");

   if (!$mi_sp_rows) {
       die( 'died no mi sp rows');
   }

    $mi_sp_record1 = $mi_sp_rows[0];
    $mi_sp_record2 = $mi_sp_rows[1];
    $mi_sp_record3 = $mi_sp_rows[2];
    $mi_sp_record4 = $mi_sp_rows[3];
    $mi_sp_record5 = $mi_sp_rows[4]; 
    $mi_sp_record6 = $mi_sp_rows[5]; 
    $mi_sp_record7 = $mi_sp_rows[6]; 
    $mi_sp_record8 = $mi_sp_rows[7]; 
    $mi_sp_record9 = $mi_sp_rows[8];

I can get the data value i want when i use:

                $itemname = $mi_sp_record1->Item;

but I want to use the above line in a while loop so i need to change the 1 to the current record number.

So I creted a variable:
              $getitemname = "$". "mi_sp_record". $spitemcount. "->Item";

which gives me the combination of the text and the current item number:

    $getitemname now contains  $mi_sp_record1->Item

but when i use the variable I just get the text and not the data in the record item:

    $sp_page = $sp_page. $getitemname . " Quantity ". $spqty ;

output should be    item name(from db record)  Quantity 1
but i get              $mi_sp_record1->Item  Quantity  1

please advise

Full code below:

     $spmax = 9;
     $spcount = 0;
     $spitmecount = 1;
     $getitem = '';
     $spqty = 0;
     $sp_page = "The following <B>Sandwich on ". ff_getSubmit(sp_bread_type). "  ". ff_getSubmit(sp_spread). "</B><BR><BR>";

     while ($spcount <= $spmax) {
            $spcount++;
            $getitem = "sp_Item". $spitemcount . "_Qty";
            $getitemname = "$". "mi_sp_record". $spitemcount. "->Item";
            $getitemnamevalue = $getitemname;
            $itemname = $mi_sp_record1->Item;
echo "<p>item name is  $itemname </P>";
            $itemname = "$". "mi_sp_record". $spitemcount. "->Item";
echo "<p>item name is  $itemname </P>";
            $itemnamecont = $itemname;
echo "<p>item name1 is  $itemnamecont </P>";
            $spitemcount++;
            $spqty = ff_getSubmit($getitem);
                 if($spqty > 0) {
                      $sp_page = $sp_page. $getitemname . " Quantity ". $spqty ;
                      $sp_page = $sp_page. " <BR><BR>" ;
                 }
      }





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users