By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,722 Members | 1,874 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,722 IT Pros & Developers. It's quick & easy.

Looping Rows from MySql to PHP...

nine72
P: 21
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($query);
if($res){
while($row = mysql_fetch_assoc($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($query);
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_name>" . $ttDbaName . "</tt_dba_name>\n";
$xmlString .= "<device_type>" . "KOS" . "</device_type>\n";

if (ttDynmcDesc != "") {
$xmlString .= "<dynamic_description>" . $ttDynmcDesc . "</dynamic_description>\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_checking>" . $ttDupChk . “</duplicate_checking>\n";//
}
if ($ttChrgDesc != "") {
$xmlString .= "<charge_description>" . $ttChrgDesc . “</charge_description>\n";
}
if ($ttHubFlg != "") {
$xmlString .= "<hub_flag>" . $ttHubFlg . “</hub_flag>\n";// currently used only for DFW WinHub
}
if ($ttAltCityDisc != "") {
$xmlString .= "<tt_alt_city_descriptor>" . $ttAltCityDisc . “</tt_alt_city_descriptor>\n";
}
$xmlString .= "</KeiBus>\n";
$xmlString .= "<KiEquipments>\n";
$xmlString .= "<KiEquipment>\n";

if ($ttSerialNo != "") {
$xmlString .= "<device_serial_no>" . $ttSerialNo . “</device_serial_no>\n";
}
if ($ttDevEsn != "") {
$xmlString .= "<device_esn>" . $ttDevEsn . “</device_esn>\n";
}
if ($ttDevMann != "") {
$xmlString .= "<device_mann>" . $ttDevMann'] ."</device_mann>\n";
}
if ($ttDevSim != "") {
$xmlString .= "<device_sim>" . $ttDevSim . “</device_sim>\n";
}
if ($ttAddInfo != "") {
$xmlString .= "<device_additional_info>" . $ttAddInfo . “</device_additional_info>\n";
}
if ($ttDevPbx != "") {
$xmlString .= "<device_pbx>" . $ttDevPbx'] ."</device_pbx>\n";
}
$xmlString .= "<device_category>" . "KIOSK" . "</device_category>\n";
if ($ttDevName != "") {
$xmlString .= "<device_name>" . $ttDevName . “</device_name>\n";
}
if ($ttDevMod != "") {
$xmlString .= "<device_model>" . $ttDevMod . “</device_model>\n";
}
if ($ttDevAppType != "") {
$xmlString .= "<device_application>" . $ttDevAppType . “</device_application>\n";
}
if ($ttGateWay != "") {
$xmlString .= "<device_gateway>" . $ttGateWay . “</device_gateway>\n";
}
if ($ttDevCommFmt != "") {
$xmlString .= "<device_comm_format>" . $ttDevCommFmt . “</device_comm_format>\n";
}
if ($ttDialUp != "") {
$xmlString .= "<device_dial_up>" . $ttDialUp . “</device_dial_up>\n";
}
$xmlString .= "<device_flag>" . "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($xmlString);
echo "</pre>";

?>[/PHP]

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

Thanks
Nine72
Sep 10 '08 #1
Share this Question
Share on Google+
2 Replies


nine72
P: 21
actually I got it figured out....

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

$num = mysql_num_rows($result);

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

$rFirstName = mysql_result($result,$i,"rFirstName");
$rMiddleI = mysql_result($result,$i,"rMiddleI");
$rLastName = mysql_result($result,$i,"rLastName");
$rAddress1 = mysql_result($result,$i,"rAddress1");
$rAddress2 = mysql_result($result,$i,"rAddress2");
$rState = mysql_result($result,$i,"rState");
$rCity = mysql_result($result,$i,"rCity");
$rZip = mysql_result($result,$i,"rZip");
$rCntryCdI = mysql_result($result,$i,"rCntryCdI");
$rCustCareNo = mysql_result($result,$i,"rCustCareNo");
$rTelNo = mysql_result($result,$i,"rTelNo");
$rFax = mysql_result($result,$i,"rFax");
$rEmailId = mysql_result($result,$i,"rEmailId");
$rDept = mysql_result($result,$i,"rDept");
$rTitle = mysql_result($result,$i,"rTitle");
$rMobNo = mysql_result($result,$i,"rMobNo");
$rUrl = mysql_result($result,$i,"rUrl");


//code to run
$xmlString .= "<DefaultContact>\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_name>" . $rLastName . "</r_last_name>\n";
$xmlString .= "<r_address1>" . $rAddress1 . "</r_address1>\n";
if ($rAddress2 != "" ) {
$xmlString .= "<r_address2>" . $rAddress2 . "</r_address2>\n";
}
$xmlString .= "<r_state_cd>" . $rState . "</r_state_cd>\n";
$xmlString .= "<r_city>" . $rCity . "</r_city>\n";
$xmlString .= "<r_zip>" . $rZip . "</r_zip>\n";
if ($rCntryCdI !="") {
$xmlString .= "<r_cntry_cd>" . $rCntryCdI . "</r_cntry_cd>\n";
}
$xmlString .= "<r_customer_care_phone>" . $rCustCareNo . "</r_customer_care_phone>\n";
$xmlString .= "<r_telephone>" . $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_id>" . $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]
Sep 10 '08 #2

pbmods
Expert 5K+
P: 5,821
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 (:
Sep 11 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.