Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




After I Load An XML File, Can I Sort It By Node Attribute


After loading an xml file, is it possible to sort it by attribute?

For example, I have the following xml file:

<xml...
<diary>
<entry date="2005-01-01">I went to the park</entry>
<entry date="2005-01-03">Sold the car today</entry>
<entry date="2005-01-02">Went for a stroll</entry>
</diary>

When I go to load this using PHP, I would use some this similar to
this:

$xmldoc = domxml_open_file('diary.xml', DOMXML_LOAD_DONT_KEEP_BLANKS);

$node = $xmldoc->document_element();

Before I go storming through the xml tree outputing along the way, can
I sort it by (in this case) date?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Sort A Group Of Nodes By Attribute? How?
I have the following XML file:

<?xml version="1.0" encoding="iso-8859-1"?>
<items>
<item line="2">all that glitters is gold,</item>
<item line="1">Theres a lady thats sure,</item>
<item line="3">and she's buying a stairway to heaven</item>
</items>

To output this code Im using the following PHP:

$xmldoc = domxml_open_file('stairway.xml',
DOMXML_LOAD_DONT_KEEP_BLANKS);
$node = $xmldoc->document_element();
if ($xmldoc->has_child_nodes()) {
$node = $node->first_child();
$endwhile = false;
while ($endwhile != true) {
echo $node->get_content() . "<br />";
if ($node->next_sibling()) {
$node = $node->next_sibling();
}else{
$endwhile = true;
}
}
}

This does what it supposed to do except I want to ensure that it
outputs nodes ordered by 'line' attribute. The obvious answer would be
to put them in order in the XML file and the above example is very
simple so that you get the point, the real life example however will be
much larger and encase anyone put something in the wrong order it would
muck up my presentation. How could I adapt my code above to allow my
nodes to be sorted? I dont mind the nodes being out of order in the
physical file (stairway.xml) but when they are output using my script,
I want them to be ordered.

Writing A Node To An XML File
I want to write a node or nodes to an existing xml document. I don't need to create a new document, thanks but no thanks.

Judging from various posted topics I've seen. It appears the php DOM for XML isn't quite there yet and has a lot of bugs. Not only that it takes a few months before web hosters update versions of php.

I tried the pear classes, but they're so poorly documented, there's no example, there's nobody you can contact at Pear for hlep. If you ask for help on forums, you get no reply's so obviously not many ppl are using these classes.

I wonder..... if there's a push from say mySQL to stall or slow down PHP's functionality for XML?

Any ideas on how to write a node or nodes into an existing XML file..... without a bunch a array manipulation?

Load .txt File From Computer And Save The File In Www/folder Director
anyone know how to add the .txt file from computer into the localhost www/Myfolder directory.

Sort Array From .dat File
I'm using the following to open and print values from a .dat file but
I can't figure out how to sort the results. I think I need to use
either the array_multisort() or krsort() functions. If so, how would I
do that?

<html>
<body>
<pre>
<?php

$fp = fopen("datfile.dat", r);
$count = 0;
while(!feof($fp))
{
$register = fgets($fp, 4);
$sales = fgets($fp, 5);

$register_array[$count] = $register;
$sales_array[$count] = $sales;

print "Register: $register_array[$count]<br>";
print "Sales: $sales_array[$count]<br>";
$count = $count + 1;
}

?>
</pre>
</body>
</html>


Sort File Array By Time
I have an array called $data, which contains every image in a specific folder and i want to sort them, preferrably by upload time, but if this isn't possible the time of the last change would also do the work. Anybody of you guys know how?

How To Sort A Flat Text File By A Particular Field
I have created a flat file database to store contact information on my friends. The fields are 'firstname', 'surname', 'job title', 'address' etc What I am trying to do is be able to display a sorted list of my friends based on a particular field eg 'sort by surname'or 'sort by address' etc

Each row in the file ends with a '' and each field in each row is separated by a ' '.

I have come to the conclusion that I need to use the array_multisort function but cannot find any examples of taking information from a flatfile database and using array_multisort to sort and display based on a particular field. This is how far I have got but I am now stuck as to where to go from here? I have read the php manuals but it does not appear to improve my understanding of what needs to be done. Code:

XML - Node Manipulation
I was wondering if anyone could point me to any references regarding manipulating XML Child Nodes. I am currently retrieving data from XML in a manner that is useful. However, I am scratching my head when I need to change that information.

Select Node From DOM By ID?
I'm looking for a way to select a <div> by id from an entire xhtml page. I'm not a very experienced coder, but I'm learning... Does php have a fuction for this? it would be like

$entire_page = "entire xhtml page fetched from DB which contains <div id='wanted_div'>some content I want</div>";

$my_wanted_div =   .... // how do I get the content of 'iwantthisdiv' here?

Children Of Child Node??
Is there any function or way to access the children of a child node using DOM???

I mean if i have the xml structure as:
<app>
<app_data>
<data name='method'><value>sum_dif</value></data>
<data name='val1'><value>123</value></data>
<data name='val2'><value>456</value></data>
<app_data> // child of child node
<data name='coool'><value>divo9</value></data>
<data name='sands'><value>007</value></data>
<data name='make'><value>bond</value></data>
</app_data>
</app_data>
</app>
How can I access the data in the child node <app_data>?

Deleting A Node With Known Position In DOM (XML)
I have a a xml with a very basic structure:

<root>
  <template name="name0">data0</template>
  <template name="name1">data1</template>
  <template name="name2">data2</template>
  <template name="name3">data3</template>
  <template name="name4">data4</template>
  <template name="name5">data5</template>
  <template name="name6">data6</template>
</root>

I'm trying to remove the 4th node in the file (named name3). The code i'm using for this is:

<?
    $i = 3; //Hoping to delete the 4th node.
    $doc = new DOMDocument(); $doc->load('file:///var/templates.xml');
 
    $items = $doc->getElementsByTagName('template'); $items2 = $items->item($i);
    $itemg = $items2->nodeValue; echo $itemg; //It does return the value of the item i'm trying to delete.
 
    $itemg = $items->removeChild($items2); //Return: "Fatal error: Call to undefined method DOMNodeList::removeChild()"
?>

As said above, the script return Fatal error: Call to undefined method DOMNodeList::removeChild(). I've no idea why it isn't working, and definitely not an idea what the correct code would be.

Load File From Client
I am trying to do a load data local infile command for using it from my client to load his data to my server. Now the question is How is more confortable and security
a) Open the file into client and read line by line and creating record in my DB

b)Copy the file to the server and use command LOCAL DATA INFILE directly I am using SSL of course without certification but it doesn't matter yet? Which can be more secure to do?

Howto Load SQL From A File
How to load sql file(external) with php ...

>>index.html
<form method=post action='test.php'>
<input type=file name=file><br>
<input type=submit value=DO>
</form>

>>test.php
$sql = file_get_contents($_FILES['file']);
$sql = trim($sql);

mysql_connect('localhost','root','');
mysql_select_db('test');
mysql_query($sql);

Can $node->node_value() Return A Null Value?
I am using the following function to access a nodes value from an XML
file. It works fine until it discovers a empty tag. I would like to
have the option of leaving some tags empty for my script.

..
..
..
function foutput_contact ($node_name) {
$xml_document = domxml_open_file('xml/contacts.xml');
if ($xml_document) {
$nodes= $xml_document->get_elements_by_tagname($node_name);
$nodeCount = count($nodes);
$node = $nodes[0];
if ($node) {
$node = $node->first_child();
return $node->node_value();
}
}
}

The error is returned at the line 'return $node->node_value()' but
only when I use an empty node. Can this script be modified to allow
empty nodes?

DomDocument: Setting Attributes To A New Node
I'm trying to create a single function to append new nodes to a
DOMDocument object:

public function addElement( $element, $name, $value = '', $attrs = Null
)
{
if( !( $created = $this->createElement( $name, $value ) ) )
throw new Exception( 'Could not create a new node ' );

if( !( $child = $element->appendChild( $child ) ) )
throw new Exception( 'Could not append a new node ' );

// Process and attachs the new attributes from array $attrs if
any...
// if( $attrs )
// foreach( $attrs as $attribute => $value )
// ...
}

So far, so good. Now I want to set attributes and its values of the
recent created node (playing with createAttribute() and setAttribute(),
but I can't get the DOMElement from the new child DOMNode. Is it
possible without issuing getElementsByTagName() or getElementById() ??

Is another easy way -using DomDocument object- to create a new
element (such <table width="50%" border="0">...</table>) which has its
attributes and its values ?

Load Into Database From The Text File
i'm having difficulties here to load a text file to my database... let's say if i've a table named "train_info", and the field for that particular table is user-id, training_hours, training_date. let's say i've a text file that looks like this :

"
123434 12 2002-08-03
545322 10 2002-08-03
533434 12 2002-08-03
654333 12 2002-08-03
535434 12 2002-08-03
"

Is it possible for me to read such text file to be inserted into my "train_info" table?

How To Load Uneven XML File Into An Array
I need an array filled with an XML file made from the CSV example below.

bactisample row has 14 "columns"
bactiresult row has 11 "columns"

CSV is taken and run through an XML creator (we have no control over this piece).....

[DOM XML] How To Encode A Node Content (Accentuated Characters)
I'm trying to generate a RSS newsfeed using the DOM XML functions. However I
can't find a way to use accentuated characters. I even tried to specify a
character encoding set but it doesn't solve the problem.

Error I get :
XML Parsing Error: not well-formed
Location: news.php?action=syndicate&format=rss2
Line Number 1, Column 102:<?xml version="1.0" encoding="ISO-8859-15"?><rss
version="2.0"><channel><title>Website title - News (
----------------------------------------------------------------------------
-----------------------------------------------------------^

The not well-formed character is an accentuated character, as you can see on
the following code sample :

<?php

header ('content-type: text/xml');

echo ('<?xml version="1.0" encoding="ISO-8859-15"?>');

$dom_doc = domxml_new_doc (&#391;.0');

$rss_el = $dom_doc->create_element ('rss');
$rss_el->set_attribute ('version', &#392;.0');
$rss_el = $dom_doc->append_child ($rss_el);

$channel_el = $dom_doc->create_element ('channel');
$channel_el = $rss_el->append_child ($channel_el);

$title_el = $dom_doc->create_element ('title');
$title_el = $channel_el->append_child ($title_el);
$title_el->set_content ('Website title - News (àéèù)');

echo ($dom_doc->html_dump_mem ());

?>

Removing the accentuated characters from the title generates a well formed
XML file. Note that I also tried to encode the characters using the
htmlentities function but it didn't change anything.

XML - Sorting By Attribute
I'm not sure whether this is a question about php or xml or what to be honest - a poke in the right direction would be much appreciated...

I'm storing news articles in XML format.

newsitems.php which contains the XML looks like this; ....

Load The HTML Output Of A File Into A Variable?
How can i load the html output of a file into a variable.. Kind of like include()ing or require()ing a file.. but not echoing the content.. but saving it to a variable..

Can it be done? I dont want to use fgets because they are PHP files.. and i want to get the HTML as if a user opened with a browser..

Domxml_new_doc - Can I Add Encoding Attribute?
I've got a question about adding encoding attribute to my DOM XML Document?

I'm from Poland and we use extended latin alphabet - I'd like to use
iso-8859-2 Polish charset

e.g.:
<?xml version="1.0" encoding="iso-8859-2"?>

is there such posibility in DOM XML?

LDAP And TelephoneNumber Attribute
Anyone have a problem with PHP returning the telephoneNumber attribute empty while all the other attributes return just fine. Someone had the same exact problem on phpbuilder but it was never solved. Apparently it holds true for facsimileTelephoneNumber also. Any ideas?

A '<' Character Cannot Be Used In Attribute 'href', Except Through <[xml]
The following embedded snip it of PHP code won't validate using xhtml 1.0 strict. When validating I get the following error:

A '<' character cannot be used in attribute 'href', except through <[xml] Code:

href="/_Director/forms.php? <?PHP create_request_query('AskQuestions', 'AskQuestions'); ?>" Any idea what's wrong?

Populating An Auto_increament Attribute
I have just designed a BD. there are companies with auto increament which are integer. When I try to populate it after i tool value from another form and try to insert it into a table i recieve an error! I don't ask the companyID value from user as it is auto increament. Don't tell me to put NULL for that entry as it didn't work as well! Code:

SimpleXML Parsing By Attribute Value
I have an existing XML data set and would like to parse it with PHP5 based on the value of an attribute (any attribute!). I don't want to convert all my data from an attribute-heavy structure to a more proper element-based structure if I don't have to because of the javascript I am using on the client side. Listed below is the XML structure and PHP code I have been testing.

My existing data structure looks like this:
<gallery>
<photos>
<photo
path = "sunflower01.jpg"
width = "500"
height = "375"
thumbpath = "sunflower01.jpg"
thumbwidth = "125"
thumbheight = "94">
</photo>
</photos>
</gallery>

The script is here:

<?php
$xml = simplexml_load_file("pictures.xml");
$image = $xml->xpath("/gallery/photos/photo[@path='sunflower01.jpg']");
echo $image[0]->photo@thumbpath;
?>

Cannot Load Mysql Extension - Php_mysql.dll File Required.
I need php_mysql.dll file and where i can add this file...cause my sql server
shows a error that "Cannot load mysql extension"..

SimpleXML And Load Php File (Content-type: Text/xml)
I'm taking my first steps with xml and SimpleXML functions.
xml.php (It could be made dynamically with a mysql result I post this snippet for example)

PHP Code xml.php:

<?php
$xmlstr = "<?xml version="1.0" standalone="yes"?>";
$xmlstr .= "<movies>
<movie>Behind the Parser</movie>
</movies>";
header('Content-type: text/xml; charset=utf-8');
echo $xmlstr;
?>

PHP Code loadXml.php:

I've got this nasty error :
Warning: xml.php:2: parser error : Start tag expected, '<' not found in
c:xxxwwwxmlexamplemioplot.php on line 3

Warning: $xmlstr = ""; in c:xxxwwwxmlexampleloadXml.php on line 3

Warning: ^ in c:xxxwwwxmlexampleloadXml.php on line 3
bool(false)

I've got the same error in my web site .

xml.php is a valid xml file, isn't it ?
Therefore I'm wondering why the snippet
doesn't work ?

PHP Flat File Database - How To Load And Edit Lines?
I am using a text file as a database, each field delimited by ||
I want to be able to print all lines to a page, then by selecting one
(with, say, a radio button) it will load into the form at the bottom of
the page, where I can edit the fields, and save back to the same line in
the text file.

I dont know how to use primary keys or anything with a text file
database,

Winamp Does Not Load Playlist When Sending M3u File Using Php-script
This is my problem:

I'm writing a script that...
1. creates a customized pls/m3u playlist
2. sends the pls or a m3u playlist to the webbrowser.

The browser should open Winamp/Windows Media Player and load the
downloaded playlist.

However this doesnt seem to work. Everything winamp shows is the
playlist-filename. It seems that the playlist-file that was sent to
Internet Explorer does not exist when winamp tries to read it.

If I take the output of the script and places it in a .m3u-file
everything will
work perfect, but I do not want a .m3u-file for each of my mp3s!

This is the code for my script:
-----------------------------------------------------------
<?php
include ('playlist.php'); // include playlist-class

$playlist = new Playlist("m3u"); // Create instance of playlist
$output = $playlist->getPlaylist(); // Generate dynamic playlist

header("Content-Type: audio/mpegurl");
header("Content-Disposition: filename=playlist.m3u");

print($output);
?>
-----------------------------------------------------------

Warning: Simplexml_load_file() [function.simplexml-load-file]:
heres the errors:

Warning: simplexml_load_file() [function.simplexml-load-file]: core/combat/magic/Spark.const.xml:4: parser error : Extra content at the end of the document in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481

Warning: simplexml_load_file() [function.simplexml-load-file]: <mastery>Death</mastery> in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481

Warning: simplexml_load_file() [function.simplexml-load-file]: ^ in C:Program Filesxampphtdocswinterswordcorecombatcombat.class.php on line 481

and heres the .xml document: Code:

Counting Items In An Array Having X Attribute
I want to randomly select 5 cards from a standard playing card deck and count how many of each suit are returned:

[connect]
$sql = "SELECT * FROM cards ORDER BY RAND()LIMIT 5";
$result = mysql_query($sql);
while($cards = mysql_fetch_array($result)) {

$value = $cards["card_value"];
$suit = $cards["card_suit"];
$image = $cards["card_image"];
--------

Using count() within the loop returns a count of 1 since each card can only be of one suit. I tried using something like this:

$spades = 0;
if($suit='spades') {
$spades = $spades+1;
}

and I tried a foreach statement to count within the loop which always returns a count of 1.

Would someone be so kind as to point me in the right direction?

Accept Form Attribute Not Working
I cannot get my accept attribute working properly inside either my form, or my input tag. W3schools says that accept is supposed to go inside the input tag, but msdn says it goes in the form tag. I need it for an upload form I'm making, I want to only allow application/octet-stream type files, so I put this as my opening form tag:

<form enctype="multipart/form-data" accept="application/octet-stream" action="{$_SERVER['PHP_SELF']}" method="POST">

But I can still upload music, text files, and movies.  What gives?

Php-4.4.0 And Test.wsf = Error: The Value For The Attribute Is Not Valid: Language
We need to use version php-4.4.0-Win32 because one of the portal software
doesn't support version php-5.0.5-Win32. We cannot get the PHP setup part
working. Here is the error message:

Windows Script Host

Script: C:kits est.wsf
Line: 3
Char: 11
Error: The value for the attribute is not valid: language
Code: 80040049
Source: Windows Script Host

Here is the code from the install.txt

To test if ActiveScript is working, create a new file, named test.wsf (the
extension is very important) and type:

<job id="test">

<script language="PHPScript">
$WScript->Echo("Hello World!");
</script>

</job>

Save and double-click on the file. If you receive a little window saying
"Hello World!" you're done.

Everything works fine using php-5.0.5-Win32.

Simplexml And Attributes With A Namespace In Front. How Do You Getthe Attribute?
Here's a bit of xml code that works.

<?php

$string =
"<?xml version="1.0" standalone="yes"?>
<world>
<people xmlns:ss="http://crap">
<person id="5">John Doe</person>
<person id="2">Susie Q. Public</person>
</people>
</world>";

$xml = simplexml_load_string($string);
print "<pre>";
print_r($xml);
print "</pre>";

foreach($xml->people->person as $p)
foreach($p->attributes() as $a =$b)
{
print "$a =$b<br />";
}

// prints out
// id =5
// id =2
?>

Now what if I change the first person to this
<person ss:id="5">John Doe</person>

Anyone know how to get the id?

This is a question that is pertinent to an excel .xml file as
you'll get lines like this
<Cell ss:Index="3">stuff</Cell>

btw: there is a guide on ibm that tells you how to do this with php
and dom. I'm just wondering if there's a way to do it with simplexml.

How Can I Load Load Additional Extensions ?
My OS is Winxp . My web server is apache 2 which is installed as a NT
service .

My php version is 4.32 , and I extracted it into "c:php" .

I run php as a apache module .

I want to load Additional extensions .They are php_mbstring.dll,
php_xslt.dll and php_domxml.dll .

I have made changes to php.ini as follow.
extension_dir = "c:phpextensions"
extension=php_mbstring.dll
extension=php_xslt.dll
extension=php_domxml.dll

then I restarted apache2 .

but it told me that the modules could not be located .

Two Tables To Sort
I have two tables. Table 1 has the following columns: id, number and headline. Table 2: id, number, description.

What I need to do is sort the rows from both tables to one page sorted by the field "number".

I had two solutions:
1. Two queries from which I create one array. The array can then be sorted with PHP's function. The problem with this is that a "number" can have the same value in both tables.
2. Creating a temporary mysql table, inserting the data there and then selecting it ordered by the number. The problem with this one is concurrent users. If the table exists already and another user starts shoving "his data" to the table it all gets messed up.

Array Sort By Value
I have an array that has the following structure:

Array
(
[0] => xml_make Object
(
[name] => Alfa Romeo
[totalItems] => 270
)

[1] => xml_make Object
(
[name] => Aston Martin
[totalItems] => 7
)

[2] => xml_make Object
(
[name] => Audi
[totalItems] => 948
)

[3] => xml_make Object
(
[name] => Austin
[totalItems] => 51
)

[4] => xml_make Object
(
[name] => BMW
[totalItems] => 2235
)
}

How can I sort the array by the value in total Items?

Sort Data
When I click a title of table, I want to sort data. It same phpMyAdmin.

A Question Of SORT
I've been looking into a minor little glitch in one my programs. I'm writing a transaction table for sales orders, and two of the fields are 'Number of Distrbutions' and 'Sales Order Distribution'. The Number of Distributions contains the total number of line items for an order, the Sales order Distribution is the number associated with any given line item.

You can probably already guess the problem I'm having with this. When I read the sales order out of the database, it will be read out of order, ie,

1
10
11
12
2
20
21
3
4
5

I understand using natsort will resolve this problem. But the problem lies in the database, not in the actual sorting. In other words, I'm not reading these lines from an array where I might apply natsort. So my question would be, how do I sort this out (pun intended) with the database (MySQL).

The first solution I've come up with is to make my field (SOD) a text field, default ?', and superimpose the line item number. That should work... and would be easier than trying to populate an array and re-sort everything.

Is this the sort of thing (another pun intended) you've dealt with, and what was your solution?

Sort By Rank
I want is to figure out a rank by whoever has the most unique pageviews would be number one and the least would be last.

Sort-Problem
with the code below the output is sort by $verantw but $title and
$file in the same row DON'T belong to $verantw.

How do I have to make the sort command that $verantw, $title and $file
in the row "belongs together"?

Hope you understand my problem......

<?php
$handle = opendir('.');
$daten = array();
$daten['files'] = array();
$daten['title_tags'] = array();
$daten['verantw'] = array();

while ($file = readdir($handle)) {
if (substr($file, -4) == '.htm') {
$daten['files'][] = $file;
$html = file_get_contents('./' . $file);
preg_match_all('/!!!!(.*)!!!!/', $html, $matches);
if (isset($matches[1][0])) {
$daten['verantw'][] = $matches[1][0];
}
preg_match_all('!<title>([^<]+)</title>!i', $html, $matches);
if (isset($matches[1][0])) {
$daten['title_tags'][] = $matches[1][0];
}
}
}

sort($daten['verantw']);

$nr = 0;
$max = count($daten['verantw']);
for ($i = 0; $i < $max; $i++) {
echo "<tr>";
echo "<td class="text" width="4%">".++$nr."</td>";

echo "<td class="text" width="28%"><a class="link"
href="".$daten['files'][$i].""
target="_blank">".$daten['files'][$i]."</a></td>";

echo "<td class="verantw" width="25%">";
if ($daten['verantw'][$i]) echo $daten['verantw'][$i];
else echo '&nbsp;'
echo "</td>";

echo "<td class="text" width="35%">";
if ($daten['title_tags'][$i]) echo $daten['title_tags'][$i];
else echo '&nbsp;'
echo "</td>";
......
?>

I Need To Sort An Array
Current Case:
I have a table in a database

PRODUCTS
--------------
product_id
product_name
product_category
product_order

I am trying to create a change order script. With Up/Down links.

So I run my querry and store the data in the database. So I end up with an
array ....

Sorting Doesn't Sort?
I've got an array of arrays that I need to sort on preferably one of the
indices of the nested array, keeping the order of the outside array. The
structure is like this:

array([i] => array(key["name"] => data)
and what I need to do is to sort the nested array alphabetically according
to key["name"].
I can either use the name property of the nested array as index for the
outside array (then I need to keep the relationship between the outside
array and the nested array, or use a numeric index thus making the
relationship between the outside and nested array irrellevant.) What I need
to do in any case is to sort the nested array. I've tried using
arsort($array, SORT_STRING) but for some reason this doesn't sort the array
the way that I expected.

A var_dump of one element of the outside array looks like this:
array(2)
{ [1]=> array(2)
{ ["id"]=> string(1) "1" ["name"]=> string(6) "JustforShow" }
{ [2]=> array(2)
{ ["id"]=> string(1) "1" ["name"]=> string(6) "Testing" }

etc.

Arra_merge Sort
array_merge( $List, array( 'current' => 'Current' ) ); Is there anyway I can sort "current" to be the first for output?

How Do You Sort Records?
I have a db table "person" that I can sort by title, first_name,
last_name, or city with no problems at all because "title",
"first_name", "last_name", and "city" are columns in the table.

The requirement is to ALSO sort by department NAME. Problem is, I
can't do that in the "person" table because the column is
"department_id" which is a foreign key constraint to the department
table.

How do I sort the person records by department_name based on this?

I am using PHP 4.3.2 and MySQL 4.0.10

Now, second problem and even more of a problem:

The requirement is to ALSO sort by state NAME and country NAME. The
fields "state" and "country" in the "person" table contain only an
abbreviation of state and country; the corresponding full name of each
state and country are found in respective XML files in /xml/state.xml
and /xml/country.xml

PHP MYSQL Sort
My website setup is PHP Version 4.4.1, MYSQL 4.1.11. When the database results are returned and displayed they seems to ignore the sort/ order by clause.  At times the order seems to be in reverese or exactly as the results are in the database. 

I also noticed that the problem arises after an update to the MYSQL database but that doesn't explain why the order by in PHP is ignored.

Joins Of A Sort
I have two tables. 

1. with a list of airports, and their codes.
2. with a list of flights, with flight data and airport codes.

I have a query which is working fine in gathering all the flight information from table 2.  Now, when i post the data in a table, i want to show the name of the airport, however, in table 2, it doesn't contain the name of the airport, only the airport code.

I want to get the airport name from table 1, while still maintaining the error free query that i have mentioned above.

I've tried the Select `table1`.*, `table2`.* from `table1`, `table2` where Working query AND `table1`.airportcode = `table2`.aircode order by what-ever.

and try to post the data from table 2, but i get no results where as before i got some.

RSS Array Sort
I am pulling in a few RSS feeds into my site and I need to be able to sort the array I build by the pubdate of the feeds. The resulting array looks like this:

Array
(
    [0] => Array
        (
            [title] => Title of Feed
            [link] => link of feed
            [pubdate] =>  2007-05-04 00:00:00
            [description] =>  Description
        )

    [1] => Array
        (
            [title] => Title of Feed
            [link] => link of feed
            [pubdate] =>  2007-06-04 00:00:00
            [description] =>  Description
        )

I need to be able to sort by $theitems[$i]['pubdate'], how can I do that?

SORT / While / Query
I am trying to sort a query by the state_name column for viewing. I have a table where I SELECT a city and state_id for a user. Once I have the city and state_id I am able to SELECT characteristics (including the state_name) relevant to each city and state from another table (the data has to be in a separate table). I want to display the data in rows that are sorted, but also have the cooresponding city and state listed with the characteristics.

Because I am taking data from two different tables, and running a 'while loop' for one query dependent on the other, the ORDER BY function does not work (at least that is what I think is the problem). The data IS being displayed with the appropriate fields associated, but I cannot sort the way I want. I have included code:

Sort Data Problem
Hi, I got a problem. I want to sort mysql select results in a way that is not handeled by mysql itself. I was said that what I want might be possible to solve via php, but I have no clue how. Every help appriceated... The problem:


say I got a table "test" with columns "Row" and "Text". For example
Row | Text
---------------------------------------------------
1 | blablabla <order>2</order> blabla
2 | hladdbla <order>1</order> haaabla
3 | alablabla <order>3</order> dblabla
Now what I need is to sort this table by the numbers inside the <order> tags. The result should be: row 2, 1, 3

As I said, unfortunately this cant be done in mysql - I tried this:
SELECT * FROM `test` ORDER BY text='<order>%</order>'
with no result.


Copyright © 2005-08 www.BigResource.com, All rights reserved