when new record added create data from id and static information

Jun 14, 2008
55
0
66

Hi, I have a datbase tabe like this:

CREATE TABLE `paper` (
`id_paper` INTEGER(11) NOT NULL AUTO_INCREMENT,
`sample_url` VARCHAR(50) COLLATE utf8_general_ci NOT NULL DEFAULT '',
PRIMARY KEY (`id_paper`)


When I add new record I need the field "sample_url" to automatically add this information:

images/15_sample.jpg.

images - is subfolder where my images are stored
15 - is id_paper (new primary autonumber ID)
_sample.jpg - is static and should be added.

I retrieve my data like this:

SELECT
paper.id_paper,
paper.sample_url,
concat('<img src=images/', sample_url, ' ' 'width="66" height="174" />') AS sample
FROM
paper

How do I do this?
 

aceO07

Diamond Member
Nov 6, 2000
4,491
0
76
I don't think there's a way in sql to set a column to default dynamic values for a table. The default values are static, expect for created datetimes. You will need to write code to increment the number when you do inserts.

edit: OR do triggers are KLin posted. I take too long to reply.
 
Jun 14, 2008
55
0
66
I use adobedeveloper toolbox to generate the code with minor editing, I'm not php guru either.

I use this code to add fields:

// Add columns
$ins_paper->setTable("paper");
$ins_paper->addColumn("sample_url", "STRING_TYPE", "POST", "sample_url");
$ins_paper->setPrimaryKey("id_paper", "NUMERIC_TYPE");

This is php for the text box:

<tr>
<td class="KT_th"><label for="sample_url">sample_url:</label></td>
<td><input type="text" name="sample_url" id="sample_url" value="<?php echo KT_escapeAttribute($row_rspaper['sample_url']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("sample_url");?> <?php echo $tNGs->displayFieldError("paper", "sample_url"); ?> </td>
</tr>


What do I need to change?

I think in this line here:
<td><input type="text" name="sample_url" id="sample_url" value="<?php echo KT_escapeAttribute($row_rspaper['sample_url']); ?>" size="32" />
I need to add some php code to get the ID of primary key and my static text too, but how?
 
Jun 14, 2008
55
0
66
I changed this:

<tr>
<td class="KT_th"><label for="sample_url">sample_url:</label></td>
<td><input type="text" name="sample_url" id="sample_url" value="<?php echo KT_escapeAttribute($row_rspaper['sample_url']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("sample_url");?> <?php echo $tNGs->displayFieldError("paper", "sample_url"); ?> </td>
</tr>

To this:

<input type="hidden" name="sample_url" id="sample_url" value="images/<?php echo KT_escapeAttribute($row_rspaper['id_paper']); ?>_sample.jpg" />

But I have a problem:

images/_sample.jpg

The id is not added. The code: <?php echo KT_escapeAttribute($row_rspaper['id_paper']); ?>
does not pass the id.

The field "id_paper" in this code <?php echo KT_escapeAttribute($row_rspaper['id_paper']); ?> is not a text box field on the page. It is primary key incremented by mySQL. So the code can't find a field named "id_paper" and value is not entered. I could be worng.

But somehow the page assigns the correct id to my slave records on second table? (pass the primary key as foreign key to second table) Can't I use this to add a prefix to my "_sample.jpg."? But I don't know how to get this information.

I designed the page using dreamweaver developer toolbox "insert into two pages wizard" and customized it like shown here:

http://209.85.129.132/search?q...=3&hl=lt&ct=clnk&gl=lt