Jump to content

[SOLVED] Code problem.


DeepakJ

Recommended Posts

Ok I got my code down to this

 

<?php
$hostname = "localhost";
$username = "root";
$password = "98989lol";
$dbname = "licensinginformation";


mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");
$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");
$query = "SELECT customerid FROM customerid";
$Result = mysql_query($query);
echo "<html><head><title>AlibreCam Verification System</title></head>";
while($row = mysql_fetch_array($Result)){
$alpha = $row['customerid'];
echo "<center><TABLE border=0 cellpadding=3><tr><td><center>Customer ID:</center></td>
<td><center>".$alpha."</center></td></tr><tr><td><center>Invoice Number:</center></td>
<td><center>";
$query2 = "SELECT invoicenum FROM invoiceid WHERE customerid='$alpha'";
$aResult = mysql_query($query2);
while($row1=mysql_fetch_array($aResult)){
$invoicenum[]=$row1['invoicenum'];
echo $row1['invoicenum']."</center></td></tr><tr><td></td><td><center>";
}
echo "</center></td></tr><tr><td><center>Product ID:</center></td>	<td><center>";
$counter = 0;
foreach($invoicenum as $num => $value){
$query3 = "SELECT * FROM productid WHERE invoicenum = '$value'";
$bResult = mysql_query($query3);
while($row2=mysql_fetch_array($bResult)){
$pid = $row2['productid'];
$counter = $counter + 1;
echo $pid."</center></td></tr><tr><td></td><td><center>";
}
}
echo "</center></td></tr><tr><td><center>Number of copies bought:</center></td>
<td><center>";
$query3 = "SELECT * FROM invoiceid WHERE customerid = '$alpha'";
$cResult = mysql_query($query3);
$numoflicenses=0;
while($row3=mysql_fetch_array($cResult))(
$numoflicenses = $numoflicenses + $row3['numoflicenses']
);
echo $numoflicenses."</center></td></tr><tr><td><center># of licenses remaining:</center></td>
<td><center>".$counter."</center></td></tr></table><br>";
}

?>

 

This code works ok except the productids arent' being extracted based on invoicenum. It basically copies the previous customerids productid instead. The same happens with number of licenses remaining.

Link to comment
https://forums.phpfreaks.com/topic/62510-solved-code-problem/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.