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.

Edited by mobo57: n/a

8 Years
Discussion Span
Last Post by mobo57

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

Edited by myhfelix: n/a


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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.