Angelojoseph17 Posted February 8, 2010 Share Posted February 8, 2010 Hi i have a while loop which takes values out of an array. but my else statement wont work. please tell me why while($row=mysql_fetch_array($result)){ $Solutions =$row['solutions']; $Issue=$row['Issue']; $Category=$row['Category']; //-display the result of the array echo "<p>" .$Solutions . " " . $Category . "</p>\n"; } } if($row['solutions'] = ''){ require("google.php"); } } } I just wanna know why it wont even break into an else. or an if. I'm new to php btw. Quote Link to comment https://forums.phpfreaks.com/topic/191368-while-loop-help/ Share on other sites More sharing options...
jl5501 Posted February 8, 2010 Share Posted February 8, 2010 If what you posted is your code you are using you can see you have far too many }'s Quote Link to comment https://forums.phpfreaks.com/topic/191368-while-loop-help/#findComment-1008900 Share on other sites More sharing options...
Angelojoseph17 Posted February 8, 2010 Author Share Posted February 8, 2010 <?php if(isset($_POST['submit'])){ if(isset($_GET['go'])){ if(preg_match("/^[ a-zA-Z]+/", $_POST['name'])){ $name=$_POST['name']; //connect to the database $db=mysql_connect ("localhost", "root", "blabla") or die ('I cannot connect to the database because: ' . mysql_error()); //-select the database to use $mydb=mysql_select_db("final_project"); //-query the database table $sql="SELECT Issue, Category,solutions FROM Persons WHERE Issue LIKE '%" . $name . "%' OR Category LIKE '%" . $name ."%'"; //-run the query against the mysql query function $result=mysql_query($sql); //-create while loop and loop through result set while($row=mysql_fetch_array($result)){ $Solutions =$row['solutions']; $Issue=$row['Issue']; $Category=$row['Category']; //-display the result of the array echo "<p>" .$Solutions . " " . $Category . "</p>\n"; } } else if($row['solutions'] = ''){ require("google.php"); } } } ?> Thats the whole bit of code. Quote Link to comment https://forums.phpfreaks.com/topic/191368-while-loop-help/#findComment-1008902 Share on other sites More sharing options...
premiso Posted February 8, 2010 Share Posted February 8, 2010 I do not even see an else statement in that code. You have way too many braces } which could be because you have not posted the whole code. Before you venture further into programming I would highly suggest you read up on Ident Styles for programming, pick one and stick to it. As well PHP has it's own standards set by PEAR which you can find Pear PHP Code Standards It will help you throughout programming doing proper indentation as it helps with debugging. If you are just using notepad, I would suggest getting an editor like Notepad++ or Netbeans by Java with PHP Syntax Highlighting. Quote Link to comment https://forums.phpfreaks.com/topic/191368-while-loop-help/#findComment-1008904 Share on other sites More sharing options...
KevinM1 Posted February 8, 2010 Share Posted February 8, 2010 I think they're referring to the else if, which was written as just an if in the OP. If that's the case, your logic is messed up. If the first case (the regex) is true, then you access the db and do a bunch of stuff. If it's not true (else if), then there's no $row['solution'] because you haven't accessed the db. The db is accessed only if the first case is true. Quote Link to comment https://forums.phpfreaks.com/topic/191368-while-loop-help/#findComment-1008906 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.