Jump to content

[SOLVED] XML PHP Question


selliott

Recommended Posts

If I use php to generate an XML document, is there a way to code it so if the file was called "photos.php" and it generated an xml file like:

 

<master>

    <node photo="test1.jpg" description="description here" galleryId="1" />

    <node photo="test2.jpg" description="more text" galleryId="2" />

</master>

 

That it could be setup in a way that if you enter something like "photos.php?galleryId=2", it would only display the nodes that has the galleryId=2?

Link to comment
https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/
Share on other sites

Great, here's my code...can anyone help me get this adjusted to work.

 

<?php 



//--------define connectivity information
$ConnString="DRIVER={SQL Server};SERVER=server_url_here;DATABASE=db_name_here";
$DB_User="db_username_here";
$DB_Passwd="db_password_here";
$table = "photos"; 
//-------Query database
$QueryString="SELECT * FROM $table";
//-------connect to database
$Connect = odbc_connect( $ConnString, $DB_User, $DB_Passwd );  
$Result = odbc_exec( $Connect, $QueryString ); 

  while($row = odbc_fetch_array( $Result ) )
  {
  	$photos[] = $row['photo'];
$descriptions[] = $row['description'];
$galleryId[] = $row['galleryId'];
  }


//    MAKE THE XML DOC


$nl = "\r\n"; 

    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>" . $nl; 
echo '<master>' . "\n";
for ($i=0; $i<count($photos); $i++) {

echo '<node photo="' . $photos[$i] . '" description="' . $descriptions[$i] . '" galleryId="' . $galleryId[$i] . '"/>' . "\n";

}
echo '</master>';

odbc_close( $Connect );
?>

  Quote
That it could be setup in a way that if you enter something like "photos.php?galleryId=2", it would only display the nodes that has the galleryId=2?

 

Where do you $_GET this value, "?galleryId=2"?  You would need to change your query to:

 

 $QueryString="SELECT * FROM $table WHERE gallery_id = $_GET['galleryId']";

 

Is this what you're looking for?

 

 

  Quote

  Quote
That it could be setup in a way that if you enter something like "photos.php?galleryId=2", it would only display the nodes that has the galleryId=2?

 

Where do you $_GET this value, "?galleryId=2"?  You would need to change your query to:

 

 $QueryString="SELECT * FROM $table WHERE gallery_id = $_GET['galleryId']";

 

Is this what you're looking for?

 

 

 

Awesome! Thanks!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.