GalaxyTramp Posted September 23, 2009 Share Posted September 23, 2009 Hi I hope I am explaining this clearly. I have 2 tables "my_property" and "property_pics For example: In the table "my_property" propertyref '001' has an id of '21' In the table "property_pics" id '21' references all images associated with propertyref '001' with a row called 'file'. File is the path to the image, id is unique to particular property and is the same in both tables. I need to output all the image paths for each propertyref then loop round for the next and so on. I know that I need to query the other table to output the "$file" but after some time trying I have to ask for help. This is for an XML feed my code below. <?php header("Content-Type: text/xml; charset=UTF-8"); include("includes/conn.php"); $rssfeed = '<?xml version="1.0" encoding="UTF-8"?>'; $rssfeed .= '<root>'; $query = "SELECT * FROM my_property WHERE status ='Y' AND cat_id='4'"; $result = mysql_query($query) or die ("Could not execute query"); while($row = mysql_fetch_array($result)) { extract($row); $rssfeed .= '<property>'; $rssfeed .= '<id>'.$id.'</id>'; $rssfeed .= '<date>'.$date.'</date>'; $rssfeed .= '<ref>'.$propertyref.'</ref>'; $rssfeed .= '<price>'.$price.'</price>'; $rssfeed .= '<currency>EUR</currency>'; $rssfeed .= '<type>'; $rssfeed .= '<en>'.$property_type.'</en>'; $rssfeed .= '</type>'; $rssfeed .= '<town>'.$location.'</town>'; $rssfeed .= '<province>'.$city.'</province>'; $rssfeed .= '<location_detail>'.$address.'</location_detail>'; $rssfeed .= '<beds>'.$bedrooms.'</beds>'; $rssfeed .= '<baths>'.$bathrooms.'</baths>'; $rssfeed .= '<desc>'; $rssfeed .= '<en>'. htmlspecialchars($description) .'</en>'; $rssfeed .= '</desc>'; $rssfeed .= '<images>'; $rssfeed .= '<image id="1">'; $rssfeed .= '<url>http://www.mywebsite.com/pics/'.$file.'</url>' $rssfeed .= '</image>'; $rssfeed .= '</images>'; $rssfeed .= '</property>'; } $rssfeed .= '</root>'; echo $rssfeed; ?> Thanks GT Link to comment https://forums.phpfreaks.com/topic/175275-solved-phpxml-feed-looping-problem/ Share on other sites More sharing options...
nuttycoder Posted September 23, 2009 Share Posted September 23, 2009 put another query inside the loop: <?php header("Content-Type: text/xml; charset=UTF-8"); include("includes/conn.php"); $rssfeed = <?xml version="1.0" encoding="UTF-8"?>'; $rssfeed .= '<root>'; $query = "SELECT * FROM my_property WHERE status ='Y' AND cat_id='4'"; $result = mysql_query($query) or die ("Could not execute query"); while($row = mysql_fetch_array($result)) { extract($row); $s = mysql_query("SELECT * FROM property_pics WHERE id='$id'"); $r = mysql_fetch_object($s); $rssfeed .= '<property>'; $rssfeed .= '<id>'.$id.'</id>'; $rssfeed .= '<date>'.$date.'</date>'; $rssfeed .= '<ref>'.$propertyref.'</ref>'; $rssfeed .= '<price>'.$price.'</price>'; $rssfeed .= '<currency>EUR</currency>'; $rssfeed .= '<type>'; $rssfeed .= '<en>'.$property_type.'</en>'; $rssfeed .= '</type>'; $rssfeed .= '<town>'.$location.'</town>'; $rssfeed .= '<province>'.$city.'</province>'; $rssfeed .= '<location_detail>'.$address.'</location_detail>'; $rssfeed .= '<beds>'.$bedrooms.'</beds>'; $rssfeed .= '<baths>'.$bathrooms.'</baths>'; $rssfeed .= '<desc>'; $rssfeed .= '<en>'. htmlspecialchars($description) .'</en>'; $rssfeed .= '</desc>'; $rssfeed .= '<images>'; $rssfeed .= '<image id="1">'; $rssfeed .= '<url>http://www.mywebsite.com/pics/'.$r->file.'</url>' $rssfeed .= '</image>'; $rssfeed .= '</images>'; $rssfeed .= '</property>'; } $rssfeed .= '</root>'; echo $rssfeed; ?> Link to comment https://forums.phpfreaks.com/topic/175275-solved-phpxml-feed-looping-problem/#findComment-923770 Share on other sites More sharing options...
GalaxyTramp Posted September 24, 2009 Author Share Posted September 24, 2009 Thanks for your reply. I needed to show multiple images, your code only allowed for one. The code below displays all the images relating to the property. What I need to do now is count the entries in the DB and get $image to count from 1 upwards for each image. $querypics = "SELECT * FROM property_pics WHERE id='$id' LIMIT 10"; $resultpics = mysql_query($querypics) or die ("Could not execute query"); $rssfeed .= '<images>'; while($rowpics = mysql_fetch_array($resultpics)) { extract($rowpics); $rssfeed .= '<image id="'.$imageid.'">'; $rssfeed .= '<url>http://www.mywebsite.com/pics/'.$file.'</url>'; $rssfeed .= '</image>'; Regards GT Link to comment https://forums.phpfreaks.com/topic/175275-solved-phpxml-feed-looping-problem/#findComment-924003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.