Jump to content

basic record display problems


87dave87

Recommended Posts

Trying to show results of address details from my database.

 

But the if statement for 'if there is no result' isnt working... its just displaying 'no recordno recordno record '

 

I want this to skip if there is no result (using the 'no record' as test text)

 

Also how can I skip showing a detail, such as 'echo "$addressline2<br>";' if there is nothing in that field on the database?

 

Mailshots from
<?
$query = "SELECT * FROM userfield";
$result = mysql_query($query);
$num = mysql_numrows($result);
print $num
?>
Members

</b>

<p>

<?
$i=0;
while ($i < $num) {

$firstnames=mysql_result($result,$i,"field5");
$surname=mysql_result($result,$i,"field6");
$housenamenumber=mysql_result($result,$i,"field7");
$addressline1=mysql_result($result,$i,"field8");
$addressline2=mysql_result($result,$i,"field9");
$addressline3=mysql_result($result,$i,"field10");
$citycounty=mysql_result($result,$i,"field11");
$postcode=mysql_result($result,$i,"field12");
$country=mysql_result($result,$i,"field13");

if($result="")
{
echo "no record";
}

else
{
echo "-- TEST --<br>";
echo "$firstnames $surname<br>";
echo "$housenamenumber $addressline1<br>";
echo "$addressline2<br>";
echo "$addressline3<br>";
echo "$citycounty<br>";
echo "$postcode<br>";
echo "$country<br>";
echo "-- TESTEND --<br>";
echo "<br>";
}
$i++;
}
?>

</p>

<?
mysql_close($conn);
?>

 

For the page click here

Link to comment
https://forums.phpfreaks.com/topic/50628-basic-record-display-problems/
Share on other sites

<?
$result = mysql_query("SELECT * FROM userfield");
while ($row=mysql_fetch_assoc($result)) {
echo "-- TEST --<br>";
if(!empty($firstnames)) echo "$row[field5] $row[field6]<br>";
if(!empty($addressline1))   echo "$row[field7] $row[field8]<br>";
if(!empty($addressline2))   echo "$row[field9]<br>";
if(!empty($addressline3))   echo "$row[field10]<br>";
if(!empty($citycountry))   echo "$row[field11]<br>";
if(!empty($postcode))   echo "$row[field12]<br>";
if(!empty($country))   echo "$row[field13]<br>";
echo "-- TESTEND --<br>";
echo "<br>";
}
mysql_close($conn);
?>

oops

 

<?
$result = mysql_query("SELECT * FROM userfield");
while ($row=mysql_fetch_assoc($result)) {
echo "-- TEST --<br>";
if(!empty($row[field5])) echo "$row[field5] $row[field6]<br>";
if(!empty($row[field7]))   echo "$row[field7] $row[field8]<br>";
if(!empty($row[field9]))   echo "$row[field9]<br>";
if(!empty($row[field10]))   echo "$row[field10]<br>";
if(!empty($row[field11]))   echo "$row[field11]<br>";
if(!empty($row[field12]))   echo "$row[field12]<br>";
if(!empty($row[field13]))   echo "$row[field13]<br>";
echo "-- TESTEND --<br>";
echo "<br>";
}
mysql_close($conn);
?>

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.