I want to generate the deptno automatically.
Im using backend as mysql which allows auto-incrementation only for an integer,
not supports for varchar. So any code to do it?
Thank you.
Code blocks are created by indenting at least 4 spaces
... and can span multiple lines

<?php

$con = mysql_connect('localhost','root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); }

mysql_select_db("stu", $con); $result = mysql_query("SELECT * FROM student"); while($row = mysql_fetch_array($result)) { echo $row['deptno'] . " " .$row['sname']

. " " .$row['age'];

echo "
";

}mysql_close($con); ?>

Code blocks are created by indenting at least 4 spaces
... and can span multiple lines
Member Avatar for diafol

Why are you including this random piece of SQL on student? The deptno will be created in the depts table?

What exactly are you asking? How to perform an INSERT query?

how can i have an auto increment of department number which start with 10pit01, so on..

how can i have an auto increment of department number which start with 10pit01, so on..

how can i have an auto increment of department number which start with 10pit01, so on..

Member Avatar for diafol

Why do you need to do this? Why not just have an autoincrement (integer)? If you really have to have this prefix (10pit[0]) you can attach it via SQL or php. Are you actually going to display this code? If not, I fail to see the need to use it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.