![](https://forums.phpfreaks.com/uploads/set_resources_1/84c1e40ea0e759e3f1505eb1788ddf3c_pattern.png)
DBookatay
-
Posts
334 -
Joined
-
Last visited
Posts posted by DBookatay
-
-
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
)
-
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?
-
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];
-
-
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>";}
-
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>";}
?>
-
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?
-
Thats it....
Thank you!!!
-
Im not sure, your code will work on all browsers. Because, you are placing the data generated by the first file (<table>...</table>) into the second file after </tr>. so, in most of the browsers the data will not be shown if they are placed in non-data area. It should be placed after the table closed or between <td></td> tags.
The html code isnt complete, so ignore that.
I didnt bother to check it, wanted to wait till I finished everything..
Do you have any ideas for the php question I posed? I would really rather not use an include file
-
you can use a require to pull the second script into the first script. I use a similar technique to add functionality and keep things simple.
How is this accomplished?
-
I am in the middle of revamping my current site, add have a question about putting a current script into an existing php script...
Heres what I mean:
The current script:
<?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>"; } ?>
What I am trying to now do is relocate it into this script:
<? if ($kbbPrice) { $kbb = ' <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"><img src="images/Common/KBB/hdr01.gif" /></td></tr> </table> <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> ************ INSERT NEW CODE HERE ************ </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>';} ?>
How can this be done?
-
Post what the current code is, showing one under the other...
-
I have a field in my dB that I use to store links from other websites, (Kelly Blue Book / kbb.com) to be exact, which uses links like this:
http://www.kbb.com/KBB/UsedCars/PricingReport.aspx?VehicleId=3110&ManufacturerId=34&ModelId=227&YearId=2004&Mileage=54210&SelectionHistory=3110%7c6222%7c06810%7c0%7c0%7c120944%7ctrue%7c120968%7ctrue%7c120857%7ctrue
Problem is, when I pull the info out of the dB
$kbbSlctn = $row['kbbSlctn'];
it turns all of the "%" into "|", so the result is
http://www.kbb.com/KBB/UsedCars/PricingReport.aspx?VehicleId=3110&ManufacturerId=34&ModelId=227&YearId=2004&Mileage=54210&SelectionHistory=3110|7c6222|7c06810|7c0|7c0|7c120944|7ctrue|7c120968|7ctrue|7c120857|7ctrue
What is happening here?
-
Here's a more important question: why use $row_count at all? You're already using mysql_num_rows().
Good point...
-
Thanks guys, that solved it.
-
Still now showing the "Sorry, no listings" line...
-
Can anyone spot a problem with the following code?
My line
if (!$row_count) $listings = '<div><b>Sorry, no listings under '.$category.' matchining your criteria were found.</b></div>';
is not working.
Complete code:
$query = "SELECT * FROM listings WHERE category = '{$_GET['id']}'"; $result = mysql_query($query); $numrows = mysql_num_rows($result); for($x = 0; $row = mysql_fetch_array($result); $x++) { $id = $row['id']; $lines = stripslashes($row['lines']); $markets = stripslashes($row['markets']); $opportunity = stripslashes($row['opportunity']); $listings .= '<div id="list"><table width="100%"><tr><td class="listID"><a href="NEED_LINK?id='.$id.'">Listing ID: '.$id.'</a></td></tr><tr><td class="listLine"><b>Product Lines:</b> '.$lines.'</td></tr><tr><td class="listLine"><b>Target Markets:</b> '.$markets.'</td></tr><tr><td class="listLine"><b>Sales Opportunity:</b> '.$opportunity.'</td></tr></table></div>'; $row_count++; if (!$row_count) $listings = '<div><b>Sorry, no listings under '.$category.' matchining your criteria were found.</b></div>'; }
-
http://en.wikipedia.org/wiki/MD5
32 characters, typically, regardless of input string. Most of the fields I work with set the VARCHAR to 40 chars.
PhREEEk
Thanks for the help, and the article...
-
I am setting up a registration form that has password fields.
I set up the field with a maxlength of 20 characters and am encrypting the entry using MD5.
Question is, if a password is the entire 20 characters, what length should I set my VARCHAR input in the dB?
How many alphanumeric characters are returned in MD5 for 1 "normal" character?
-
Got it...
function formatText($inputName,$text) { if ($_SERVER['REQUEST_METHOD']=="POST") { if (empty($_POST[$inputName])) { return '<span class="redBold">'.$text.'</span>'; $_SESSION['ispassed']=false; } else { return $text; } } else { return $text; } }
Had to change all "echo"s to "return".
-
-
Look at this page: http://bestsalesreps.com/index.php?main=004®Type=Rep here the error I am having is clearly shown.
Instead of the input names "First" , "Last" etc echoing where they should (above the input box) they are showing up at the top of the page...
That I what I am trying to solve...
Anyone???
-
Look at this page: http://bestsalesreps.com/index.php?main=004®Type=Rep here the error I am having is clearly shown.
Instead of the input names "First" , "Last" etc echoing where they should (above the input box) they are showing up at the top of the page...
That I what I am trying to solve...
-
No...I don't want the code to the function. I want the code to where you are trying to USE the function.
<? //Required Fields function formatText($inputName,$text) { if ($_SERVER['REQUEST_METHOD']=="POST") { if(empty($_POST[$inputName])) { echo '<span class="redBold">'.$text.'</span>'; $_SESSION['ispassed']=false; } else {echo $text;} } else echo $text; } if(isset($_GET['regType'])); switch($_GET['regType']) { case 'Rep': $regType = ' <table> <tr> <td valign="top"> <!-- START LEFT --> <div id="sctnTle">Personal Information</div> <div id="sctnHldr"> <table> <tr> <td class="frm">'.formatText("nmF","First") .'</td> <td width="10" rowspan="2"> </td> <td class="frm">M.</td> <td width="10" rowspan="2"> </td> <td class="frm">'.formatText("nmL","Last") .'</td> </tr> <tr> <td><input id="input" type="text" name="nmF" size="20" autocomplete="off" value="'.$POST_nmF.'" /></td> <td><input id="char1" type="text" name="nmM" size="1" autocomplete="off" maxlength="1" value="'.$POST_nmM.'" onKeyup="autotab(this, document.form.nmL)" /></td> <td><input id="input" type="text" name="nmL" size="24" autocomplete="off" value="'.$POST_nmL.'" /></td> </tr> <tr><td class="frmPad" colspan="5">'.formatText("email1","Email Address") .'</td></tr> <tr><td colspan="5"><input id="input" type="text" name="email1" size="40" autocomplete="off" value="'.$POST_email1.'" /></td></tr> <tr><td class="frmPad" colspan="5">'.formatText("email2","Confirm Email Address") .'</td></tr> <tr><td colspan="5"><input id="input" type="text" name="email2" size="40" autocomplete="off" value="'.$POST_email2.'" /></td></tr> </table> <table> <tr><td class="frmPad">Time Zone</td></tr> <tr><td>'.$timezones.'</td></tr> </table> </div> <div id="sctnTle">Login Information</div> <div id="sctnHldr"> <table> <tr><td class="frm">'.formatText("uname","Desired Username") .'</td></tr> <tr><td><input id="input" type="text" name="uname" size="35" autocomplete="off" value="'.$POST_uname.'" /></td></tr> <tr><td class="frmPad">'.formatText("pass1","Password") .'</td></tr> <tr><td><input id="input" type="password" name="pass1" size="35" autocomplete="off" value="'.$POST_pass1.'" /></td></tr> <tr><td class="frmPad">'.formatText("pass2","Confirm Password") .'</td></tr> <tr><td><input id="input" type="password" name="pass2" size="35" autocomplete="off" value="'.$POST_pass2.'" /></td></tr> </table> </div>'; break; } ?>
[SOLVED] Problem with a "Stay Updated" script
in PHP Coding Help
Posted
I am trying to make a form on my site (http://www.carcityofdanbury.com/inventory.php?status=Error#StayUpdated) where a user enters their email address if they wish to recieve emails when my site is updated, but I'm obviously doing something incorrect, cause the script keeps failing. Can someone show/ tell me what is wrong?
The HTML
The PHP:
(I know that the code is much longer and hacked togather than it needs to be, but I am a self admitted "NOOB!")