DBookatay Posted December 19, 2007 Share Posted December 19, 2007 I posted this topic about a week ago, but no one could give me an answer why only the first "ftr" (Air Conditioning) is showing up, and nothing else. (Here is a working example: http://www.carcityofdanbury.com/inventory_view2.php?stock=15984 Under "Selected Equipment") $kbbS_features = array( 'ftr_001' => 'Air Conditioning', 'ftr_002' => 'Telescoping Wheel', 'ftr_003' => 'ABS (4-Wheel)', 'ftr_004' => 'Tilt', 'ftr_005' => 'Power Windows', 'ftr_006' => 'Power Seat (D)', 'ftr_007' => 'Auto Climate Control', 'ftr_008' => 'Telescoping Wheel', 'ftr_009' => 'Power Door Locks', 'ftr_010' => 'Power Seat (P)', 'ftr_011' => 'Navigation System', 'ftr_012' => 'Rear Spoiler', 'ftr_013' => 'Power Mirrors', 'ftr_014' => 'Heated Seats (F)', 'ftr_015' => 'DVD System', 'ftr_016' => 'Power Steering', 'ftr_017' => 'Dual Front Airbags', 'ftr_018' => 'Bluetooth Wireless', 'ftr_019' => 'Cruise Control', 'ftr_020' => 'Side Airbags (F)', 'ftr_021' => 'Parking Sensors', 'ftr_022' => 'Sunroof', 'ftr_023' => 'Side Airbags (R)', 'ftr_024' => 'Alloy Wheels' ); foreach ($row as $ftr => $value) if (substr($ftr, 0,4)== 'ftr_' && $value == 'x') $kbbS[] = $kbbS_features[$ftr]; $standard = ""; for($x=0; $x<count($ftr);$x++) { if($x%2==0){$standard .= "<table><tr>";} $standard .= "<td height=\"20\" width=\"115\">{$kbbS[$x]}</td>"; if($x%2==1){$standard .= "</tr></table>";} } if($x%2==1) {$standard .= "<td> </td></tr></table>";} Else where in the code I have the <? echo $standard; ?> echoed, but only Air Conditioning is showing up. And on the test example all 24 "ftr"s are available. Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/ Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 You are giving me nothing at all to work with. I see variables but i have no idea what the variables are and therefore cannot help you. so if you want help then give us the whole thing Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418256 Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 You are giving me nothing at all to work with. I see variables but i have no idea what the variables are and therefore cannot help you. so if you want help then give us the whole thing This was the old code, then someone rewrote it to make it more efficent: foreach ($row as $feature => $value) {if (substr($feature, 0,== "feature_") { if ($feature == "feature_AC") {if ($value == "x") {$features[] = "Air Conditioning";}} if ($feature == "feature_PW") {if ($value == "x") {$features[] = "Power Windows";}} if ($feature == "feature_PDL") {if ($value == "x") {$features[] = "Power Door Locks";}} if ($feature == "feature_PM") {if ($value == "x") {$features[] = "Power Mirrors";}} if ($feature == "feature_CC") {if ($value == "x") {$features[] = "Cruise Control";}} if ($feature == "feature_SR") {if ($value == "x") {$features[] = "Sunroof";}} if ($feature == "feature_LS") {if ($value == "x") {$features[] = "Leather Seats";}} if ($feature == "feature_PS") {if ($value == "x") {$features[] = "Power Seat(s)";}} if ($feature == "feature_HFS") {if ($value == "x") {$features[] = "Heated Front Seats";}} if ($feature == "feature_HRS") {if ($value == "x") {$features[] = "Heated Rear Seats";}} if ($feature == "feature_TW") {if ($value == "x") {$features[] = "Tilt Steering Wheel";}} if ($feature == "feature_TCW") {if ($value == "x") {$features[] = "Telescoping Wheel";}} if ($feature == "feature_KE") {if ($value == "x") {$features[] = "Keyless Entry";}} if ($feature == "feature_TRS") {if ($value == "x") {$features[] = "Third Row Seating";}} if ($feature == "feature_RS") {if ($value == "x") {$features[] = "Remote Start";}} if ($feature == "feature_SP") {if ($value == "x") {$features[] = "Snow Plow";}} if ($feature == "feature_RR") {if ($value == "x") {$features[] = "Roof Rack";}} if ($feature == "feature_AW") {if ($value == "x") {$features[] = "Alloy Wheels";}} if ($feature == "feature_FL") {if ($value == "x") {$features[] = "Fog Lights";}} if ($feature == "feature_BL") {if ($value == "x") {$features[] = "Bed Liner";}} if ($feature == "feature_HID") {if ($value == "x") {$features[] = "H.I.D Lights";}} if ($feature == "feature_PG") {if ($value == "x") {$features[] = "Privacy Glass";}} if ($feature == "feature_TP") {if ($value == "x") {$features[] = "Tow Package";}} if ($feature == "feature_GPS") {if ($value == "x") {$features[] = "GPS System";}} if ($feature == "feature_NS") {if ($value == "x") {$features[] = "Navigation System";}} if ($feature == "feature_DVD") {if ($value == "x") {$features[] = "DVD System";}} if ($feature == "feature_TA") {if ($value == "x") {$features[] = "Theft Alarm";}} if ($feature == "feature_ABS") {if ($value == "x") {$features[] = "Anti-Lock Brakes";}} if ($feature == "feature_FAB") {if ($value == "x") {$features[] = "Dual Front Airbags";}} if ($feature == "feature_SCF") {if ($value == "x") {$features[] = "Side Curtin Airbags (F)";}} if ($feature == "feature_SCR") {if ($value == "x") {$features[] = "Side Curtin Airbags (R)";}} if ($feature == "feature_DCC") {if ($value == "x") {$features[] = "Dual Climate Control";}} if ($feature == "feature_PAP") {if ($value == "x") {$features[] = "Power Adjustable Pedals";}} if ($feature == "feature_MS") {if ($value == "x") {$features[] = "Memory Seats(s)";}} if ($feature == "feature_OS") {if ($value == "x") {$features[] = "OnStar";}} if ($feature == "feature_HL") {if ($value == "x") {$features[] = "HomeLink";}} }} The the display <?php for($x=0; $x<count($features);$x++) { if($x%2==0){echo "<table width=\"100%\"><tr>";} echo "<td class=\"vehFtrs\"><img src=\"images/Common/KBB/bulletOn.gif\" /> {$features[$x]}</td>"; if($x%2==1){echo "</tr></table>";} } if($x%2==1) {echo "<td> </td></tr></table>";} ?> Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418258 Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 The way you had the array was co <?php $kbbS_features = array( 'ftr_001' => 'Air Conditioning', 'ftr_002' => 'Telescoping Wheel', 'ftr_003' => 'ABS (4-Wheel)', 'ftr_004' => 'Tilt', 'ftr_005' => 'Power Windows', 'ftr_006' => 'Power Seat (D)', 'ftr_007' => 'Auto Climate Control', 'ftr_008' => 'Telescoping Wheel', 'ftr_009' => 'Power Door Locks', 'ftr_010' => 'Power Seat (P)', 'ftr_011' => 'Navigation System', 'ftr_012' => 'Rear Spoiler', 'ftr_013' => 'Power Mirrors', 'ftr_014' => 'Heated Seats (F)', 'ftr_015' => 'DVD System', 'ftr_016' => 'Power Steering', 'ftr_017' => 'Dual Front Airbags', 'ftr_018' => 'Bluetooth Wireless', 'ftr_019' => 'Cruise Control', 'ftr_020' => 'Side Airbags (F)', 'ftr_021' => 'Parking Sensors', 'ftr_022' => 'Sunroof', 'ftr_023' => 'Side Airbags (R)', 'ftr_024' => 'Alloy Wheels' ); $kbbs = ''; foreach($row as $feature) { $feature_contains = substr($feature, 0, 4); if($feature_contains == 'ftr_') if($value == 'x') { $kbbs .= '"' . $kbbS_features[$feature] . '",'; } } } $kbbs = substr($kbbs, 0, strlen($kbbs)-1); $kbbs = explode(',', $kbbs); ?> After you have done this you have an array of all of that vehicles features. now when you go to echo this you would do a: <?php foreach($kbbs as $feature) { print $feature . '<br />'; } ?> which should show you all of your dream cars features Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418267 Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 The way you had the array was co <?php $kbbS_features = array( 'ftr_001' => 'Air Conditioning', 'ftr_002' => 'Telescoping Wheel', 'ftr_003' => 'ABS (4-Wheel)', 'ftr_004' => 'Tilt', 'ftr_005' => 'Power Windows', 'ftr_006' => 'Power Seat (D)', 'ftr_007' => 'Auto Climate Control', 'ftr_008' => 'Telescoping Wheel', 'ftr_009' => 'Power Door Locks', 'ftr_010' => 'Power Seat (P)', 'ftr_011' => 'Navigation System', 'ftr_012' => 'Rear Spoiler', 'ftr_013' => 'Power Mirrors', 'ftr_014' => 'Heated Seats (F)', 'ftr_015' => 'DVD System', 'ftr_016' => 'Power Steering', 'ftr_017' => 'Dual Front Airbags', 'ftr_018' => 'Bluetooth Wireless', 'ftr_019' => 'Cruise Control', 'ftr_020' => 'Side Airbags (F)', 'ftr_021' => 'Parking Sensors', 'ftr_022' => 'Sunroof', 'ftr_023' => 'Side Airbags (R)', 'ftr_024' => 'Alloy Wheels' ); $kbbs = ''; foreach($row as $feature) { $feature_contains = substr($feature, 0, 4); if($feature_contains == 'ftr_') if($value == 'x') { $kbbs .= '"' . $kbbS_features[$feature] . '",'; } } } $kbbs = substr($kbbs, 0, strlen($kbbs)-1); $kbbs = explode(',', $kbbs); ?> After you have done this you have an array of all of that vehicles features. now when you go to echo this you would do a: <?php foreach($kbbs as $feature) { print $feature . '<br />'; } ?> which should show you all of your dream cars features Problem is, I need the "$features" to not just print, but to print into its own cell, meaning: <tr> <td>Air Conditioning</td> <td>Telescoping Wheel</td> </tr> <tr> <td>ABS (4-Wheel)</td> <td>Navigation System</td> </tr> <tr> <td>Dual Front Airbags</td> <td>Alloy Wheels</td> </tr> and if its an uneven amount <tr> <td>Air Conditioning</td> <td>Telescoping Wheel</td> </tr> <tr> <td>ABS (4-Wheel)</td> <td>Navigation System</td> </tr> <tr> <td colspan="2">Alloy Wheels</td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418458 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 Here is a simple multi column script. Replace the while statement with the loop for your array <?php echo '<table border="0" CELLSPACING="0" CELLPADDING="10" align="center">'; //set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc $numcols = 2; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT sdate, type FROM dategroup ORDER BY sdate ASC"; $mysql_result = mysql_query($query) or die (mysql_error()); // get each row while($myrow = mysql_fetch_row($mysql_result)) { //get data - eg, reading fields 0 and 1 $tn = $myrow[0]; $in= $myrow[1]; if ($numcolsprinted == $numcols) { echo "</tr>\n<tr>\n"; $numcolsprinted = 0; } // output row from database echo "<td>$in $tn</td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } echo "<TD></TD>\n"; echo "</table>; ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418465 Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 Your post really has nothing to do with this topic Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418469 Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 Here is a simple multi column script. Replace the while statement with the loop for your array <?php echo '<table border="0" CELLSPACING="0" CELLPADDING="10" align="center">'; //set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc $numcols = 2; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT sdate, type FROM dategroup ORDER BY sdate ASC"; $mysql_result = mysql_query($query) or die (mysql_error()); // get each row while($myrow = mysql_fetch_row($mysql_result)) { //get data - eg, reading fields 0 and 1 $tn = $myrow[0]; $in= $myrow[1]; if ($numcolsprinted == $numcols) { echo "</tr>\n<tr>\n"; $numcolsprinted = 0; } // output row from database echo "<td>$in $tn</td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } echo "<TD></TD>\n"; echo "</table>; ?> Ray Ok, I'm following you so far, but where I have the "ftrs" echoing is already in a php string. Meaning: if ($kbbPrice) { $right = '<div align="center"><table><tr><td><img src="images/Common/KBB/hdrL.gif" width="9" height="73" /><a href="http://www.kbb.com/KBB/UsedCars/'.$kbbValue.'" target="_blank"><img src="images/Common/KBB/hdrM.gif" width="153" height="73" /></a><img src="images/Common/KBB/hdrR.gif" width="204" height="73" /></td></tr><tr><td class="ContHldr" align="center"><div align="right" style="padding: 0 14 0 0"><img src="images/Common/KBB/bulletOff.gif" name="kbb001" /> <a onMouseOver="img2over(kbb001)" onMouseOut="img2out(kbb001)" class="KBB" href="http://www.kbb.com/KBB/UsedCars/'.$kbbValue.'" target="_blank">View Full Blue Book Report</a><br /><br /></div><div><img src="images/Common/KBB/hdr01.gif" /></div><br /><div align="center"><table width="345"><tr><td><img style="border: 1px solid #999999" src="'.$kbbImage.'" /></td><td rowspan="2"><img src="images/Common/spacer.gif" width="10" height="1" /></td><td rowspan="2"><table class="KBB1" width="170"><tr><td class="txt1">Condition</td><td class="txt1">Value</td></tr><tr class="KBB1"><td class="txt1"><font color="#000000">Excellent</font></td><td class="txt1" width="70">'.$kbbPrice.'</td></tr><tr><td class="KBB2" colspan="2"><b>Suggested Retail<br />Value Assumes<br />Excellent Condition...</b></td></tr></table></td></tr><tr><td style="padding: 5 0 0 0"><img src="images/Common/KBB/icon_Pic.gif" /> <a class="KBB" href="http://www.kbb.com/KBB/UsedCars/'.$kbbPics.'" target="_blank">More Photos</a></td></tr></table><p><table class="KBB2" width="345"><tr><td><div id="KBB1"><table width="328"><tr class="KBB2"><td class="txt2">Average Consumer Rating</td><td valign="middle" rowspan="2"><img src="images/Common/KBB/bulletOff.gif" name="kbb002" /> <a class="KBB" onMouseOver="img2over(kbb002)" onMouseOut="img2out(kbb002)" href="http://www.kbb.com/KBB/UsedCars/'.$kbbRatings.'" target="_blank">Read Reviews</a><br /><br /><img src="images/Common/KBB/bulletOff.gif" name="kbb003" /> <a class="KBB" onMouseOver="img2over(kbb003)" onMouseOut="img2out(kbb003)" href="http://www.kbb.com/KBB/UsedCars/'.$kbbRatings.'" target="_blank">Review This Vehicle</a></td></tr><tr><td height="46">'.$kbbRating.'</td></tr></table></div></td></tr></table><p><table class="KBB2" width="345"><tr><td><div id="KBB1"><table><tr class="KBB22"><td class="txt2" colspan="2">Vehicle Highlights</td></tr><tr><td height="20" width="90"><b>Mileage:</b></td><td height="20" width="255">'.$mileage.'</td></tr><tr><td height="20" width="90"><b>Engine:</b></td><td height="20" width="255">'.$kbbEng.'</td></tr><tr><td height="20" width="90"><b>Transmission:</b></td><td height="20" width="255">'.$kbbTrans.'</td></tr><tr><td height="20" width="90"><b>Drivetrain:</b></td><td height="20" width="255">'.$kbbDrive.'</td></tr></table></div></td></tr></table><p><table class="KBB2" width="345"><tr><td><div id="KBB1"><table><tr class="KBB2"><td class="txt2" colspan="3">Selected Equipment</td></tr><tr><td height="30" width="345" colspan="3"><b>Standard</b></td></tr>'.$standard.$optional.'</div></td></tr></table></div><div id="KBB2" align="left">* Connecticut '.$today.'</div></td></tr><tr><td><img src="images/Default/Titles/btm365.gif" /></td></tr></table></div><p>'; } So how do I edit the script to not "echo" but return it as "$standard"? Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418470 Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 Alright i modified the script so that it will do two per table row. as well you can go back and change this by adding another step. If you have a vehicle which has the following things: Air Conditioning Telescoping Wheel ABS (4-Wheel) Navigation System Dual Front Airbags Alloy Wheels And you use this code: <?php $kbbs_num = '1'; foreach($kbbs as $feature) { if($kbbs_num == '1') { print '<tr><td>' $feature . '</td>'; $kbbs_num = '2'; elseif($kbbs_num == '2') { print '<td>' $feature . '</td></tr>'; $kbbs_num = '1'; } } ?> You will now get the output: <tr> <td>Air Conditioning</td> <td>Telescoping Wheel</td> </tr> <tr> <td>ABS (4-Wheel)</td> <td>Navigation System</td> </tr> <tr> <td>Dual Front Airbags</td> <td>Alloy Wheels</td> </tr> Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418472 Share on other sites More sharing options...
DBookatay Posted December 19, 2007 Author Share Posted December 19, 2007 Your post really has nothing to do with this topic Parse error: syntax error, unexpected T_FOREACH in /home/.phillipina/dbookatay/carcityofdanbury.com/inventory_view2.php on line 386 Line 386:foreach($kbbs as $feature) { Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418475 Share on other sites More sharing options...
mr_mind Posted December 19, 2007 Share Posted December 19, 2007 place a ; after $kbbs_num ='1' Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418476 Share on other sites More sharing options...
craygo Posted December 19, 2007 Share Posted December 19, 2007 First of all he asked for a multi-column script so I gave it to him. Second just replace the echo with the variable <?php $standard = ""; $standard .= "<table border=0 CELLSPACING=0 CELLPADDING=0 align=center>"; //set 3 to 4 of you want 4 columns. Set it to 5 if you want 5, etc $numcols = 2; // how many columns to display $numcolsprinted = 0; // no of columns so far // get the results to be displayed $query = "SELECT sdate, type FROM dategroup ORDER BY sdate ASC"; $mysql_result = mysql_query($query) or die (mysql_error()); // get each row while($myrow = mysql_fetch_row($mysql_result)) { //get data - eg, reading fields 0 and 1 $tn = $myrow[0]; $in= $myrow[1]; if ($numcolsprinted == $numcols) { $standard .= "</tr>\n<tr>\n"; $numcolsprinted = 0; } // output row from database $standard .= "<td>$in $tn</td>\n"; // bump up row counter $numcolsprinted++; } // end while loop $colstobalance = $numcols - $numcolsprinted; for ($i=1; $i<=$colstobalance; $i++) { } $standard .= "<TD></TD>\n"; $standard .= "</table>; ?> Now if you echo $standard you should get your table Ray Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-418477 Share on other sites More sharing options...
mr_mind Posted December 20, 2007 Share Posted December 20, 2007 third that it is really a lot longer than need be. Quote Link to comment https://forums.phpfreaks.com/topic/82282-still-cant-figure-this-out-only-returning-the-1st-option/#findComment-419175 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.