Jump to content

examining one mysql row


beermaker74

Recommended Posts

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 query

there 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. ie
table row
id | photoid| folderurl | photo1url | photo1caption | photo2url | etc etc up to 20 photos and captions
so 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.
Link to comment
Share on other sites

[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. ie
table row
id | 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..."
Link to comment
Share on other sites

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.