Jump to content

Recommended Posts

Here's what I am trying to do:

 

If you do a while or for loop, is possible to create a variable for individual values?

For example, if I employed a loop to pull out all the cities in an address table, is it then possible to take the result and then be able to create something like $atlanta or $macon or $augusta.

 

From my limited experience I can get the loop to output everything but all I know is to echo those results. My goal is to use each variable for math in a different table cells. Currently all I can accomplish is putting them all in one cell b/c the echo is doesn't allow me to put <table>'s, <tr>'s and <td>'s between results.

Link to comment
https://forums.phpfreaks.com/topic/167650-question-about-loop-results/
Share on other sites

This achieves what I want but in a really inefficient way.

 

$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
or die('Error connecting to MySQL server'); 

$query1 = "SELECT * FROM whitealbumreg.lps";
  $result1 = mysqli_query($dbc, $query1)
    or die('Error querying database.');
    
$query2 = "SELECT * FROM whitealbumreg.lps WHERE lp_origin='uk'";
  $result2 = mysqli_query($dbc, $query2)
    or die('Error querying database.');
    
$query3 = "SELECT * FROM whitealbumreg.lps WHERE lp_origin='us'";
  $result3 = mysqli_query($dbc, $query3)
    or die('Error querying database.');
    
$query4 = "SELECT * FROM whitealbumreg.members WHERE member_gender='m'";
  $result4 = mysqli_query($dbc, $query4)
    or die('Error querying database.');
    
$query5 = "SELECT * FROM whitealbumreg.members WHERE member_gender='f'";
  $result5 = mysqli_query($dbc, $query5)
    or die('Error querying database.');

$query6 = "SELECT * FROM whitealbumreg.members";
  $result6 = mysqli_query($dbc, $query6)
    or die('Error querying database.');
    
$query7 = "SELECT * FROM whitealbumreg.lps WHERE lp_load='side'";
  $result7 = mysqli_query($dbc, $query7)
    or die('Error querying database.');
    
$query8 = "SELECT * FROM whitealbumreg.lps WHERE lp_load='top'";
  $result8 = mysqli_query($dbc, $query8)
    or die('Error querying database.');
    
$query9 = "SELECT * FROM whitealbumreg.lps WHERE lp_spine='thin'";
  $result9 = mysqli_query($dbc, $query9)
    or die('Error querying database.');

$query10 = "SELECT * FROM whitealbumreg.lps WHERE lp_spine='thick'";
  $result10 = mysqli_query($dbc, $query10)
    or die('Error querying database.');
    
$query11 = "SELECT * FROM whitealbumreg.lps WHERE lp_emi='yes'";
  $result11 = mysqli_query($dbc, $query11)
    or die('Error querying database.');
    
$query12 = "SELECT * FROM whitealbumreg.lps WHERE lp_emi='no'";
  $result12 = mysqli_query($dbc, $query12)
    or die('Error querying database.');
    
$query13 = "SELECT * FROM whitealbumreg.lps WHERE lp_audio='mono'";
  $result13 = mysqli_query($dbc, $query13)
    or die('Error querying database.');
    
$query14 = "SELECT * FROM whitealbumreg.lps WHERE lp_audio='stereo'";
  $result14 = mysqli_query($dbc, $query14)
    or die('Error querying database.');
    
$query15 = "SELECT * FROM whitealbumreg.lps WHERE lp_label='domestic'";
  $result15 = mysqli_query($dbc, $query15)
    or die('Error querying database.');
    
$query16 = "SELECT * FROM whitealbumreg.lps WHERE lp_label='export'";
  $result16 = mysqli_query($dbc, $query16)
    or die('Error querying database.');
    
$query17 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style8'";
  $result17 = mysqli_query($dbc, $query17)
    or die('Error querying database.');
    
$query18 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style9'";
  $result18 = mysqli_query($dbc, $query18)
    or die('Error querying database.');

$query19 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style1'";
  $result19 = mysqli_query($dbc, $query19)
    or die('Error querying database.');
    
$query20 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style2'";
  $result20 = mysqli_query($dbc, $query20)
    or die('Error querying database.');

$query21 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style3'";
  $result21 = mysqli_query($dbc, $query21)
    or die('Error querying database.');

$query22 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style4'";
  $result22 = mysqli_query($dbc, $query22)
    or die('Error querying database.');

$query23 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style5'";
  $result23 = mysqli_query($dbc, $query23)
    or die('Error querying database.');

$query24 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style6'";
  $result24 = mysqli_query($dbc, $query24)
    or die('Error querying database.');

$query25 = "SELECT * FROM whitealbumreg.lps WHERE lp_style='style7'";
  $result25 = mysqli_query($dbc, $query25)
    or die('Error querying database.');
    
$query26 = "SELECT * FROM whitealbumreg.lps WHERE lp_factory='pa'";
  $result26 = mysqli_query($dbc, $query26)
    or die('Error querying database.');

$query27 = "SELECT * FROM whitealbumreg.lps WHERE lp_factory='ca'";
  $result27 = mysqli_query($dbc, $query27)
    or die('Error querying database.');
    
$query28 = "SELECT * FROM whitealbumreg.lps WHERE lp_factory='il'";
  $result28 = mysqli_query($dbc, $query28)
    or die('Error querying database.');
    
$query29 = "SELECT * FROM whitealbumreg.lps WHERE lp_factory='va'";
  $result29 = mysqli_query($dbc, $query29)
    or die('Error querying database.');
    
    
    

$query31 = "SELECT * FROM whitealbumreg.lps WHERE lp_banded='yes'";
  $result31 = mysqli_query($dbc, $query31)
    or die('Error querying database.');
    
$query32 = "SELECT * FROM whitealbumreg.lps WHERE lp_banded='no'";
  $result32 = mysqli_query($dbc, $query32)
    or die('Error querying database.');

$query33 = "SELECT * FROM whitealbumreg.lps WHERE lp_side1='first'";
  $result33 = mysqli_query($dbc, $query33)
    or die('Error querying database.');

$query34 = "SELECT * FROM whitealbumreg.lps WHERE lp_side1='second'";
  $result34 = mysqli_query($dbc, $query34)
    or die('Error querying database.');

$query35 = "SELECT * FROM whitealbumreg.lps WHERE lp_audio='mono' AND lp_style='style8'";
  $result35 = mysqli_query($dbc, $query35)
    or die('Error querying database.');
    
$query36 = "SELECT * FROM whitealbumreg.lps WHERE lp_audio='stereo' AND lp_style='style8'";
  $result36 = mysqli_query($dbc, $query36)
    or die('Error querying database.');

$query37 = "SELECT * FROM whitealbumreg.lps WHERE lp_audio='mono' AND lp_style='style9'";
  $result37 = mysqli_query($dbc, $query37)
    or die('Error querying database.');
    
$query38 = "SELECT * FROM whitealbumreg.lps WHERE lp_audio='stereo' AND lp_style='style9'";
  $result38 = mysqli_query($dbc, $query38)
    or die('Error querying database.');
    
$query39 = "SELECT * FROM whitealbumreg.lps WHERE lp_side4='first'";
  $result39 = mysqli_query($dbc, $query39)
    or die('Error querying database.');

$query40 = "SELECT * FROM whitealbumreg.lps WHERE lp_side4='second'";
  $result40 = mysqli_query($dbc, $query40)
    or die('Error querying database.');
    

    $lps = mysqli_num_rows($result1);
    $uk = mysqli_num_rows($result2);
    $us = mysqli_num_rows($result3);
    $m = mysqli_num_rows($result4);
    $f = mysqli_num_rows($result5);
    $members = mysqli_num_rows($result6);
    $side = mysqli_num_rows($result7);
    $top = mysqli_num_rows($result8);
    $thin = mysqli_num_rows($result9);
    $thick = mysqli_num_rows($result10);
    $emi_yes = mysqli_num_rows($result11);
    $emi_no = mysqli_num_rows($result12);
    $mono = mysqli_num_rows($result13);
    $stereo = mysqli_num_rows($result14);
    $domestic = mysqli_num_rows($result15);
    $export = mysqli_num_rows($result16);
    $style8 = mysqli_num_rows($result17);
    $style9 = mysqli_num_rows($result18);
$style1 = mysqli_num_rows($result19);
    $style2 = mysqli_num_rows($result20);
    $style3 = mysqli_num_rows($result21);
    $style4 = mysqli_num_rows($result22);
    $style5 = mysqli_num_rows($result23);
    $style6 = mysqli_num_rows($result24);
    $style7 = mysqli_num_rows($result25);
    $pa = mysqli_num_rows($result26);
    $ca = mysqli_num_rows($result27);
    $il = mysqli_num_rows($result28);
    $va = mysqli_num_rows($result29);
    
    $banded_yes = mysqli_num_rows($result31);
    $banded_no = mysqli_num_rows($result32);
    $first1 = mysqli_num_rows($result33);
    $second1 = mysqli_num_rows($result34);
    $mono_style8 = mysqli_num_rows($result35);
    $stereo_style8 = mysqli_num_rows($result36);
    $mono_style9 = mysqli_num_rows($result37);
    $stereo_style9 = mysqli_num_rows($result38);
    $first4 = mysqli_num_rows($result39);
    $second4 = mysqli_num_rows($result40);

    
echo "<br />\n";  
echo "<table width='616' border='0' cellpadding='2'>\n";

// New Row
echo "<tr>\n";
echo "  <td>\n";
echo "   <table width='607' border='1' cellpadding='2'>\n";
echo "     <tr>\n";
echo "       <td><font size='4'>Registered copies of the Beatles White Album</font></td>\n";
echo "       <td class='center' width='30'>Total</td>\n";
echo "       <td class='center' width='35'>Percent</td>\n";
echo "       <td class='center' width='120'>Percent of Total Release*</td>\n";
echo "     </tr>\n";
echo "		<tr>\n";
echo "       <td>UK</td>\n";
echo "       <td class='center'>" . $uk . "</td>\n";
echo "       <td class='center'>" . round(($uk / $lps) * 100) . "%" . "</td>\n";
echo "       <td class='center'>" . (($uk / 100000) * 100) . "%" . "</td>\n";
echo "     </tr>\n";
echo "      <tr>\n";
echo "        <td>US</td>\n";
echo "        <td class='center'>" . $us . "</td>\n";
echo "        <td class='center'>" . round(($us / $lps) * 100) . "%" . "</td>\n";
echo "        <td class='center'>" . (($us / 3200000) * 100) . "%" . "</td>\n";
echo "      </tr>\n";
echo "   </table>\n";
echo "   <table width='607'>\n";
echo "		<tr>\n";
echo "		  <td class='right'>* - based on 3,200,000 US and 100,000 UK copies</td>\n";
echo " 		</tr>\n";
echo "   </table>\n";
echo "  </td>\n";
echo "</tr></table>\n";

echo "<table width='600' border='0' cellpadding='2'>\n";

//new row
echo " <tr><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: Side vs. Top Load</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Side</td>\n";
echo "  <td class='center'>" . $side . "</td>\n";
echo "  <td class='center'>" . round(($side / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Top</td>\n";
echo "  <td class='center'>" . $top . "</td>\n";
echo "  <td class='center'>" . round(($top / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: Thin vs. Thick Spine</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Thin</td>\n";
echo "  <td class='center'>" . $thin . "</td>\n";
echo "  <td class='center'>" . round(($thin / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Thick</td>\n";
echo "  <td class='center'>" . $thick . "</td>\n";
echo "  <td class='center'>" . round(($thick / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table></td></tr>\n";

//new row
echo "<tr><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: \"An EMI recording\"</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>With</td>\n";
echo "  <td class='center'>" . $emi_yes . "</td>\n";
echo "  <td class='center'>" . round(($emi_yes / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Without</td>\n";
echo "  <td class='center'>" . $emi_no . "</td>\n";
echo "  <td class='center'>" . round(($emi_no / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: Mono vs. Stereo</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Mono</td>\n";
echo "  <td class='center'>" . $mono . "</td>\n";
echo "  <td class='center'>" . round(($mono / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Stereo</td>\n";
echo "  <td class='center'>" . $stereo . "</td>\n";
echo "  <td class='center'>" . round(($stereo / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";
echo " </td></tr>\n";

// new row
echo " <tr><td>\n";
echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: Domestic vs. Export Label</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Domestic</td>\n";
echo "  <td class='center'>" . $domestic . "</td>\n";
echo "  <td class='center'>" . round(($domestic / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Export</td>\n";
echo "  <td class='center'>" . $export . "</td>\n";
echo "  <td class='center'>" . round(($export / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK Number Style</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/ukNumberStyle1.jpg' width='100' height='20' alt='UK Number Style 1' /></td>\n";
echo "  <td class='center'>" . $style8 . "</td>\n";
echo "  <td class='center'>" . round(($style8 / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/ukNumberStyle2.jpg' width='100' height='20' alt='UK Number Style 2' /></td>\n";
echo "  <td class='center'>" . $style9 . "</td>\n";
echo "  <td class='center'>" . round(($style9 / $uk) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table></td></tr>\n";

//new row
echo "<tr><td>\n";
echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>US Number Style</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle1.jpg' width='100' height='20' alt='US Number Style 1' /></td>\n";
echo "  <td class='center'>" . $style1 . "</td>\n";
echo "  <td class='center'>" . round(($style1 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle2.jpg' width='100' height='20' alt='US Number Style 2' /></td>\n";
echo "  <td class='center'>" . $style2 . "</td>\n";
echo "  <td class='center'>" . round(($style2 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle3.jpg' width='100' height='20' alt='US Number Style 3' /></td>\n";
echo "  <td class='center'>" . $style3 . "</td>\n";
echo "  <td class='center'>" . round(($style3 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle4.jpg' width='100' height='20' alt='US Number Style 4' /></td>\n";
echo "  <td class='center'>" . $style4 . "</td>\n";
echo "  <td class='center'>" . round(($style4 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle5.jpg' width='100' height='20' alt='US Number Style 5' /></td>\n";
echo "  <td class='center'>" . $style5 . "</td>\n";
echo "  <td class='center'>" . round(($style5 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle6.jpg' width='100' height='20' alt='US Number Style 6' /></td>\n";
echo "  <td class='center'>" . $style6 . "</td>\n";
echo "  <td class='center'>" . round(($style6 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td><img src='/images/usNumberStyle7.jpg' width='100' height='20' alt='US Number Style 7' /></td>\n";
echo "  <td class='center'>" . $style7 . "</td>\n";
echo "  <td class='center'>" . round(($style7 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";

echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>US Pressing Plants</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Scranton, PA</td>\n";
echo "  <td class='center'>" . $pa . "</td>\n";
echo "  <td class='center'>" . round(($pa / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Los Angeles, CA</td>\n";
echo "  <td class='center'>" . $ca . "</td>\n";
echo "  <td class='center'>" . round(($ca / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Jacksonville, IL</td>\n";
echo "  <td class='center'>" . $il . "</td>\n";
echo "  <td class='center'>" . round(($il / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Winchester, VA</td>\n";
echo "  <td class='center'>" . $va . "</td>\n";
echo "  <td class='center'>" . round(($va / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";
    
echo " </td></tr>\n";

//new row
echo " <tr><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>US: Banded Copies</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Banded</td>\n";
echo "  <td class='center'>" . $banded_yes . "</td>\n";
echo "  <td class='center'>" . round(($banded_yes / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Not Banded</td>\n";
echo "  <td class='center'>" . $banded_no . "</td>\n";
echo "  <td class='center'>" . round(($banded_no / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>Member by Gender</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Male</td>\n";
echo "  <td class='center'>" . $m . "</td>\n";
echo "  <td class='center'>" . round(($m / $members) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Female</td>\n";
echo "  <td class='center'>" . $f . "</td>\n";
echo "  <td class='center'>" . round(($f / $members) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";
    
echo " </td></tr></table>\n";

echo "<table width='600' border='0' cellpadding='2'>\n";

//new row
echo "<tr><td>\n";
echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>US: Original vs. Corrected Side 1</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Original</td>\n";
echo "  <td class='center'>" . $first1 . "</td>\n";
echo "  <td class='center'>" . round(($first1 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Corrected</td>\n";
echo "  <td class='center'>" . $second1 . "</td>\n";
echo "  <td class='center'>" . round(($second1 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>US: Original vs. Corrected Side 4</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Original</td>\n";
echo "  <td class='center'>" . $first4 . "</td>\n";
echo "  <td class='center'>" . round(($first4 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Corrected</td>\n";
echo "  <td class='center'>" . $second4 . "</td>\n";
echo "  <td class='center'>" . round(($second4 / $us) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table></td></tr>\n";


//new row
echo "<tr><td>\n";
echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: 7-digit stats</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Mono</td>\n";
echo "  <td class='center'>" . ($style8 - $stereo_style8) . "</td>\n";
echo "  <td class='center'>" . round(($mono_style8 / $style8) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Stereo</td>\n";
echo "  <td class='center'>" . ($style8 - $mono_style8) . "</td>\n";
echo "  <td class='center'>" . round(($stereo_style8 / $style8) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";

//new column
echo "</td><td>\n";

echo "<table width='300' border='1' cellpadding='2'>\n";
echo " <tr>\n";
echo "  <td>UK: 6-digit stats</td>\n";
echo "  <td class='center' width='30'>Total</td>\n";
echo "  <td class='center' width='35'>Percent</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Mono</td>\n";
echo "  <td class='center'>" . ($style9 - $stereo_style9) . "</td>\n";
echo "  <td class='center'>" . round(($mono_style9 / $style9) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo "  <td>Stereo</td>\n";
echo "  <td class='center'>" . ($style9 - $mono_style9) . "</td>\n";
echo "  <td class='center'>" . round(($stereo_style9 / $style9) * 100) . "%" . "</td>\n";
echo " </tr>\n";
echo "</table>\n";
    
echo " </td></tr>\n";

//end table with
echo "</table>\n";  

I'd say instead of improving your php you could refine your sql to lower the number of queries needed to get these results. Not knowing the natuer of your db structure I may br wrong, but there is no way on hell you should need to query a single table 40 times to get you're desired results.

 

It looks like all you're doing is counting the certain results. This can be simplified and sped up greatly with better sql!

You have not actually shown what you are trying to change or accomplish with these variables (an example would be nice), but you should not generate a specific list of named variables. That just makes more work because you must now keep track of the actual variables created, which means the code must now be edited every time something changes. You should either use array variables or more simply just output what you want inside of the while loop.

 

One of the main points of using a database is that you retrieve just the data you want in the order that you want it and then you use general purpose code (that does not needed to be edited every time the data changes) to iterate over the results.

Posting your table definitions along with an example of what you are trying to achieve would help too. Seeing the code is nice but reverse engineering 500+ lines of code to 'see" what you have and what you are doing is probably not going to happen.

CREATE TABLE  `whitealbumreg`.`lps` (
`lp_id` MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`fk_member_id` MEDIUMINT NOT NULL ,
`lp_origin` VARCHAR( 3 ) NOT NULL ,
`lp_style`  VARCHAR( 7 ) NOT NULL ,
`lp_number` VARCHAR( 10 ) NOT NULL ,
`lp_load` ENUM(  'top',  'side' ) NOT NULL ,
`lp_spine` ENUM(  'think',  'thin' ) NOT NULL ,
`lp_emi` ENUM(  'yes',  'no' ) NOT NULL ,
`lp_audio` ENUM(  'mono',  'stereo' ) NOT NULL ,
`lp_label` ENUM(  'domestic',  'export' ) NOT NULL ,
`lp_factory` ENUM(  'pa',  'ca',  'il',  'va',  'none' ) NOT NULL ,
`lp_banded` ENUM(  'yes',  'no' ) NOT NULL ,
`lp_side1` ENUM(  'first',  'second' ) NOT NULL ,
`lp_side4` ENUM(  'first',  'second' ) NOT NULL ,
`lp_img` VARCHAR( 64 ) NOT NULL ,
FOREIGN KEY (fk_member_id) REFERENCES members (member_id)
) ENGINE = MYISAM

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.