Jump to content

data from db


Guest Bsmiffy1

Recommended Posts

Guest Bsmiffy1
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:

[code]  // 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]; [/code]

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:

[code]    $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>" ;
                }
      }
[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.