beermaker74 Posted January 31, 2007 Share Posted January 31, 2007 i need to examine one sql row and display the results in a xml file. [code]<?php$colname_Recordset1 = "-1";if (isset($_POST['houseid'])) { $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST['houseid'] : addslashes($_POST['houseid']);}mysql_select_db($database_vhtest, $vhtest);$query_Recordset1 = sprintf("SELECT * FROM photo WHERE houseid = %s", $colname_Recordset1);$Recordset1 = mysql_query($query_Recordset1, $vhtest) or die(mysql_error());$row_Recordset1 = mysql_fetch_assoc($Recordset1);$totalRows_Recordset1 = mysql_num_rows($Recordset1);?>[/code]here is my querythere will be only one record displayed. I need to display some of the rows to be inserted into an xml file. Here is my problem. I need to display the column values only of they are filled. So sometimes the columns will be completely filled and sometimes they will be blank. Is there an easy way to do this? I also only need to pick certain values. ietable rowid | photoid| folderurl | photo1url | photo1caption | photo2url | etc etc up to 20 photos and captionsso for the xmlfile I need to grab the folderurl and the photourl and caption from each column if it is filled.I hope I explained it well enough. Quote Link to comment Share on other sites More sharing options...
Hypnos Posted January 31, 2007 Share Posted January 31, 2007 [quote author=beermaker74 link=topic=124808.msg517686#msg517686 date=1170212194]I need to display the column values only of they are filled. So sometimes the columns will be completely filled and sometimes they will be blank. [/quote]I have two ways that come to mind, but there are lots of options.One if statement per column:[code=php:0]if($row_Recordset1['photoid']) { echo $row_Recordset1['photoid'];}if($row_Recordset1['folderurl']) { echo $row_Recordset1['folderurl'];}[/code]Or, just a foreach loop for every column in the result row:[code=php:0]foreach($row_Recordset1 as $value) { if($value) { echo $value; }}[/code][quote author=beermaker74 link=topic=124808.msg517686#msg517686 date=1170212194]I also only need to pick certain values. ietable rowid | photoid| folderurl | photo1url | photo1caption | photo2url | etc etc up to 20 photos and captions[/quote]It's most efficient to just kill that "select star" crud, and list what columns you do want.IE: "SELECT id, photoid, folderurl, photo1url FROM photo..." Quote Link to comment 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.