Jump to content

php with mysql session id


BluwAngel

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
https://forums.phpfreaks.com/topic/258042-php-with-mysql-session-id/
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.

Archived

This topic is now archived and is closed to further replies.

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