...

View Full Version : [SOLVED] While / For Loop - Extract data



facets
09-24-2005, 06:48 AM
Hey Gang,

Having some troubles with this loop. Any ideas on how I could ensure every record from the DB was outputted? Do I need a while loop instead?



//SQL Extract
$query = mysql_query("SELECT *, aupapercategory.paperCategory FROM ausapapersummary
LEFT JOIN aupapercategory ON ausapapersummary.paperCategoryId = aupapercategory.papercategoryId
LEFT JOIN austock ON ausapapersummary.stockId = austock.StockId
LEFT JOIN auadhesive ON ausapapersummary.adhesiveId = auadhesive.adhesiveId
LEFT JOIN auliner ON ausapapersummary.linerId = auliner.linerId
LEFT JOIN ausupplier ON ausapapersummary.supplierId = ausupplier.supplierId
LEFT JOIN ausuitability ON ausapapersummary.suitabilityFoil = ausuitability.suitabilityId
LEFT JOIN admins ON ausapapersummary.ausapaperUserId = admins.id WHERE 1=1");

// For loop
$csvOutput = array("$colloPaperName", "$paperCategory", "$manufacturerName", "$supplier", "$availability", "$features", "$limitations", "$productExamples", "$suitabilityFoil", "$suitabilityYellowLight", "$suitabilityLabel", "$suitabilityOpacity", "$suitabilityBronze", "$suitabilityScreen", "$suitabilityIceBucket", "$stockDescription", "$basisWeight", "$caliper", "$wetTensileStrenghtCD", "$wetTensileStrenghtMD", "$dryTensileStrengthCD", "$dryTensileStrengthMD", "$opacity", "$gloss", "$moistureContent", "$brightness", "$relativeHumitity", "$absorbtion", "$smoothness", "$tearStrengthCD", "$tearStrengthMD", "$burstStrength", "$pH", "$adhesiveDescription", "$thickness", "$initialTack", "$ballTack", "$peelAdhesion180", "$peelAdhesion90", "$shear", "$shelfLife", "$minApplicationTemp", "$serviceMin", "$serviceMax", "$linerDescription", "$grammage", "$caliper", "$strengthCD", "$strengthMD", "$translucency", "$shear", "$humidity", "$smoothnessWS", "$smoothnessFS", "$releaseForceLow", "$releaseForceHigh");

for($x = 0; $x<count($csvOutput); $x++) {

echo $csvOutput[$x];echo",";

}

missing-score
09-24-2005, 07:19 AM
Well, the variables you are using haven't actually been set... For get rows you selected you need to use mysql_fetch_row or mysql_fetch_assoc. Im not sure exactly what you want to do, if you just want to display one row or many, but I will assume 1:



$query = mysql_query("SELECT *, aupapercategory.paperCategory FROM ausapapersummary
LEFT JOIN aupapercategory ON ausapapersummary.paperCategoryId = aupapercategory.papercategoryId
LEFT JOIN austock ON ausapapersummary.stockId = austock.StockId
LEFT JOIN auadhesive ON ausapapersummary.adhesiveId = auadhesive.adhesiveId
LEFT JOIN auliner ON ausapapersummary.linerId = auliner.linerId
LEFT JOIN ausupplier ON ausapapersummary.supplierId = ausupplier.supplierId
LEFT JOIN ausuitability ON ausapapersummary.suitabilityFoil = ausuitability.suitabilityId
LEFT JOIN admins ON ausapapersummary.ausapaperUserId = admins.id WHERE 1=1");

$data = mysql_fetch_row($query);
$datacount = count($data);

for($i=0;$datacount;$i++){
echo "{$data[$i]},";
}

facets
09-24-2005, 07:47 AM
I want to extract all data (rows) from the SELECT statement.
I've set up the variables like so :



$query_data = mysql_fetch_array($query);

$summaryId = $query_data['summaryId'];
$paperCategoryId = $query_data['paperCategoryId'];
$colloPaperName = $query_data['colloPaperName'];
$manufacturerName = $query_data['manufacturerName'];
etc.etc..

missing-score
09-24-2005, 07:50 AM
Firstly, dont use MySQL fetch array unless you are planning on using the numeric AND associative keys... Use mysql_fetch_assoc() instead.

Ok, well run that through a while loop like this:




$result = mysql_query("...");

while($query_data = mysql_fetch_assoc($result)){

// ... set vars, do whatever it is you want to do, it will do this
// for every row returned.

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum