Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts

    [SOLVED] While / For Loop - Extract data

    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?

    PHP Code:
    //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",";

      } 
    Last edited by facets; 09-24-2005 at 01:09 PM.

  • #2
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:
    $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]},";


  • #3
    New Coder
    Join Date
    Jul 2005
    Posts
    62
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I want to extract all data (rows) from the SELECT statement.
    I've set up the variables like so :

    PHP Code:
    $query_data mysql_fetch_array($query); 
          
    $summaryId $query_data['summaryId'];
    $paperCategoryId $query_data['paperCategoryId'];
    $colloPaperName $query_data['colloPaperName'];
    $manufacturerName $query_data['manufacturerName'];
    etc.etc.. 

  • #4
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    PHP Code:

    $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.




  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •