Guest Bsmiffy1 Posted June 30, 2006 Share Posted June 30, 2006 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->Itembut 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 1but i get $mi_sp_record1->Item Quantity 1please adviseFull 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 https://forums.phpfreaks.com/topic/13329-data-from-db/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.