Page 1 of 1

SelectedID=$data['id']

Posted: 2022-02-01 15:52
by pasbonte
Hello
I am a beginner...and I advance empirically..
Why is this not working? thank you !


I'm talking about
href="http://www.xxxxxxxxx.org/xxxxxxxxx/INFO ... edID=$data['id']>TABLEAU des informations</a>
et SelectedID=$data['id']

* send an email notification when a new order is placed CREATION : fiche nouvelle envoyée à xxxxxxxx tous*/
ob_start(); ?>
<h3>Important : Nouvelle information pour vous</h3>
<hr>
<table>
<tr><td><b>NUMERO ID</b></td><td><?php echo $data['id']; ?></td></tr>
<tr><td><b>TITRE</b></td><td><?php echo sqlValue("select TITRE from INFORMATIONS_ADMINISTRATIVES where id='" . makeSafe($data['id']) . "'"); ?></td></tr>

<p>Veuillez vous connecter à l'application pour visualiser cette information <a href="http://www.xxxxx-xxxxx.org/xxxxxxx/INFO ... p">TABLEAU des informations</a><br/>

<p>Veuillez vous connecter à l'application pour visualiser cette information <a href="http://www.xxxxxxxxx.org/xxxxxxxxx/INFO ... edID=$data['id']>TABLEAU des informations</a><br/>
</table>
<?php
$mail_body = ob_get_contents();
ob_end_clean();

//$customer_email = sqlValue("select email from customers where CustomerID='" . makeSafe($data['CustomerID']) . "'");

mail(
'[email protected]',
'Nouvelle information sur INTRANET : ' . $data['TITRE'],
$mail_body,
"From: [email protected]\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-type: text/html; charset=iso-8859-1\r\n"
);

Re: SelectedID=$data['id']

Posted: 2022-02-01 21:00
by angus
try using

Code: Select all

$data['selectedID']

Re: SelectedID=$data['id']

Posted: 2022-02-02 08:17
by pasbonte
Hello
I am completely blocked on this variable, which exists but which I cannot pass, it seems to me that I have tried everything with the " " or the ' '

Code: Select all

<a href="http://www.xxxxxx.org/xxxxxx/INFORMATIONS_ADMINISTRATIVES_view.php?SelectedID="'$data['id'])'">TABLEAU des informations</a><br/>

Re: SelectedID=$data['id']

Posted: 2022-02-02 08:50
by jsetzer
PHP and other programming languages make it easy to mess up with quotes and variables.

You can build your link like this:

Code: Select all

<?php

$pk = $data['id'] ?? $data['selectedID']; // PHP 7
$href = "http://www.xxxxxx.org/xxxxxx/INFORMATIONS_ADMINISTRATIVES_view.php?SelectedID={$pk}";
$link = "<a href=\"{$href}\">TABLEAU des informations</a>";
Tipp

When inserting records, there is no primary set in $data variable. But, as mentioned above, we can use 'selectedID' entry of $data array. Especially when passing $data into other functions or class methods, I usually use the following code for getting the primary key, even if not set, yet:

Annotation:
My primary keys are always named 'id'. If your's are named differently, change it or take a look at the alternative at the end of this article.


For PHP 7...

The Null Coalescing Operator (??) requires PHP 7.

Code: Select all

$pk = $data['id'] ?? $data['selectedID'];
Older PHP versions

Code: Select all

$pk = isset($data['id']) ? $data['id'] : $data['selectedID']; 
Both alternatives return 'id' value, if set, otherwise the 'selectedID' value

Alternative with flexible primary key column name

This alternative automatically detects the primary key column name of given table $tn and returns that value, if set, otherwise the 'selectedID' value

Code: Select all

<?php

// change this
$tn = "TABLENAME"; 
$caption = "Open record";

// don't change this if you want to open a record of the given AppGini table $tn ---->
$pk = $data[getPKFieldName($tn)] ?? $data['selectedID'];
$href = "{$tn}_view.php?SelectedID={$pk}";
$link = "<a href=\"{$href}\">{$caption}</a>";
// <--------------

// you can use $link variable now

Re: SelectedID=$data['id']

Posted: 2022-02-03 07:53
by pasbonte
Hello
Thank you jsetzer
Excellent course, which I will keep and study, a big thank you (you should sell them, small explanatory sheets..) !