PHP - Simple Xml Just Outputing Values Of Inner-most Elements
I'm working on a way to let parents in my son's cub scout pack volunteer for specific spots in a duty roster via an AJAX page and MySQL db.
The duty roster is saved as an array in the db. My intent is to pull out the array, parse it into XML to send back to the jQuery which asked for it. The end result right now is that it just displays a bunch of "available" strings in a row, which is the default value for a job slot which hasn't been filled yet. The xml should look something like: Code: [Select] <data> <DAY val="DAYVALUE"> <TIMEBLOCK val ="TIMEVALUE"> <JOB title="titlevalue"> <slot num="x">AVAILABLE or NAME</slot> <slot num="x">AVAILABLE or NAME</slot> {...} </JOB> </timeblock> </DAY> <data> Where the attribute changes to reflect the different days for the campout, and the TIMEBLOCK val attribute changes for the different timeblocks which have job slots (Breakfast, Lunch, etc). Here is the snippet of code. The page starts with Header('Content-type: text/xml'); before making the call to the db (I've left that section out for security). The part where it gets retrieves and traverses the array are working as expected. It's where the XML gets built that everything goes wonky. (But if someone can show me a more recursive, efficient way of getting the same effect, I'm all ears) The output of this page shows up at:http://www.pack238.net/campingregistration/retrievedutyroster.php You'll see at the bottom where it just says "available available available available available available available available...." The code is: Code: [Select] //start the xml $xml = new SimpleXMLElement('<data></data>'); // get the duty roster array from the database $query = "select dutyroster from ".$eventsTable." where eventID = 1"; $result = mysql_query($query); if(!$result) { } else{ //put the returned result into a usable array $returnedRows = mysql_fetch_array($result); $day = unserialize($returnedRows[0]); foreach($day as $key => $value) //this gives us each day { echo "<Br/> Key is: $key && the value is $value"; $day1 = $xml->addChild('DAY'); $dayValue = $day1->addAttribute('val',$key); //Here, we know we're at the top level, so parse out the sub arrays foreach($value as $key1 => $value1)//this gives us each time block { $timeblock = ""; $timeblockValue = ""; $timeblock = $day1->addChild('TIMEBLOCK'); $timeblockValue = $timeblock->addAttribute('val',$key1); echo "<br/> Let's see the time blocks for each day: $key1 $value1"; //check to see if there's a JOBS sub array yet again or if it's a standalone if(is_array($value1)) { foreach($value1 as $key2 => $value2) { $job = ""; $title = ""; $job = $timeblock->addChild('JOB'); // $title = $timeblock->addAttribute('title',$key2); //this is the line throwing the attribute error echo "<br/> We're in a sub array, and the values a $key2 $value2"; if(is_array($value2)) { foreach($value2 as $key3 => $value3) { //for each slot: $slot = $job ->addChild('slot',$value3); $slotnum = $slot ->addAttribute('num',$key3); echo "<br/> The jobs a $key3 $value3"; } } else //we need to account for individual jobs that don't have a subarray { $slot = $job ->addChild('slot',$value3); $slotnum = $slot -> addAttribute('num','0'); } } } } // echo "<br/><br/>The array returned is: ".$usableArray."<br/>"; // $usableArray = unserialize($usableArray); // print_r($usableArray); }//end of the main foreach //we got the duty roster array....now just parse out the days, time periods, and jobs then create the xml $dom = dom_import_simplexml($xml)->ownerDocument; $dom->formatOutput = true; echo $dom->saveXML(); echo "<hr/>"; //print_r($xml); }//end of else to if(!result) Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
hi i tried to add this to my php file Code: [Select] <?php $xfile = @file('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $data = explode("::",$xfile[$random_num]); echo $data[1]; ?> i get no output i then tried just including the txt file like include 'banners.txt'; then everything in the txt file opens. and if i use fopen like this Code: [Select] <?php $xfile = fopen ('banners.txt', "r"); $random_num = rand (0,count($xfile)-1); $udata = explode("::",$xfile[$random_num]); echo $udata[1]; ?> i get this error Warning: fopen(banners.txt) [function.fopen]: failed to open stream: No such file or directory in /home/www/public_html/template/folder1/main.php on line 72 where as the txt file exist there anyone could help solve my issue? I have the following code, and really can't see what is wrong with it. Any help would be great. <?php if (!mysql_connect('127.0.0.1', 'root', '')) { echo 'Could not connect to mysql'; exit; } $dbname = 'Requests'; $result = mysql_list_tables($dbname); if (!$result) { echo "DB Error, could not list tables\n"; echo 'MySQL Error: ' . mysql_error(); exit; } while($row2 = mysql_fetch_row($result)) { foreach ($row2[0] as $table_id) { $query = "SELECT * FROM $table_id"; $dbresult = mysql_query($query); // added code to use the tablename and select all records from that table // create a new XML document $doc = new DomDocument('1.0'); // create root node $root = $doc->createElement('mixes'); $root = $doc->appendChild($root); // process one row at a time while($row = mysql_fetch_assoc($dbresult)) { // add node for each row $occ = $doc->createElement($table_id); $occ = $root->appendChild($occ); // add a child node for each field foreach ($row as $fieldname => $fieldvalue) { $child = $doc->createElement($fieldname); $child = $occ->appendChild($child); $value = $doc->createTextNode($fieldvalue); $value = $child->appendChild($value); } // foreach } // while } } echo 'Wrote: ' . $doc->save("s.xml") . ' bytes'; // Wrote: 72 bytes ?> Hey everyone. I have a project I'm working on and am having some issues. I'm trying to build a web-based FTP program for a client. I have all the ftp stuff down packed, but I'm having issues with connecting to a local computer. I can get the directories an a local disk viewing and changing just fine, my problem is I'm wondering how I might pass each value of the array generated by the scandir() function into a form element value such as a checkbox. The furthest I've been able to get with this is displaying the last object in the array. Here is some code: <?php foreach ($d as $key => $val) { echo "<table width=auto height=auto border=0> <tr> <td><img src=".$icon." width=16 height=16></td> <td>".$val."</td> <td><input name=selection type=checkbox value=".$val."></td> </tr> </table>"; ?> All I get is the last item in the array. any help is appreciated. I am attempting to flush values from a URL query with a pagation script. This line of code will replace one value: $page_name2 = preg_replace('/&?start=\d+/','',$page_name); This line of code will replace the second value: $page_name3 = preg_replace('/&?limit=\d+/','',$page_name); Can I combine them to replace both values in replace? This obviously isn't it: $page_name3 = preg_replace(('/&?limit=\d+/','',)&&('/&?start=\d+/','',)$page_name); Thank you. Hi there... This array thing seems little strange and I had to turn to phpfreaks I have an array named: $optionInfo When we do: print_r($optionInfo); it displays all the values stored in the array i.e. Array ( [4] => Array ( [optionId] => 5 [optionName] => Blue - Medium [optionListId] => 4 [dateCreated] => [enabled] => 1 ) ) And as we can clearly see, we have the optionId value as 5. So therefore, when I type: Code: [Select] print_r($optionInfo[optionId]); It returns nothing. Even though there is a value 5 in the array but I just can't get the individual value of optionId. Is there something I am missing here. Kindly reply. Thank you! Cheers! Hi there, I am working on a PHP web form and I have a very simple situation I guess, I have a variable named: $MyVal When I do print_r($MyVal); To see whats inside, I get: SimpleXMLElement Object ( [0] => 8.23 ) Now I am assigning this variable into a session variable so that I can do calculations with it. So I assign: $_SESSION['MySesVal'] = $MyVal; But after assigning to session variable, when I do my calculations: $finalValue = $_SESSION['MySesVal'] * 4; I get 0. So is it because the actual $MyVal variable has some XML stuff as: SimpleXMLElement Object ( [0] => 8.23 ) So what is the right way to properly assign $MyVal variable to a session variable to do calculations. Please reply. All comments and feedbacks are always welcome. Thank you! Hi there, I am having a PHP form with simple combo box. Here is the code: <form name="form1" method="get" action=""> <select name="select" onChange="form1.submit()"> <option value='value1'>My Value1</option> <option value='value2'>My Value2</option> <option value='value3'>My Value3</option> </select> </form> Now the form is successfully being submitted upon 'onChange' event. The only thing I am trying to do is to retain the value of the new option. As every time I select the value from the combo, it goes back and displays the 'value 1' even when I select value 3 or 2. How do I make the combo box retain the value as 3 (when I select option 3) after the form is submitted. Please reply. Thank you! I was wondering how to write something like this: if (table1.column1 + table2.column2 > table3.column3 then ..... I am confused where to put ( ) and ' Dear All Members here is my table data.. (4 Columns/1row in mysql table)
id order_no order_date miles How to split(miles) single column into (state, miles) two columns and output like following 5 columns /4rows in mysql using php code.
(5 Columns in mysql table) id order_no order_date state miles 310 001 02-15-2020 MI 108.53 310 001 02-15-2020 Oh 194.57 310 001 02-15-2020 PA 182.22
310 001 02-15-2020 WA 238.57 ------------------my php code -----------
<?php
if(isset($_POST["add"]))
$miles = explode("\r\n", $_POST["miles"]);
$query = $dbh->prepare($sql);
$lastInsertId = $dbh->lastInsertId(); if($query->execute()) {
$sql = "update tis_invoice set flag='1' where order_no=:order_no"; $query->execute();
} ----------------- my form code ------------------
<?php -- Can any one help how to correct my code..present nothing inserted on table
Thank You Edited February 8, 2020 by karthicbabuHi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) Hi all, Just curious why this works: Code: [Select] while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]')"; } And this does not: $headdata_1 = "'$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]'"; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values($headdata_1)"; }it puts $data[#'s] in the database fields instead of the actual data that '$data[0]','$data[1]'... relates to. I wrote a script to create the values in $headdata_1 based on the number of headers in $csvheaders1 but can't seem to get it working in the sql statement. Thanks Hi everyone, I'm trying to select either a class or an id using PHP Simple HTML DOM Parser with absolutely no luck. My example is very simple and seems to comply to the examples given in the manual(http://simplehtmldom.sourceforge.net/manual.htm) but it just wont work, it's driving me up the wall. Here is my example: http://schulnetz.nibis.de/db/schulen/schule.php?schulnr=94468&lschb= I think the HTML is invalid: i cannot parse it. Well i need more examples - probly i have overseen something! If anybody has a working example of Simple-html-dom-parser...i would be happy. The examples on the developersite are not very helpful. your dilbertone Hello, im very green to php and I am having trouble creating a simple log in script. Not sure why this is not working, maybe a mysql_query mistake? I am not receiving any errors but nothing gets updated in the members table and my error message to the user displays. any help is appreciated! here is my php: <?php session_start(); $errorMsg = ''; $email = ''; $pass = ''; if (isset($_POST['email'])) { $email = ($_POST['email']); $pass = ($_POST['password']); $email = stripslashes($email); $pass = stripslashes($pass); $email = strip_tags($email); $pass = strip_tags($pass); if ((!$email) || (!$pass)) { $errorMsg = '<font color="#FF0000">Please fill in both fields</font>'; }else { include 'scripts/connect_db.php'; $email = mysql_real_escape_string ($email); $pass = md5($pass); $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$pass'"); $log_check = mysql_num_rows($sql); if ($log_check > 0) { while($row = mysql_fetch_array($sql)) { $id = $row["id"]; $_SESSION['id']; $email = $row["email"]; $_SESSION['email']; $username = $row["username"]; $_session['username']; mysql_query("UPDATE members SET last_logged=now() WHERE id='$id' LIMIT 1"); }//Close while loop echo "You are logged in"; exit(); } else { $errorMsg = '<font color="#FF0000">Incorrect login data, please try again</font>'; } } } ?> and the form: <?php echo $errorMsg; ?> <form action="log_in.php" method="post"> Email:<br /> <input name="email" type="text" /><br /><br /> Password:<br /> <input name="password" type="password" /><br /><br /> <input name="myBtn" type="submit" value="Log In" /> </form> Hi can someone pls help, im tryin a tutorial but keep getting errors, this is the first one i get after registering. You Are Registered And Can Now Login Warning: Cannot modify header information - headers already sent by (output started at /home/aretheyh/public_html/nealeweb.com/regcheck.php:43) in /home/aretheyh/public_html/nealeweb.com/regcheck.php on line 46 Hi Folks,
My apologies if this isn't posted in the wrong forum - I'm assuming this is a CSS issue but may turn out to be a HTML problem.
I'm currently developing a website for a photographer, which can be found he http://www.byrnecomp...services.ie/CP/
At the bottom of the page on the left-hand-side is the photographers and on the right-hand-side is his email address.
The problem I'm having is that when the site is viewed in full screen on a large monitor, both of these contact details sit underneath the page content and not at the bottom of the screen - is there an easy way to fix thing?
Problem can be seen here
Thanks in advance for any and all help,
Regards,
Mike
Hello mates, I'm newbie in PHP and I'm trying to make something here. I'm working on a script that allows me to write some comments (from admin panel) and display them on my index page. For now, the script is displaying me all comments that I'm writing, and I want to display just 5 let's say. Any solution for this? Code: [Select] <tbody> <?php $scom=mysql_query("select * from comments order by date desc"); $num=mysql_num_rows($scom); if($num!=0) { while($randc=mysql_fetch_array($scom)) { echo' <tr> <td width="50" align="center" valign="top" bgcolor="#B5D2DC"><img src="images/500999.png" width="30" height="30" /></td> <td class="textmic"> <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#B5D2DC"> <tr> <td class="textc"><u>'.$randc["date"].'</u></td> </tr> <tr> <td align="justify">'; $newtext = wordwrap($randc["comment"], 20, "\n", true); echo $newtext.'</td> </tr> <tr> <td> <hr width="100%" noshade="noshade" size="8" color="#B5D2DC" /> </td> </tr> </table> </td> </tr> '; } } ?> </tbody> Can someone tell me the best way to group elements in an XML file? Code: [Select] <item> <title>Event 1</title> <dc:date>2010-09-25T01:00:00+01:00</dc:date> <dc:date>2010-10-02T01:00:00+01:00</dc:date> <dc:date>2010-10-09T01:00:00+01:00</dc:date> </item> <item> <title>Event 2</title> <dc:date>2010-09-25T01:00:00+01:00</dc:date> <dc:date>2010-10-02T01:00:00+01:00</dc:date> <dc:date>2010-10-09T01:00:00+01:00</dc:date> </item> Above is an example of what im trying to do and below is what i want the output to be Code: [Select] 25th September 2010 Event 1 Event 2 2nd October 2010 Event 1 Event 2 And so on, can anyone point me in the right direction on where to start looking to do something like this in PHP. Thanks Garry I am able to get all elements but the 'i*' parts. How do I do this. Code: [Select] $formarray = array( 'name' => array( 'i1'=> array('a'=>'a1', 'b'=>'b1', 'c'=>'c1', 'd'=>'d1', 'e'=>'e1', 'f'=>'f1', 'g'=>'g1'), 'i2'=> array('a'=>'a2', 'b'=>'b2', 'c'=>'c2', 'd'=>'d2', 'e'=>'e2', 'f'=>'f2', 'g'=>'g2'), 'i3'=> array('a'=>'a3', 'b'=>'b3', 'c'=>'c3', 'd'=>'d3', 'e'=>'e3', 'f'=>'f3', 'g'=>'g3'), 'i4'=> array('a'=>'a4', 'b'=>'b4', 'c'=>'c4', 'd'=>'d4', 'e'=>'e4', 'f'=>'f4', 'g'=>'g4'), ) ); foreach ($formarray as $newarray => $a) { ?><strong><?=$newarray;?></strong><br><? foreach ($a as $key => $k) { foreach ($k as $b) { ?>"<?=$b;?>", <? } ?><br><? } //end of second foreach ?><br><br><br><? } //end of first foreach ?> |