Forum Moderators: coopster

Message Too Old, No Replies

query returning some kind of info that doesnt print

printing info returned from query, gives return in HTML

         

will1480

3:35 pm on Jun 8, 2004 (gmt 0)

10+ Year Member



I am querying a table and i dont want to print some information if the table doesnt contain any information.

my code:
$query="SELECT * FROM items WHERE name='john doe';
$result=mysql_query($query);
$row=mysql_fetch_array($result,MYSQL_BOTH);

if($row{$k}!=""){
echo 'I should only be here if $row{$k} not empty';
echo $row{$k};
}

This will sometimes print even when $row{$k} contains nothing. The table value it is returning should be null or empty and therefore shouldnt print anything?

Is it carriage returns or something? When I view the HTML source it will print a new line where the $row{$k} is at.

m_shroom

5:34 am on Jun 9, 2004 (gmt 0)

10+ Year Member



Try;

if (strlen($row[$k])<1)

johnerazo

6:22 am on Jun 9, 2004 (gmt 0)

10+ Year Member



or simply...

if ($row)

mysql_fetch_array function returns FALSE if there are no resulting rows.

---
John Erazo

will1480

6:29 am on Jun 9, 2004 (gmt 0)

10+ Year Member



Yeah, I am using something like that as a work around, but it just isnt a real good solution.

I am using something like:
$temp=str_replace(" ","",$row2{$k});

The problem is, it will remove all the spaces except 1 space in certain instances. So if I were to echo '--'.$temp.'--'; my output would be something like -- -- .

There should be no possible way for a space to be in there using the str_replace.

m_shroom

6:59 am on Jun 9, 2004 (gmt 0)

10+ Year Member



If you first;

$temp=("--").($temp).("--");

echo $temp;

Your space should vanish.

will1480

2:49 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



The problem is that I am using an if statement to determine wether or not something should be printed.

$temp=str_replace(" ","",$row2{$k});
if($temp!=""){ echo '<td>'.$row2{$k}.'</td>';}

So I would like to avoid it printing what looks like an empty cell. here is part causing problem from the var_dump:
[12]=> string(1) " "

I really want to remove that character, but I have some strings which will be only 1 character in length that I still do want to display, so forced character remove and strlen do not really work here.

Also, I did try adding characters to the string before removing the white space, but that did not work as well, same end result. I am wondering if it is some weird clear character. How can I check what the character code is in ASCII?

will1480

3:18 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



Well, I went through and did a check for all abc...xyz and such characters, including spaces, periods, and such. It will work as a workaround, just would really like to know what the character is, just to make things smoother.

will1480

3:35 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



I think I got it. PHP has a function for removing all white spaces. $temp=ltrim($temp); Seems to work great, thanks for all the help.

surfin2u

4:20 pm on Jun 9, 2004 (gmt 0)

10+ Year Member



ltrim() removes whitespace characters (spaces, tabs, newlines, carriage returns, nulls) from the beginning of a string. Use trim() to strip whitespace from the beginning and end of a string.