selliott Posted September 25, 2008 Share Posted September 25, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/ Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 Yes. Quote Link to comment https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/#findComment-650142 Share on other sites More sharing options...
selliott Posted September 25, 2008 Author Share Posted September 25, 2008 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 Link to comment https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/#findComment-650150 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 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 Link to comment https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/#findComment-650153 Share on other sites More sharing options...
selliott Posted September 25, 2008 Author Share Posted September 25, 2008 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! Quote Link to comment https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/#findComment-650184 Share on other sites More sharing options...
Maq Posted September 25, 2008 Share Posted September 25, 2008 NP, glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/125729-solved-xml-php-question/#findComment-650186 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.