This topic is locked

Limit one add only

12/30/2022 12:41:01 PM
PHPRunner General questions
H
Hakkı Ü. author

Hello. Although I tried the following examples, I could not run the "if" condition in my own project.
I have a main table and a subtable connected to the main table in my database. If there is no record entered in my subtable, I want the "add new" button to be active. If there is a record, I want the "add new" button to be passive or not visible.

This topic has already been opened and solved in the forum. https://asprunner. https://asprunner.com/forums/topic/11124-limit-one-add-only

Translated with www.DeepL.com/Translator (free version)

global $conn;

$str = "select count(*) from alt_tablo";

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

$data = db_fetch_numarray($rs);

if ($data[0]) //if record exist

$xt->assign("add_link",false);

img alt

H
Hakkı Ü. author 12/30/2022

img alt

the code in the picture above did not work.

admin 12/31/2022

You are making changes to the code without understanding what it is for and how it may affect the end result. Do not change something that you do not understand.

For instance, you replaced if ($data[0]) with if ($data[1]) which cannot possibly work.

M
muammer 12/31/2022
global $conn;

$str = "select count(*) from alt_tablo";

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

$data = db_fetch_numarray($rs);

if ($data[0] >1) //if record exist

$xt->assign("add_link",false);

Hi Hakkı,
I don't know if you tried it for the case where the data value is greater than 1, if you want, try it like this, I hope it works.