Jump to content

Recommended Posts

I have a column in a database which i want to fetch 2 differing values from depending on the access rights of a member.

 

I have used

 

$countRes = mysql_query('SELECT * FROM table WHERE user = "'.$member.'"') or die(mysql_error());
$count=mysql_num_rows($countRes);
if(empty($count)) 
{
$file_stat[1] = 'public';
}
else
{
$file_stat[1] = 'public';
$file_stat[2] = 'friends';
}
mysql_free_result($countRes);
$result = mysql_query('SELECT * FROM table WHERE user = "'.$member.'" AND fileStatus IN("'.implode('", "', $file_stat).'")') or die(mysql_error())

 

This has worked for me before but doesn't seem to be working this time. Does anyone have a suggestion.

Link to comment
https://forums.phpfreaks.com/topic/148679-mysql-query/
Share on other sites

When the user isn't veryfied its showing public results only and when they are verifified it's only showing public results. I have added the following

 

if(empty($count)) 
{
$file_stat[1] = 'public';
echo 'Unverified';
}
else
{
$file_stat[1] = 'public';
$file_stat[2] = 'friends';
echo 'Verified';
}

 

When not logged in it shows public files and echoes unverified

 

When logged in it echoes verified and only shows public files.

 

There are no errors or warnings, if you didn't know better you'd think it was working fine

Link to comment
https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781135
Share on other sites

the  "fileStatus" is a column in the database which hold information whether a file is for public viewing for friends viewing only. Basically what it is, is

 


SELECT & FROM table WHERE file_is_either IN("public, friends")

 

I cannot find anything on the mysql 'IN' function and was hopeing someone could assist

Link to comment
https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781256
Share on other sites

I am really sorry to mess everyone around who took the time to read this post but both

 


$result = mysql_query("SELECT * FROM table WHERE user = '".$member."' AND fileStatus IN('".implode("', '", $file_stat)."')") or die(mysql_error());

 

and

 

 

$result = mysql_query('SELECT * FROM table WHERE user = "'.$member.'" AND fileStatus IN("'.implode('", "', $file_stat).'")') or die(mysql_error())

 

work fine, the trouble was there is a third setting in the fileStatus table (private), there where no friends just public and private so that's where it was going wrong/right. Aparently it was the idiot on the keyboard that was coding it that was the error

Link to comment
https://forums.phpfreaks.com/topic/148679-mysql-query/#findComment-781526
Share on other sites

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.