Jump to content

php with mysql session id


BluwAngel
 Share

Recommended Posts

i need to create search in database like this select everything from database but it cant be included rows where session id is equal to id of user

 

code

$datum	= "$godina-$mjesec-$dan";
$event_select	= mysql_query("SELECT * FROM events WHERE event_date='$datum'");

//izlistat evente
while ($events = mysql_fetch_array($event_select))
	{			
		$id_user	= $events['id_user'];
		$user_select= mysql_query("SELECT * FROM users WHERE id='$id_user' ");
		$user 		= mysql_fetch_array($user_select);

... creating table

 

i tried to put something like

AND id!=$_SESSION[id] but it didnt work

 

so i need create table for every row where id_user is not equal to session id

now it works and i get table for every row

 

do i need if loop or?

Link to comment
Share on other sites

Instead of having a query inside of a loop, which you should always avoid doing, use a JOIN and filter the results of the join using the ON clause.

 

$event_select_sql = "SELECT e.*,u.* FROM events e LEFT JOIN users u ON (u.id = e.id_user) WHERE e.event_date = '$datum' AND e.id_user != {$_SESSION['id']}";
$event_select_query = mysql_query($event_select_sql) or die($event_select_sql . "<br />" . mysql_error());
while($events = mysql_fetch_array($event_select_query))
{
    //create table with db fields...
}

 

Also, avoid selecting every field from a db table, this will slow down the query. Instead, select only the fields that you are going to use.

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

×
×
  • 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.