Executing a variable number of queries
Posted: Mon Mar 17, 2003 12:54 am
Hello,
to the site admins: please don't be angry if this post actually belongs to "Databases"
Here's my question: In some part of the Back Office of the PHP / MySQL based cms i'm currently working at, an editor can inscribe names of people which are working at the same project. After choosing how many (1 - xxxx) people he wants to inscribe, a second form opens with the following code:
Therewith, $auth_num rows with 3 input fields (Last name, first name, Initials) in each row are produced, $i is used to specify each row and the input fields within it. $p04 is an internal project number and not relevant for the following actions.
After the editor has created and filled out let's say 5 rows, the form is send to a validation step, in which a MySQL query should extract data corresponding to the names entered before from three different tables in the staff database:
This query is working fine but: it must be run for each row (Last-First-Initial) produced in the step before, respectively with the exact field names $i produced (in this case: $auth_last_0 [...] $auth_ini_4), so that the data can be separated and processed. If I would know the exact number of rows in advance - no problem. But the number can be 1 as well as 33, and the field numbers are not only important for data separtating and processing but also to flag the most important (the last) and the second most important (the first) person in this set. Any ideas?
Thanx in advance.
to the site admins: please don't be angry if this post actually belongs to "Databases"
Here's my question: In some part of the Back Office of the PHP / MySQL based cms i'm currently working at, an editor can inscribe names of people which are working at the same project. After choosing how many (1 - xxxx) people he wants to inscribe, a second form opens with the following code:
Code: Select all
<?php
if (($p04=='01') || ($p04=='03')) {
for ($i=0; $i < $auth_num; $i++) {
echo "<B>$i.</B> <INPUT TYPE=text NAME="auth_last_$i" VALUE="" SIZE=25> <INPUT TYPE=text NAME="auth_first_$i" VALUE="" SIZE=10> <INPUT TYPE=text NAME="auth_ini_$i" VALUE="" SIZE=2>\n";
echo "<BR>";}}
else {}
?>After the editor has created and filled out let's say 5 rows, the form is send to a validation step, in which a MySQL query should extract data corresponding to the names entered before from three different tables in the staff database:
Code: Select all
<?php
require_once('../../include/databases/db_connect.php3');
$dbName = "DBstaff";
MYSQL_CONNECT($hostname,$username,$password) OR DIE("Database connection failed.");
@mysql_select_db("$dbName") or die("Database not found.");
$query = "SELECT staff.s01, staff.s03, staff.s04, staff_departments.dep_s03, staff_departments.dep_s05, staff_departments.dep_s06, staff_groups.grp_s03, staff_groups.grp_s04, staff_groups.grp_s05, staff_groups.grp_s06 from staff LEFT JOIN staff_departments on staff.s03 = staff_departments.dep_s03 LEFT JOIN staff_groups on staff_departments.dep_s03 = staff_groups.grp_s03 WHERE staff.s05 = '$auth_last_xx' AND staff.s06 = '$auth_first_xx' AND staff.s07 = '$auth_ini_xx'";
$erg = MYSQL_QUERY($query);
$numrows = MYSQL_NUM_ROWS($erg);
?>Thanx in advance.