This topic is locked

Show / Hide Add new depending on content

11/20/2007 12:30:08 AM
PHPRunner General questions
M
mmponline author

I want the Add new link to the add page to disappearas soon as the user loaded his/her first record - Thus allowing only adding one record per user.
Eg.

  1. User registers.
  2. Login and "no records added" mesage is displayed.
  3. User adds first record by clicking "Add new" link.
  4. After recrd added, the link on the list page needs to dissappear.
    Thanks for any help.

J
Jane 11/20/2007

Stephan,
you can do the following:

  • proceed to the Visual Editor tab, switch to HTML mode,
  • find this code:
    <INPUT class=button onclick="java script:window.location.href='_test_add.php'" type=button value="Add new" disptype="control1">

and replace it with this one:

{if $addnew}<INPUT class=button onclick="java script:window.location.href='_test_add.php'" type=button value="Add new" disptype="control1">{/if}


  • then add List page: Before Display event on the Events tab.

    Here is a sample:
    global $conn;

    $str = "select count(*) from TableName where UserName='".$_SESSION["UserID"]."'";

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

    $data = db_fetch_numarray($rs);

    if ($data[0])

    $smarty->assign("addnew",0);

    else

    $smarty->assign("addnew",1);

M
mmponline author 11/20/2007

I have problems with this: The button shows on empty as well as when there is a listing already. Please verify which fields the red info should refer to:
QUOTE
<INPUT class=button onclick="java script:window.location.href='_test_add.php' " type=button value="Add new" disptype="control1">
and replace it with this one:
QUOTE
{if $addnew}<INPUT class=button onclick="java script:window.location.href='_test_add.php' " type=button value="Add new" disptype="control1">{/if}

  • then add List page: Before Display event on the Events tab.

    Here is a sample:
    QUOTE
    global $conn;

    $str = "select count(*) from [color="#FF0000"]TableName - have it _PlayerInformation where UserID - not sure"]."'";

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

    $data = db_fetch_numarray($rs);

    if ($data[0])

    $smarty->assign("addnew",0);

    else

    $smarty->assign("addnew",1);
    I don't need to use a button, can be a normal text link, if this will make it easier.

J
Jane 11/20/2007

Stephan,
make sure your query return correct value:

$str = "select count(*) from _PlayerInformation where UserName='".$_SESSION["UserID - not sure"]."'";

echo $str;



UserName is your actual field name where login name is stored.