This topic is locked

View rights

5/11/2009 6:14:17 AM
PHPRunner General questions
R
Ravengaard author

I have a problem that needs solving.

I am trying to create a page where a specific user can only list records that contain a specific value. But he should also be able to list his own records, even if this value is not set.
Can this be done with the "Advanced" Tab under "Security"? Or do I need some additional customized code?
I have tried using ordinary filters on the "Edit SQL Query" tab.

J
Jane 5/11/2009

Hi,
use List page: Before SQL query event on theEvents tab to add dynamic where clause.

Here is a sample:

$strWhereClause = whereAdd($strWhereClause,"Fieldname='test value'");

R
Ravengaard author 5/12/2009

Thanks for your reply.

I have gotten it to work semi-properly.
Could I call on $username or something in this event? I would like to get the username of the currently active user.

(Select user.id where username=$Username)

I would like to call on username to be able to get the ID associated with it. Then compare that ID against owner ID in the table.

And also add an "or" statement which tells it to also add records with "this field is not null"
So basicly, he should see his owns posts and posts with a specific value over "null", even if he is not the owner of them.

J
Jane 5/12/2009

Hi,
username of current user is stored in the $_SESSION["UserID"] variable.

You can select ID based on the username using following code:

global $conn;

$str = "select ID from UsersTable where UserName='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$_SESSION["ID"] = $data["ID"];

R
Ravengaard author 5/12/2009

Hi, thank you for you swift reply.

The snippet of code you gave me works like a charm, still working on the second problem. Making the list show records where "Datum" is bigger then "0", even if the user is not the owner of it.
This is what I've done so far:

(1st, selecting the posts where the user is set as owner)

(2nd, Trying to create an OR statement for Datum)

Will the OR statement work in this case? (Or will it try to parse the already parsed records of the earlier strWhereClause?

$strWhereClause = whereAdd($strWhereClause,"Owner_Id='".$data["ID"]."'");

$strWhereClause = whereAdd($strWhereClause,"Datum > 0", 'OR');


It crashes, refering to that it thinks that 'OR' is a second column (I think).

J
Jane 5/12/2009

Hi,
try to use this one:

$strWhereClause = whereAdd($strWhereClause,"Owner_Id='".$data["ID"]."' or Datum > 0");

R
Ravengaard author 5/12/2009

Thanks a bunch! Works very well.