Again the dumb question. Sorry in advance and thanks for your responses in advance!
Here is my code after the DB connection:

$result = mysql_query( "SELECT * FROM overall WHERE profilename IS NOT NULL AND username = '$reguser'" )or die(mysql_error()); 
while($row = mysql_fetch_array($result)){
	echo $row['profilename'].$row['prodesc']."<br />";
}

What I am trying to do is to echo only those records that meet both criteria. My problem is this for example:
there are 10 records where the above is met and an additional 20 records where only one or the other is met. My echo results 30 rows, 20 empty and 10 with the data requested.
Tried what I could find, but all solutions seem to be aimed at surpressing individual records in the result, such as preventing the record in the row.
Again, thanks in advance for your help.

Recommended Answers

All 2 Replies

At database level you can change it to something like this, assume column structure for profilename and prodesc are the same:

$result = mysql_query( "SELECT * FROM overall WHERE profilename IS NOT NULL AND prodesc IS NOT NULL AND username = '$reguser'" )or die(mysql_error());

If you don't want to make changes to database query, you can also change it at application level

while($row = mysql_fetch_array($result)){
    if (strlen($row['profilename'].$row['prodesc'])) {
        echo $row['profilename'].$row['prodesc'].'<br />';
    }
}

Or use the following method. The code is a bit faster:

while($row = mysql_fetch_array($result)){
    $output = $row['profilename'].$row['prodesc'];
    if (isset($output[0])) {
        echo $output.'<br />';
    }
}

Hope that helps

myhfelix:
PERFECT!
That is what I needed. Tried something similar, but it obviously was not quite right.
Thanks for your quick and professional response!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.