Jump to content

Query SQL database and return specific fields


jaykappy

Recommended Posts

Hello - 

I am using the code below...but am needing to modify it to return specific fields in the table. Very new to this and hoping to get a little help
I would imagine that the code in red below is the part that needs to be modified to return:

Field 1 Value
Field 2 Value
Field 3 Value
etc
etc

Anyone out there that can give me a hand?

Thanks in advance


$sql_str2 = "SELECT * FROM DISPLAY_VALUES WHERE PID = '".$p_num."'";
   $photo_rs2 = $conn->execute($sql_str2); 
   echo "<div class='redbg'> <b><big>TESTING:</big></b></div>";
   echo "<br>";
   If ($photo_rs2->EOF)
   {
       echo "No values exist for this parcel!";
   } else
   {

           $p_name2 = $photo_rs2->Fields("Filename")->Value;
           $p_hype2 = "javascript&#058;window.open('file://S:/GeoImag/Assessing/Sketches/".$p_name2."','photowindow','width=450,height=350')";
           writelinewhype($p_name2,"Image",$p_hype2);
           $photo_rs2->MoveNext();

       }
       echo "</table>";
       $photo_rs3->Close();
       $photo_rs3 = null;              
    }

I dont know if you are on the right track or what. But this method should work

 

$sql= "SELECT * FROM DISPLAY_VALUES WHERE PID = '".$p_num."'";
$results = mysql_query( $sql );

echo "<div class='redbg'> <b><big>TESTING:</big></b></div>";
echo "<br>";
if( mysql_num_rows( $results ) < 1)
echo "No values exist for this parcel!";
else{
while( $row = mysql_fetch_array( $results )  ){
	//do whatever you are trying to achieve
}
echo "</table>";
}

Also, a very good thing to do for all your queries would be to put a simple line which can help you a lot when you need to troubleshoot your queries, so try to do it like this:

 

$results = mysql_query( $sql,$db_conn ) or die (mysql_error());

 

It will save you a lot of time in future... ;)

Archived

This topic is now archived and is closed to further replies.

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