I'm getting paid to do this, and I'm in TROUBLE PLEASE HELP!
Posted: Tue Jun 17, 2003 3:34 am
I need to take data from SQL tables and organize them. Basically, I search for a match between to tables, and then I put one under the table of another. It is putting customers in the array of the person who served the customer. Array jack should be like:
Jack Smith
- Jenny
- Bob
- etc.
Assume my SQL queries are correct. What is wrong with this? It displays nothing.
(Admin Edit Note: We put the PHP BBCode tag in there for a reason. Please be kind and use it.)
Jack Smith
- Jenny
- Bob
- etc.
Assume my SQL queries are correct. What is wrong with this? It displays nothing.
Code: Select all
<?php
session_start();
require("checksession.inc");
require("classoperations.inc");
###########
// Make sure session is valid
$seschecker = new SessionClass();
$seschecker->CheckStatus();
// Finished
###########
$loginobject = new sqlconnect();
?>
<html>
<head>
<title>Results</title>
</head>
<body>
<img src="nav_db_r1_c1.gif"><br><br>
<a href="login.php">Click to return</a>
<br><br>
<table>
<?php
// Find the current user's ClientNameID by comparing
// Their session value with the database
// Thx to DevNet for this!
$result = mysql_query("SELECT * FROM ClientLogin WHERE Username = '$valid_user'");
while ($info = mysql_fetch_array($result)) {
$id = $info['ClientNameID'];
}
// Now $id should hold their ClientNameID record
// Find number of rows
$result = mysql_query("SELECT * FROM CustomerEntry
WHERE ClientNameID = $id");
$num_rows = mysql_num_rows($result);
######################################################
## FORMAT FOR WHILE LOOP ##
######################################################
## $x = 1; ##
## $num_rows++; ##
## ##
## while ( $x < $num_rows ) { ##
## ... do stuff ##
## ##
## $x++; ##
## } ##
######################################################
$x = 34;
$num_rows++;
while ( $x < $num_rows ) {
// $x starts at 34 (the first row) and ends at lets say 37
// which will be the last row
$result = mysql_query("SELECT * FROM CustomerEntry
WHERE CustomerEntryID = $x");
while ($info = mysql_fetch_array($result)) {
$ClientSalesID = $info['ClientSalesID'];
$CFName = $info['FName'];
$CLName = $info['LName'];
}
// Has data, now compare to other table
$result = mysql_query("SELECT * FROM ClientSales
WHERE ClientSalesID = $ClientSalesID");
while ($info = mysql_fetch_array($result)) {
// We have a match. We must add it to a multi-dimensional
// array with the opening as the salespersons name
// Now we grab the selected FName and LName for the array
$queryname = mysql_query("SELECT SalesFName, SalesLName
FROM ClientSales
WHERE ClientSalesID = $ClientSalesID");
while ($info = mysql_fetch_array($queryname)) {
$FName = $info['SalesFName'];
$LName = $info['SalesLName'];
}
// Format data
$arrayname = $FName." ".$LName;
$cname = $CFName." ".$CLName;
// Insert
$arrayname[] = $cname;
}
// Create an array to hold all the arrays [OMG!!!!!]
$totalusers[] = $arrayname;
$x++;
}
// Now this script has been ran. All the matches have been paired up. They
// have been put in their own little array which is owned by the salesperson.
// Then, that array name is added to the ultimate array list. Now it is time
// to take the ultimate array list, loop through it to get each array in the
// array list, and then loops through THAT array to get to our data. Basically
// it is arrays without them being inside themselves
// Count the size of the array
// Which should be the number of rows
$countofarray = count($totalusers);
foreach ( $totalusers as $val ) {
// $val contains the array name
// Count size of $val
$countofval = count($val);
print "<tr rowspan=$countofval>";
print "<td>$val</td>";
foreach ( $val as $val2 ) {
print "<td>$val2</td>";
print "</tr><tr>";
}
print "</tr>";
}
?>
</table>