This topic is locked
[SOLVED]

 $_SESSION["UserID"] and code snippets

8/12/2010 3:35:20 PM
PHPRunner General questions
K
kkiboo author

I am trying to create a code snippet that tells the logged in user how many rows they have created.

$str = "select count(*) from Table where person=$_SESSION["UserID"]";

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

echo "My rows today:".$data["COUNT(*)"];


Obviously, the code above does not work. Is it possible to use the $_SESSION["User ID"] here? If not, is there a workaround?
Thanks in advance <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=14983&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />

A
ann 8/13/2010

Hi,
here is the correct syntax for the code:

$str = "select count(*) as cnt from Table where person=". $_SESSION["UserID"];

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

echo "My rows today:".$data["cnt"];
K
kkiboo author 8/13/2010



Hi,
here is the correct syntax for the code:

$str = "select count(*) as cnt from Table where person=". $_SESSION["UserID"];

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

echo "My rows today:".$data["cnt"];



Thanks. While this does pull up and recognize that the variable = the current user, I get an invalid identifier error because that format leads the query to come out as person=user instead of person='user'.

A
ann 8/13/2010

Hi,
then you'll need to add quotes in the code:

$str = "select count(*) as cnt from Table where person='". $_SESSION["UserID"]."'";

$rs = CustomQuery($str);

$data = db_fetch_array($rs);

echo "My rows today:".$data["cnt"];
K
kkiboo author 8/13/2010

Thanks; For some reason, it still wasn't working, but I took out the "as cnt" part to return it back to just

count(*)

and

.$data["COUNT(*)"]

and it works just fine now. <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=51858&image=1&table=forumreplies' class='bbc_emoticon' alt=':)' />