Looping Rows from MySql to PHP...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nine72
    New Member
    • Oct 2006
    • 21

    Looping Rows from MySql to PHP...

    Hi, first I want to say thanks for the help I received here over a year ago with a perplexing issue that I had. The advise was fantastic and helped a lot.

    Today I have another issues that I can not seam to get past or figure out and hope that the community here will be able to assist me in getting past this next mile stone in my current project.

    Overview…

    8 forms all data being temp store in a mysql db.
    After they have filled in the forms I am generating a very large and complex XML string from the data in the db by doing the following…

    [PHP]<?PHP

    //Open Includes for page information.
    include_once(". ./../gatewayapi/inc_gatewayapi. php");
    include_once(". ./../Connections/conn.php");
    include_once(". ./../db_calls/get_db_var.php" );

    $query = ($xmlVarSet);
    $res = mysql_query($qu ery);
    if($res){
    while($row = mysql_fetch_ass oc($res)){
    foreach($row as $key => $val){
    $_SESSION['db'][$key] = ($val);
    }
    }
    }
    ?>[/PHP]
    This is doing a fantastic job of getting the data an putting it into the named session and filling in the values for my XML String.

    My issue is now that 3 of the forms can be used multiple times so I need to some how take the above and rework it to look at a specific table count the number of rows were there is a unique identifier for the users session and then loop them through a block of my XML Code.
    Example:


    [PHP]<?PHP

    //Open Includes for page information.
    include_once(". ./../gatewayapi/inc_gatewayapi. php");
    include_once(". ./../Connections/jpbdadd.php");
    include_once(". ./../db_calls/get_session.php ");

    // NEED HELP HERE!!
    $query = ($xmlTtVarSet);
    $res = mysql_query($qu ery);
    if(!$res){
    die(mysql_error ());
    }

    $num = mysql_num_rows( $res);

    $i=0;
    while ($i < $num) {

    //code to run
    $xmlString .= "<Kiosks>\n ";
    $xmlString .= "<Kiosks>\n ";
    $xmlString .= "<KiBus>\n" ;

    $xmlString .= "<tt_legal_name >" . $ttLegalName . "</tt_legal_name>\ n";
    $xmlString .= "<tt_dba_na me>" . $ttDbaName . "</tt_dba_name>\n" ;
    $xmlString .= "<device_ty pe>" . "KOS" . "</device_type>\n" ;

    if (ttDynmcDesc != "") {
    $xmlString .= "<dynamic_descr iption>" . $ttDynmcDesc . "</dynamic_descrip tion>\n”; }
    if $ttPosCd != "") {
    $xmlString .= "<pos_code> " . $ttPosCd . “</pos_code>\n";
    }
    if ($ttStandIn != "") {
    $xmlString .= "<standin>" . $ttStandIn . “</standin>\n";
    }
    if ($ttTmZone != "0") {
    $xmlString .= "<time_zone >" . $ttTmZone . “</time_zone>\n";//
    }
    if ($ttDupChk != "") {
    $xmlString .= "<duplicate_che cking>" . $ttDupChk . “</duplicate_check ing>\n";//
    }
    if ($ttChrgDesc != "") {
    $xmlString .= "<charge_descri ption>" . $ttChrgDesc . “</charge_descript ion>\n";
    }
    if ($ttHubFlg != "") {
    $xmlString .= "<hub_flag> " . $ttHubFlg . “</hub_flag>\n";// currently used only for DFW WinHub
    }
    if ($ttAltCityDisc != "") {
    $xmlString .= "<tt_alt_city_d escriptor>" . $ttAltCityDisc . “</tt_alt_city_des criptor>\n";
    }
    $xmlString .= "</KeiBus>\n";
    $xmlString .= "<KiEquipments> \n";
    $xmlString .= "<KiEquipment>\ n";

    if ($ttSerialNo != "") {
    $xmlString .= "<device_serial _no>" . $ttSerialNo . “</device_serial_n o>\n";
    }
    if ($ttDevEsn != "") {
    $xmlString .= "<device_es n>" . $ttDevEsn . “</device_esn>\n";
    }
    if ($ttDevMann != "") {
    $xmlString .= "<device_ma nn>" . $ttDevMann'] ."</device_mann>\n" ;
    }
    if ($ttDevSim != "") {
    $xmlString .= "<device_si m>" . $ttDevSim . “</device_sim>\n";
    }
    if ($ttAddInfo != "") {
    $xmlString .= "<device_additi onal_info>" . $ttAddInfo . “</device_addition al_info>\n";
    }
    if ($ttDevPbx != "") {
    $xmlString .= "<device_pb x>" . $ttDevPbx'] ."</device_pbx>\n";
    }
    $xmlString .= "<device_catego ry>" . "KIOSK" . "</device_category >\n";
    if ($ttDevName != "") {
    $xmlString .= "<device_na me>" . $ttDevName . “</device_name>\n" ;
    }
    if ($ttDevMod != "") {
    $xmlString .= "<device_model> " . $ttDevMod . “</device_model>\n ";
    }
    if ($ttDevAppType != "") {
    $xmlString .= "<device_applic ation>" . $ttDevAppType . “</device_applicat ion>\n";
    }
    if ($ttGateWay != "") {
    $xmlString .= "<device_gatewa y>" . $ttGateWay . “</device_gateway> \n";
    }
    if ($ttDevCommFmt != "") {
    $xmlString .= "<device_comm_f ormat>" . $ttDevCommFmt . “</device_comm_for mat>\n";
    }
    if ($ttDialUp != "") {
    $xmlString .= "<device_dial_u p>" . $ttDialUp . “</device_dial_up> \n";
    }
    $xmlString .= "<device_fl ag>" . "N" . "</device_flag>\n" ;
    $xmlString .= "</KiEquipment>\n" ;
    $xmlString .= "</KiEquipments>\n ";
    $xmlString .= "</Kiosk>\n";
    $xmlString .= "</Kiosks>\n";

    $i++;
    }


    //Print results to page.
    echo "<pre>";
    print_r($xmlStr ing);
    echo "</pre>";

    ?>[/PHP]

    So that’s it, any direction, examples, thoughts, re-work, would be most helpful

    Thanks
    Nine72
  • nine72
    New Member
    • Oct 2006
    • 21

    #2
    actually I got it figured out....

    [PHP]
    $query = ($xmlCtVarSet);
    $result = mysql_query($qu ery);
    if(!$result){
    die(mysql_error ());
    }

    $num = mysql_num_rows( $result);

    $i=0;
    while ($i < $num) {

    $rFirstName = mysql_result($r esult,$i,"rFirs tName");
    $rMiddleI = mysql_result($r esult,$i,"rMidd leI");
    $rLastName = mysql_result($r esult,$i,"rLast Name");
    $rAddress1 = mysql_result($r esult,$i,"rAddr ess1");
    $rAddress2 = mysql_result($r esult,$i,"rAddr ess2");
    $rState = mysql_result($r esult,$i,"rStat e");
    $rCity = mysql_result($r esult,$i,"rCity ");
    $rZip = mysql_result($r esult,$i,"rZip" );
    $rCntryCdI = mysql_result($r esult,$i,"rCntr yCdI");
    $rCustCareNo = mysql_result($r esult,$i,"rCust CareNo");
    $rTelNo = mysql_result($r esult,$i,"rTelN o");
    $rFax = mysql_result($r esult,$i,"rFax" );
    $rEmailId = mysql_result($r esult,$i,"rEmai lId");
    $rDept = mysql_result($r esult,$i,"rDept ");
    $rTitle = mysql_result($r esult,$i,"rTitl e");
    $rMobNo = mysql_result($r esult,$i,"rMobN o");
    $rUrl = mysql_result($r esult,$i,"rUrl" );


    //code to run
    $xmlString .= "<DefaultContac t>\n";
    $xmlString .= "<contact_type> " . "DEFAULT" . "</contact_type>\n ";
    $xmlString .= "<r_first_name> " . $rFirstName . "</r_first_name>\n ";
    if ($rMiddleI != "" ) {
    $xmlString .= "<r_middle_ i>" . $rMiddleI . "</r_middle_i>\n";
    }
    $xmlString .= "<r_last_na me>" . $rLastName . "</r_last_name>\n" ;
    $xmlString .= "<r_address 1>" . $rAddress1 . "</r_address1>\n";
    if ($rAddress2 != "" ) {
    $xmlString .= "<r_address 2>" . $rAddress2 . "</r_address2>\n";
    }
    $xmlString .= "<r_state_c d>" . $rState . "</r_state_cd>\n";
    $xmlString .= "<r_city>" . $rCity . "</r_city>\n";
    $xmlString .= "<r_zip>" . $rZip . "</r_zip>\n";
    if ($rCntryCdI !="") {
    $xmlString .= "<r_cntry_c d>" . $rCntryCdI . "</r_cntry_cd>\n";
    }
    $xmlString .= "<r_customer_ca re_phone>" . $rCustCareNo . "</r_customer_care _phone>\n";
    $xmlString .= "<r_telepho ne>" . $rTelNo . "</r_telephone>\n" ;
    if ($rFax != "" ) {
    $xmlString .= "<r_fax>" . $rFax . "</r_fax>\n";
    } elseif ($rFax == "") {
    $xmlString .= "<r_fax>" . "5555555555 " . "</r_fax>\n";
    }
    $xmlString .= "<r_email_i d>" . $rEmailId . "</r_email_id>\n";
    if ($rDept != "" ) {
    $xmlString .= "<r_department> " . $rDept . "</r_department>\n ";
    }
    if ($rTitle != "" ) {
    $xmlString .= "<r_title>" . $rTitle . "</r_title>\n";
    }
    if ($rMobNo != "" ) {
    $xmlString .= "<r_mobile> " . $rMobNo . "<r_mobile> \n";
    }
    if ($rUrl != "" ) {
    $xmlString .= "<r_url>" . $rUrl . "</r_url>\n";
    }
    $xmlString .= "</DefaultContact> \n";
    $i++;
    }[/PHP]

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, Nine.

      Glad you were able to get it working. Thanks for posting your solution.

      Good luck with your project, and if you need help with anything else, post back anytime (:

      Comment

      Working...