Shadowing Posted December 14, 2011 Share Posted December 14, 2011 can someone please help me with this I'm trying to make it so that when the page loads just the condition below will happend unless the if statment happends. so I need two if statments that work off of one condition? so i was thinking of using OR but i would need a if statement that says the page is being loaded what this code does it displays someones profile when search is hit but i want it to display the persons own profile soon as the page is loaded first <?php if(isset($_POST['search'])) { // searches goaulds then displays them $search3 = "SELECT goauld,id FROM users WHERE goauld='".mysql_real_escape_string($_POST['goaulds'])."'"; $search2 = mysql_query($search3) or die(mysql_error()); WHILE($search1 = mysql_fetch_array($search2)){ $grab_goauld = $search1['goauld']; echo '<table width="300" height="5" border="1" align="center">'; echo '<th><center>Goauld Statistics</center></th>'; echo "<tr><td height='340'>$grab_goauld</td></tr>"; } } echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/ Share on other sites More sharing options...
Drongo_III Posted December 14, 2011 Share Posted December 14, 2011 So you want it to display the persons profile then display the search results if the user has done a search? Not quite following what you're trying to achieve. Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/#findComment-1297913 Share on other sites More sharing options...
Psycho Posted December 14, 2011 Share Posted December 14, 2011 OK, you really could work on your 'questions'. What you stated above is very confusing. Instead of talking about multiple if() statements and such. Just state what you are trying to accomplish, which I believe is: When the page is loaded and the user has not performed a search you want the page to displays the user's info. If the user has performed a search, then you want the page to display the information for the search. If that is the case, then you only need one conditional statement. IF the search field was submitted, then do a search on that value. If not, then use the value for the current user (you would need to have this stored in a session or cookie). if(isset($_POST['search'])) { $search_value = intval($_POST['search']); $where_clause = " goauld = {$search_value}"; } else { $search_id = intval($_SESSION['user_id']); $where_clause = " id = {$search_id}"; } // searches goaulds then displays them $query = "SELECT goauld, id FROM users WHERE {$where_clause} LIMIT 1"; $result = mysql_query($search3) or die(mysql_error()); $search1 = mysql_fetch_array($search2); $grab_goauld = $search1['goauld']; echo '<table width="300" height="5" border="1" align="center">'; echo '<th><center>Goauld Statistics</center></th>'; echo "<tr><td height='340'>$grab_goauld</td></tr>"; echo '</table>'; Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/#findComment-1297914 Share on other sites More sharing options...
Shadowing Posted December 14, 2011 Author Share Posted December 14, 2011 Sorry for the confusion guys Yah you guys are correct "When the page is loaded and the user has not performed a search you want the page to displays the user's info. If the user has performed a search, then you want the page to display the information for the search." $_SESSION['user_id'] is active It works. thanks so much now i have to try to understand how this is working. never seen the intval function before Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/#findComment-1297964 Share on other sites More sharing options...
KevinM1 Posted December 14, 2011 Share Posted December 14, 2011 Sorry for the confusion guys Yah you guys are correct "When the page is loaded and the user has not performed a search you want the page to displays the user's info. If the user has performed a search, then you want the page to display the information for the search." $_SESSION['user_id'] is active It works. thanks so much now i have to try to understand how this is working. never seen the intval function before Go here: http://www.php.net/quickref.php Bookmark it. Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/#findComment-1297972 Share on other sites More sharing options...
Shadowing Posted December 15, 2011 Author Share Posted December 15, 2011 thanks for that quick link KevinM1 I thought it was working but I guess not When page loads it shows current user when I search for another it shows current user still <?php if(isset($_POST['search'])){ $search_value = intval($_POST['search']); $where_clause = " goauld = {$search_value}"; }else{ $search_id = intval($_SESSION['user_id']); $where_clause = " id = {$search_id}"; } // searches goaulds then displays them $search3 = "SELECT goauld, id FROM game WHERE {$where_clause} LIMIT 1"; $search2 = mysql_query($search3) or die(mysql_error()); $search1 = mysql_fetch_array($search2); $grab_goauld = $search1['goauld']; echo '<table width="300" height="5" border="1" align="center">'; echo '<th><center>Goauld Statistics</center></th>'; echo "<tr><td height='340'>$grab_goauld</td></tr>"; echo '</table>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/#findComment-1297976 Share on other sites More sharing options...
Shadowing Posted December 15, 2011 Author Share Posted December 15, 2011 i think i noticed one problem <?php $search_value = intval($_POST['search']); $where_clause = " goauld = {$search_value}"; ?> $search_value = intval($_POST['goaulds']); i think that should say this since this is the form input but still doesnt work with that change Quote Link to comment https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/#findComment-1297978 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.