Jump to content

Why is only the 1st row returning?


DBookatay

Recommended Posts

Instead of each "ftr" returning the values, it only returns the first one, which is "Air Conditioning"

 

PHP Code:

			foreach ($row as $ftr => $value) {if (substr($ftr, 0,4)== "ftr_") {
			if ($ftr == "ftr_001") {if ($value == "x") {$kbbS[] = "Air Conditioning";}}
			if ($ftr == "ftr_002") {if ($value == "x") {$kbbS[] = "Leather";}}
			if ($ftr == "ftr_003") {if ($value == "x") {$kbbS[] = "ABS (4-Wheel)";}}
			if ($ftr == "ftr_004") {if ($value == "x") {$kbbS[] = "Tilt";}}
			if ($ftr == "ftr_005") {if ($value == "x") {$kbbS[] = "Power Windows";}}
			if ($ftr == "ftr_006") {if ($value == "x") {$kbbS[] = "Power Seat (D)";}}
			if ($ftr == "ftr_007") {if ($value == "x") {$kbbS[] = "Auto Climate Control";}}
			if ($ftr == "ftr_008") {if ($value == "x") {$kbbS[] = "Telescoping Wheel";}}
			if ($ftr == "ftr_009") {if ($value == "x") {$kbbS[] = "Power Door Locks";}}
			if ($ftr == "ftr_010") {if ($value == "x") {$kbbS[] = "Power Seat (P)";}}
			if ($ftr == "ftr_011") {if ($value == "x") {$kbbS[] = "Navigation System";}}
			if ($ftr == "ftr_012") {if ($value == "x") {$kbbS[] = "Rear Spoiler";}}
			if ($ftr == "ftr_013") {if ($value == "x") {$kbbS[] = "Power Mirrors";}}
			if ($ftr == "ftr_014") {if ($value == "x") {$kbbS[] = "Heated Seats (F)";}}
			if ($ftr == "ftr_015") {if ($value == "x") {$kbbS[] = "DVD System";}}
			if ($ftr == "ftr_016") {if ($value == "x") {$kbbS[] = "Power Steering";}}
			if ($ftr == "ftr_017") {if ($value == "x") {$kbbS[] = "Dual Front Airbags";}}
			if ($ftr == "ftr_018") {if ($value == "x") {$kbbS[] = "Bluetooth Wireless";}}
			if ($ftr == "ftr_019") {if ($value == "x") {$kbbS[] = "Cruise Control";}}
			if ($ftr == "ftr_020") {if ($value == "x") {$kbbS[] = "Side Airbags (F)";}}
			if ($ftr == "ftr_021") {if ($value == "x") {$kbbS[] = "Parking Sensors";}}
			if ($ftr == "ftr_022") {if ($value == "x") {$kbbS[] = "Sunroof";}}
			if ($ftr == "ftr_023") {if ($value == "x") {$kbbS[] = "Side Airbags (R)";}}
			if ($ftr == "ftr_024") {if ($value == "x") {$kbbS[] = "Alloy Wheels";}}
		}}

		$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>";}

 

Anyone spot any errors?

Link to comment
Share on other sites

yeah, use a switch first off, secondly you can do a foreach loop on a query result you must do while($row = mysql_fetch_array(){ to get all results

 

I dont understand? This one works:

		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";}}
	}}

<?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>";}

?>

 

Link to comment
Share on other sites

when he says to use a switch,

he means this

 

http://www.tizag.com/phpT/switch.php

 

 

I know how to use a switch statement, I use them a lot. How would I implament a switch statement into this?

		$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>";}

Link to comment
Share on other sites

Without knowing what your data looks like, it's impossible to debug your code. Syntactically it looks fine.

 

If I were coding this, I would put all of the features into an array, which would reduce your massive "if" statement to one line:

<?php
$kbbS_features = array('ftr_001' => 'Air Conditioning','ftr_002' => 'Telescoping Wheel','ftr_003' => 'Power Door Locks');
foreach ($row as $ftr => $value)
       if (substr($ftr, 0,4)== 'ftr_' && $value == 'x') 
                 $kbbS[] = kbbS_features[$ftr];
?>

 

I only put in the first 3 entries into the array to show how it would be done.

 

Ken

Link to comment
Share on other sites

Without knowing what your data looks like, it's impossible to debug your code. Syntactically it looks fine.

 

If I were coding this, I would put all of the features into an array, which would reduce your massive "if" statement to one line:

<?php
$kbbS_features = array('ftr_001' => 'Air Conditioning','ftr_002' => 'Telescoping Wheel','ftr_003' => 'Power Door Locks');
foreach ($row as $ftr => $value)
       if (substr($ftr, 0,4)== 'ftr_' && $value == 'x') 
                 $kbbS[] = kbbS_features[$ftr];
?>

 

I only put in the first 3 entries into the array to show how it would be done.

 

Ken

 

 

Parse error: syntax error, unexpected '[' in /home/.phillipina/dbookatay/carcityofdanbury.com/inventory_view2.php on line 340

 

Line 340:

$kbbS[] = kbbS_features[$ftr];

Link to comment
Share on other sites

Even with the new code it is only returning 1 "$ftr", which leads me to believe that the problem must be somewhere in here:

		$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>";}

 

Anyone spot anything?

Link to comment
Share on other sites

You're going to have to do some debugging of your code to see what data your script is seeing. Put code like

<?php
echo '<pre>' . print_r($row,true)  . '</pre>';
?>

 

in strategic places to dump the data.

 

Ken

 

Array

(

    [0] => 8

    [thecount] => 8

)

 

 

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.