Jump to content

[SOLVED] Can someone help me please troubleshoot this code.


DeepakJ

Recommended Posts

I spent like 10 hrs trying to fix this code.

<?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 invoiceid";
$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><center>";
}
echo "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++;
echo $pid."</center></td></tr><tr><td></td><td><center>";
}
}
echo "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>";
}

?>

 

It is supposed to print out the data from the database onto a table.

What happens though is that it complete skips the productid code and repeats the customerid info many times. I'm not sure how to fix this. Help would be greatly appreciated.

I'm not sure how your information is setup, but you may be able to make this a bit easier by fetching multiple requests at once, and printing them out together, you have a massive loop with multiple inbedded loops, this is bound to be confusing.. especially if you will need to go back at some point and modify your code. Generally the best answer is a simple one, try a new approach I think.

 

http://www.samspublishing.com/articles/article.asp?p=377068&seqNum=9&rl=1

 

 

I forgot to mention that customerid is NOT the key of the first table. The tables are divided into two. Productid which has productid and invoicenum as well as invoiceid which has customerid, invoicenum, numoflicenses. I am looking for a way to display ALL the information in the linked tables in an organzed fashion such as below(html code for form)

 

<html><head><title>AlibreCam Verification System</title></head>
<center><TABLE border=0 cellpadding=3>
<tr>
<td><center>Customer ID:</center></td>
<td><center>[email protected]</center></td>
</tr>
<tr>
<td><center>Invoice Number:</center></td>
<td><center>######</center></td>
</tr>
<tr>
<td><center>Product ID:</center></td>
<td><center>######</center></td>
</tr>
<tr>
<td></td>
<td><center>######</center></td>
</tr>

<tr>
<td></td>
<td><center>######</center></td>
</tr>

<tr>
<td></td>
<td><center>######</center></td>
</tr>
<tr>
<td><center># of copies bought:</center></td>
<td><center>######</center></td>
</tr>
<tr>
<td><center># of licenses remaining:</center></td>
<td><center>######</center></td>
</tr>
</table><br>


</html>

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.