Jump to content

Recommended Posts

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>';
  
?>

Link to comment
https://forums.phpfreaks.com/topic/253168-if-statments-triggering-on-page-load/
Share on other sites

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>';

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

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.

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>';

?>

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

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.