MasterACE14 Posted October 3, 2007 Share Posted October 3, 2007 Morning PHPFreaks, I am recieving a unexpected T_IF parse error on my encyclopedia script I was working on alittle while back(some of you might of seen my post ) here's the error: Parse error: syntax error, unexpected T_IF in /home/ace/public_html/conflictingforces/lib/encyclopedia_search.php on line 34 and here's the complete script: <?php $item_cr = $_POST["cat"]; // this gets the checkbox value $item_search = $_POST["item"]; // this gets the search box value $item_type = $_POST["type"]; // this gets the drop down box value foreach($item_type as $key => $val){ if($item_search == $val[$item_cr]){ $search = 1; echo '<table class="fix"><tr>'; echo '<td colspan="2">' . if($item_type == "weapon"){echo "WEAPON";};elseif($item_type == "armor"){echo "ARMOR";};elseif($item_type == "vehicle"){echo "VEHICLE";}; . '</td></tr>'; echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>'; echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapon"){['weapon']}elseif($item_type == "armor"){['armor']}elseif($item_type == "vehicle"){['vehicle']} . '</td></tr>'; echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>'; echo '<tr><td>damage</td><td>' . $item_type[$key]if($item_type == "weapon"){['damage']}elseif($item_type == "armor"){['defence']}elseif($item_type == "vehicle"){['power']} . '</td></tr>'; echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>'; echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>'; echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>'; echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>'; echo '</table><br />'; } } if(!isset($search) || $search != 1){ echo "not found<br><br>"; } ?> Regards ACE Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/ Share on other sites More sharing options...
AndyB Posted October 3, 2007 Share Posted October 3, 2007 echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapon"){['weapon']}elseif($item_type == "armor"){['armor']}elseif($item_type == "vehicle"){['vehicle']} . '</td></tr>'; Makes no sense. There's the source of the mistake. Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360549 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 that fixed that error, now I got another: Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/ace/public_html/conflictingforces/lib/encyclopedia_search.php on line 34 I dont understand where it is expecting a , or ; after each if statement? Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360551 Share on other sites More sharing options...
AndyB Posted October 3, 2007 Share Posted October 3, 2007 that fixed that error, now I got another: Parse error: syntax error, unexpected T_IF, expecting ',' or ';' in /home/ace/public_html/conflictingforces/lib/encyclopedia_search.php on line 34 Why don't you post the revised code so we can see just what you fixed. With all those statements stuffed into one line, it's near impossible to see the logic and/or spot the mistake. Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360554 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 I agree, it was much neater before I made the adjustments :-\ : <?php $item_cr = $_POST["cat"]; // this gets the checkbox value $item_search = $_POST["item"]; // this gets the search box value $item_type = $_POST["type"]; // this gets the drop down box value foreach($item_type as $key => $val){ if($item_search == $val[$item_cr]){ $search = 1; echo '<table class="fix"><tr>'; echo '<td colspan="2">' . $item_type[$key]if($item_type == "weapons"){['weapon']}elseif($item_type == "armors"){['armor']}elseif($item_type == "vehicles"){['vehicle']} . '</td></tr>'; echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>'; echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapons"){['weapon']}elseif($item_type == "armor"){['armors']}elseif($item_type == "vehicles"){['vehicle']} . '</td></tr>'; echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>'; echo '<tr><td>damage</td><td>' . $item_type[$key]if($item_type == "weapons"){['damage']}elseif($item_type == "armors"){['defence']}elseif($item_type == "vehicles"){['power']} . '</td></tr>'; echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>'; echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>'; echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>'; echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>'; echo '</table><br />'; } } if(!isset($search) || $search != 1){ echo "not found<br><br>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360555 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360587 Share on other sites More sharing options...
teng84 Posted October 3, 2007 Share Posted October 3, 2007 what are this line !!!!!!!!!!!!!!!!!!!!!!!!!!!!! echo '<tr><td>weapon</td><td>' . $item_type[$key]if($item_type == "weapons"){['weapon']}elseif($item_type == "armor"){['armors']}elseif($item_type == "vehicles"){['vehicle']} . '</td></tr>'; that an error Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360590 Share on other sites More sharing options...
teng84 Posted October 3, 2007 Share Posted October 3, 2007 echo '<table class="fix"><tr>'; if($item_type == "weapons"){ $x= 'weapon'; } elseif($item_type == "armors"){ $x= 'armor'; } elseif($item_type == "vehicles"){ $x= 'vehicle'; } echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>'; do it that way thats the write way you seems to obtain your own ternary design LOL Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360593 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 Im not getting anymore parse errors now, the table comes up, but isnt showing anything in the second column, or in the column that spans 2 columns. It doesnt seem to be selecting the array. here's the part I added to select the array: <?php $item_type = $_POST["type"]; // this gets the drop down box value if($item_type == "weapons") { $array = $weapons; } elseif($item_type == "armors") { $array = $armors; } elseif($item_type == "vehicles") { $array = $vehicles; } foreach($array as $key => $val){ Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360606 Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 <?php foreach ($array as $item) { if (is_array($item)) { return true; }?> Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360609 Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 also i reason it doesnt work ur arraying shit in variables you hsould do $array= array('truck','car'); etc for each one Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360612 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 sorry? you've lost me, by the way I am using a Multi-Dimensional array. Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360614 Share on other sites More sharing options...
darkfreaks Posted October 3, 2007 Share Posted October 3, 2007 you need something like for each $weapon as $weapon etc <?php if($item_type == "weapons") { $array = $weapons; foreach( $weapon as $weapon ) { echo $weapon; } }?> Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360615 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 that just doesn't work with my current setup. Its quite an Advanced Array Search script I have setup, doing it the way you suggest would mean to rewrite the whole code. And would also mean cutting out some features and future features. Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360616 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 bump Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360648 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 double bump... Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360871 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 I see a potentially serious problem here. <?php $item_type = $_POST["type"]; // this gets the drop down box value foreach($item_type as $key => $val){ ?> The $_POST array is going to contain strings. Essentially, you're taking a string and trying to use it as if it is an array. I don't think this will do what you think it will. It will treat the string as an array of characters. As far as the error with the if statement, you're using the if statement as if it returns a value, which it does not. Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-360888 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 hmm ok Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361267 Share on other sites More sharing options...
MasterACE14 Posted October 3, 2007 Author Share Posted October 3, 2007 I dunno, their must be a way to put an array into a variable for the foreach statement. [code]<?php if($item_type == "weapons") { $array = $weapons; } elseif($item_type == "armors") { $array = $armors; } elseif($item_type == "vehicles") { $array = $vehicles; } foreach($array as $key => $val)[/code] :-\ Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361274 Share on other sites More sharing options...
teng84 Posted October 3, 2007 Share Posted October 3, 2007 can we see your recent code amd please explain and if posible give examples of your expected output? Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361280 Share on other sites More sharing options...
MmmVomit Posted October 3, 2007 Share Posted October 3, 2007 Don't think of it like that. You need to think in terms of the submission form. What are all the different pieces of data that are being submitted? Remember, these are all strings. No arrays. Given those pieces of data, how do you process them to accomplish your task? Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361281 Share on other sites More sharing options...
MasterACE14 Posted October 4, 2007 Author Share Posted October 4, 2007 yeah, I understand its all strings. But thats just works the IF statements. Its the first part of the foreach statement that needs an Array specified which is where the IF statements come in. here's the complete code: <?php // encyclopedia for the game /* includes */ include_once '/home/ace/public_html/conflictingforces/vehicles.php'; include_once '/home/ace/public_html/conflictingforces/armors.php'; include_once '/home/ace/public_html/conflictingforces/weapons.php'; include_once '/home/ace/public_html/conflictingforces/variables.php'; /* javascript alert if nothing was entered into the text box */ if($_POST["item"] == '' || $_POST["item"] == ' '){ echo "<script language=\"javascript\"> alert('You must enter a Weapon, Armor, or Vehicle into the Search box!') </script>"; } ?> <div id = "encyclopedia"> <center><b><u>Encyclopedia - Beta - Version <?php echo $encyclopedia_version; ?></u></b><br></center><br> <fieldset><legend>Search Results</legend> <center> <?php $item_cr = $_POST["cat"]; // this gets the checkbox value $item_search = $_POST["item"]; // this gets the search box value $item_type = $_POST["type"]; // this gets the drop down box value if($item_type == "weapons") { $array = $weapons; } elseif($item_type == "armors") { $array = $armors; } elseif($item_type == "vehicles") { $array = $vehicles; } foreach($array as $key => $val){ if($item_search == $val[$item_cr]){ $search = 1; echo '<table class="fix"><tr>'; if($item_type == "weapons"){ $x= 'weapon'; } elseif($item_type == "armors"){ $x= 'armor'; } elseif($item_type == "vehicles"){ $x= 'vehicle'; } echo '<td colspan="2">' . $item_type[$key][$x]. '</td></tr>'; echo '<tr><td>id</td><td>' . $item_type[$key]['id'] . '</td></tr>'; if($item_type == "weapons"){ $y= 'damage'; } elseif($item_type == "armors"){ $y= 'defence'; } elseif($item_type == "vehicles"){ $y= 'power'; } echo '<tr><td>' . $x . '</td><td>' . $item_type[$key][$x] . '</td></tr>'; echo '<tr><td>price</td><td>' . $item_type[$key]['price'] . '</td></tr>'; echo '<tr><td>' . $y . '</td><td>' . $item_type[$key][$y] . '</td></tr>'; echo '<tr><td>type</td><td>' . $item_type[$key]['type'] . '</td></tr>'; echo '<tr><td>rarity</td><td>' . $item_type[$key]['rarity'] . '</td></tr>'; echo '<tr><td>description</td><td>' . $item_type[$key]['description'] . '</td></tr>'; echo '<tr><td>options</td><td>' . $item_type[$key]['options'] . '</td></tr>'; echo '</table><br />'; } } if(!isset($search) || $search != 1){ echo "not found<br><br>"; } ?> <?php if($_POST["item"] == '' || $_POST["item"] == ' ' ){ echo "Click <b>back</b> and type in a Weapon, Armor or Vehicle.<br><br>"; } ?> <!-- This script and many more are available free online at --> <!-- The JavaScript Source!! http://javascript.internet.com --> <input type=button value="Back" onClick="history.go(-1)"> <!-- Change the value of -1 to any number of pages you would like to send your visitors back --> <!-- Script Size: 0.60 KB --> </center> </fieldset> <br> </div> I'm not getting any parse errors. Its showing the table but with only the left column displaying anything. The right column, and the top column spanning 2 rows are both blank. Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361299 Share on other sites More sharing options...
teng84 Posted October 4, 2007 Share Posted October 4, 2007 i dont know how dimensional your array is byt his code foreach($array as $key => $val){ if($item_search == $val[$item_cr]){ for me that means your having this arrray array(array('teng'=>array('astig'=>'item'))) the way you code your if and forech your multi dimensional array consist of 3 index? Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361302 Share on other sites More sharing options...
teng84 Posted October 4, 2007 Share Posted October 4, 2007 try foreach($item_type as $key ){ if($item_search == $key[$item_cr]){ Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361303 Share on other sites More sharing options...
teng84 Posted October 4, 2007 Share Posted October 4, 2007 BTW if($item_type == "weapons") { $array = $weapons; } elseif($item_type == "armors") { $array = $armors; } elseif($item_type == "vehicles") { $array = $vehicles; } wher do you get $armors,$vehicles,$weapons can we see the structure of those variables being an array? Quote Link to comment https://forums.phpfreaks.com/topic/71610-unexpected-t_if/#findComment-361305 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.