Jump to content

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 );
?>

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?

 

 

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.