Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Display XML Data Grid with PHP or Database?
Old 05-23-2008, 05:21 PM Display XML Data Grid with PHP or Database?
Sydpix's Avatar
Drinker I Smoke

Posts: 424
Name: Denny
Location: In a can...
Trades: 0
Anyone have any suggestions or referrals for something like this?

I want to take an XML file and display it in an html grid?

Would I do better to create a database for this?

Code:
<rows>
<!-- Begin Row -->
    <row id="1">
        <!-- Property Name --><cell>2500-2530 West Third Street</cell>
        <!-- St. --><cell></cell>
        <!-- Address --><cell>2500-2530 West Third Street</cell>
        <!-- City --><cell>Cleveland</cell>
        <!-- ST --><cell>OH</cell>
        <!-- Zip --><cell>44113</cell>
        <!-- WH --><cell>1</cell>
        <!-- Office SF --><cell>1</cell>
        <!-- Docks --><cell></cell>
        <!-- Drive-ins --><cell></cell>
        <!-- Clear --><cell></cell>
        <!-- Crane Rail--><cell></cell>
        <!-- Div-isible SF --><cell></cell>
        <!-- Lease Rate/ SF --><cell></cell>
        <!-- Comments --><cell></cell>
    </row>
</rows>
__________________
.
Village Idiot

Sydpix is offline
Reply With Quote
View Public Profile Visit Sydpix's homepage!
 
 
Register now for full access!
Old 05-23-2008, 07:04 PM Re: Display XML Data Grid with PHP or Database?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
It really depends on what you want to do with the information that will determine if you want to put it into a database or not. Also, how many rows of information do you have? If you have a lot of them and your only purpose is to display them on a website, a database might be better than storing it as XML. As far as displaying it in HTML, this is a good use for tables.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-23-2008, 08:02 PM Re: Display XML Data Grid with PHP or Database?
Sydpix's Avatar
Drinker I Smoke

Posts: 424
Name: Denny
Location: In a can...
Trades: 0
Yes, there would be about 50 or so of these I posted above.
__________________
.
Village Idiot

Sydpix is offline
Reply With Quote
View Public Profile Visit Sydpix's homepage!
 
Old 05-24-2008, 09:34 PM Re: Display XML Data Grid with PHP or Database?
Sydpix's Avatar
Drinker I Smoke

Posts: 424
Name: Denny
Location: In a can...
Trades: 0
Well... I decided to go Database.

http://www.teamweston.com/ Click on the Commercial Real Estate Listings

Anyone know how to alternate colors in php rows?
__________________
.
Village Idiot


Last edited by Sydpix; 05-24-2008 at 09:43 PM..
Sydpix is offline
Reply With Quote
View Public Profile Visit Sydpix's homepage!
 
Old 05-26-2008, 02:25 PM Re: Display XML Data Grid with PHP or Database?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
I think a database is a good choice. For alternating row colors, try something like this:

PHP Code:
$stripe 'odd';

foreach (
$rows as $row) {

     echo 
'<tr class="'.$stripe.'">Your row info here</tr>';
     if (
$stripe 'even') {
          
$stripe 'odd';
     } else {
          
$stripe 'even';
     }


Note: You'll need CSS classes named odd and even.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-27-2008, 08:53 PM Re: Display XML Data Grid with PHP or Database?
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
It sounds like a database is overkill. Mind you, I've worked with them for about 20 years, they pay for the food in my belly and the roof over my head. I think databases are great! But not everyone agrees with me - some people actually think they're cumbersome. If you're doing everything you need at this point, without a database, it sounds like you don't need one.

XSLT is your answer. It's probably the easiest, and surely the most straight forward, way to convert XML to HTML. With a database, after you built that and the ETL, you would need code (like VM hinted at) to take the info in your database and convert it to web pages. The XSLT will do that for you, from the way it's currently stored.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 05-27-2008, 09:17 PM Re: Display XML Data Grid with PHP or Database?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
I totally second John.
XSL have been designed with problem like yours in mind.

I have added a reference to a XSL style sheet to your xml example
Code:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="tbl.xsl" type="text/xsl"?>
<rows>
<!-- Begin Row -->
    <row id="1">
        <!-- Property Name --><cell>2500-2530 West Third Street</cell>
        <!-- St. --><cell></cell>
        <!-- Address --><cell>2500-2530 West Third Street</cell>
        <!-- City --><cell>Cleveland</cell>
        <!-- ST --><cell>OH</cell>
        <!-- Zip --><cell>44113</cell>
        <!-- WH --><cell>1</cell>
        <!-- Office SF --><cell>1</cell>
        <!-- Docks --><cell></cell>
        <!-- Drive-ins --><cell></cell>
        <!-- Clear --><cell></cell>
        <!-- Crane Rail--><cell></cell>
        <!-- Div-isible SF --><cell></cell>
        <!-- Lease Rate/ SF --><cell></cell>
        <!-- Comments --><cell></cell>
    </row>
</rows>
Save this file as a file named data.xml

Now, save this into tbl.xsl into the same directory as data.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" 
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                >
  <xsl:output method="html" encoding="UTF-8" indent="yes"
              doctype-public="-//W3C//DTD HTML 4.01//EN"
              doctype-system="http://www.w3.org/TR/html4/strict.dtd"
              standalone="yes" omit-xml-declaration="yes"
              />
  <xsl:template match="/">
    <html>
      <head>
        <title>xml to table</title>
      </head>
      <body>
        <table width="100%" border="1">
          <xsl:for-each select="/rows/row">
            <tr>
              <xsl:for-each select="cell">
                <td>
                  <xsl:value-of select="."/>
                </td>
              </xsl:for-each>
            </tr>
          </xsl:for-each>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>
and with a firefox or IE browser open, drop the xml file on it.
Any modern browser can transform this internally.
It will read the XML datas, fetch the XSL style sheet and generate an HTML output from the stylesheet.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 05-27-2008, 10:00 PM Re: Display XML Data Grid with PHP or Database?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Quote:
Originally Posted by Learning Newbie View Post
It sounds like a database is overkill. Mind you, I've worked with them for about 20 years, they pay for the food in my belly and the roof over my head. I think databases are great! But not everyone agrees with me - some people actually think they're cumbersome. If you're doing everything you need at this point, without a database, it sounds like you don't need one.

XSLT is your answer. It's probably the easiest, and surely the most straight forward, way to convert XML to HTML. With a database, after you built that and the ETL, you would need code (like VM hinted at) to take the info in your database and convert it to web pages. The XSLT will do that for you, from the way it's currently stored.
Good point.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 05-28-2008, 01:36 AM Re: Display XML Data Grid with PHP or Database?
Sydpix's Avatar
Drinker I Smoke

Posts: 424
Name: Denny
Location: In a can...
Trades: 0
Thanks for all the input! Talkupation for everyone!

The problem is, I have already create the database for the listings.

In the future, I already know they want to add video, images, contact information ect.. ect... I think the database might be more manageable for this the more content is added and more feature are needed. Not to take away from the XSL but, I know mysql has alot of room for growth. (I will however test out the sample!)

I hate to invest the time in XSL, then have to backtrack to inevitably create a database for expansion purposes. With the history I have with this company, I can almost guarantee things will get more involved as time rolls on. They always do. (I'm glad they do


Is it possible to page nation and sort tables via XSL?

http://www.teamweston.com/Commercial...e/Listings.php
__________________
.
Village Idiot


Last edited by Sydpix; 05-28-2008 at 01:48 AM.. Reason: Added Link
Sydpix is offline
Reply With Quote
View Public Profile Visit Sydpix's homepage!
 
Old 05-28-2008, 06:03 AM Re: Display XML Data Grid with PHP or Database?
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Well, XSL is a fairly hard language, when you have really modular input.
But I have used that template to do a pagination on a site.
you can call it from a main template by the command
Code:
<xsl:call-template select="galleryNav">
  <xsl:with-param name="CurPage">1</xsl:param>
  <xsl:with-param name="MaxPage">10</xsl:param>
  <xsl:with-param name="Gallid">1</xsl:param>
  <xsl:with-param name="Path">1</xsl:param>
</xsl:call-template>
Obviously, the GallId and Path params are used to construct the URL mapping.
Code:
<xsl:template name="galleryNav">
  <xsl:param name="CurPage"/>
  <xsl:param name="MaxPage"/>
  <xsl:param name="Gallid"/>
  <xsl:param name="Path"/>
  <xsl:variable name="Min">
    <xsl:choose>
      <xsl:when test="number($CurPage)&gt;=3">
        <xsl:value-of select="number($CurPage)-3"/>
      </xsl:when>
      <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  <xsl:variable name="Max">
    <xsl:choose>
      <xsl:when test="number($CurPage)+3&gt;$MaxPage">
        <xsl:value-of select="$MaxPage"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="number($CurPage)+3"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
  
  <ul class="nav">
    <li class="nav">
      <a href="/{$Path}/{$Gallid}/page:0"><![CDATA[<<]]> First</a>
    </li>
    <xsl:if test="$Min&gt;0">
      <li class="nav">
        <a href="/{$Path}/{$Gallid}/page:{number($CurPage)-1}">Prev</a>
      </li>
    </xsl:if>
      
    <xsl:if test="$Min&lt;$Max">
    <li class="nav">
      <xsl:if test="$Min=$CurPage">
        <xsl:attribute name="class">nav curr</xsl:attribute>
      </xsl:if>
      <a href="/{$Path}/{$Gallid}/page:{$Min}"><xsl:value-of select="$Min+1"/></a>
    </li>
    </xsl:if>
    
    <xsl:if test="$Min+1&lt;$Max">
    <li class="nav">
      <xsl:if test="$Min+1=$CurPage">
        <xsl:attribute name="class">nav curr</xsl:attribute>
      </xsl:if>
      <a href="/{$Path}/{$Gallid}/page:{$Min+1}"><xsl:value-of select="$Min+2"/></a>
    </li>
    </xsl:if>
    
    <xsl:if test="$Min+2&lt;$Max">
    <li class="nav">
      <xsl:if test="$Min+2=$CurPage">
        <xsl:attribute name="class">nav curr</xsl:attribute>
      </xsl:if>
      <a href="/{$Path}/{$Gallid}/page:{$Min+2}"><xsl:value-of select="$Min+3"/></a>
    </li>
    </xsl:if>
    
    <xsl:if test="$MaxPage&gt;=$Min+4 and $Max&gt;=$Min+4">
      <li class="nav">
        <xsl:if test="number($Min)+3=$CurPage">
          <xsl:attribute name="class">nav curr</xsl:attribute>
        </xsl:if>
        <a href="/{$Path}/{$Gallid}/page:{$Min+3}"><xsl:value-of select="$Min+4"/></a>
      </li>
    </xsl:if>
    
    <xsl:if test="$MaxPage&gt;=$Min+5 and $Max&gt;=$Min+5">
      <li class="nav">
        <xsl:if test="number($Min)+4=$CurPage">
          <xsl:attribute name="class">nav curr</xsl:attribute>
        </xsl:if>
        <a href="/{$Path}/{$Gallid}/page:{$Min+4}"><xsl:value-of select="$Min+5"/></a>
      </li>
    </xsl:if>
    <xsl:if test="$MaxPage&gt;=$Min+6 and $Max&gt;=$Min+6">
      <li class="nav">
        <xsl:if test="number($Min)+5=$CurPage">
          <xsl:attribute name="class">nav curr</xsl:attribute>
        </xsl:if>
        <a href="/{$Path}/{$Gallid}/page:{$Min+5}"><xsl:value-of select="$Min+6"/></a>
      </li>
    </xsl:if>
    <xsl:if test="$MaxPage&gt;$Max">
      <li class="nav">
        <a href="/{$Path}/{$Gallid}/page:{$CurPage+1}">Next</a>
      </li>
    </xsl:if>
    
    <li class="nav">
      <a href="/{$Path}/{$Gallid}/page:{number($MaxPage)-1}">Last <![CDATA[>>]]></a>
    </li>
  </ul>
</xsl:template>
And for the table sorting, you have an instruction to sort a for-each loop: <xsl:sort>
http://www.w3schools.com/xsl/el_sort.asp
You would use it that way:
Code:
<xsl:for-each select="node">
  <xsl:sort select="node" data-type="text" order="descending" case-order="upper-first"/>
</xsl:for-each>
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Display XML Data Grid with PHP or Database?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.31309 seconds with 12 queries