...

View Full Version : help?



40esp
08-12-2007, 10:21 PM
I need some help getting this to work. I want php to echo a row in my database "only if" it has information. but if it doesnt have info i want it to display alternative data
<img src="uploads/none.gif"/>

but it seems not to work. it still displays data no matter what.


help me please?



<?php

$show = ('');
$a = $row_Blog['title']

if ($a <> $show)
{
echo ($row_Blog['avatar']); }
else {
echo ("<img src='uploads/none.gif'/>");

} ?>

Inigoesdr
08-12-2007, 10:41 PM
You should use mysql_num_rows(), and a loop to output the rows. Check out the examples for the mysql_fetch_assoc() (http://www.php.net/manual/en/function.mysql-fetch-assoc.php) function.

40esp
08-12-2007, 10:57 PM
Actually Im using that function.

$row_blog['title'] is using that function.

Len Whistler
08-12-2007, 11:05 PM
If row[2] is empty "alternative data" will be displayed, if row[2] has data then Location: plus the row data will be displayed.



if (strlen($row[2]) > 0) {
echo "Location: $row[2]";

} else {
echo "alternative data";

}

40esp
08-12-2007, 11:14 PM
If row[2] is empty "alternative data" will be displayed, if row[2] has data then Location: plus the row data will be displayed.



if (strlen($row[2]) > 0) {
echo "Location: $row[2]";

} else {
echo "alternative data";

}


I've tried that and i got this error:


Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /var/www/web1/web/home.php on line 116

I changed $row[2] to $row_Blog['avatar']. was I supposed to do that? if not what is the variable $row have?

Len Whistler
08-13-2007, 01:27 AM
I've tried that and i got this error:
[CODE]I changed $row[2] to $row_Blog['avatar']. was I supposed to do that? if not what is the variable $row have?

$row[2] is the 3rd column of your database - 1st column is $row[0] - you can also use the name of the columns, such as:


$row[avatar]

StupidRalph
08-13-2007, 12:09 PM
Or use curly brace syntax

echo {$row_Blog['avatar']};


$row[avatar]
Wouldn't you need to have that in double quotes to access it that way? Else, it'll first be interpreted as a constant. :confused:
"$row[avatar]";
http://www.php.net/types.array

40esp
08-13-2007, 01:12 PM
got it. =] thankss all.

Inigoesdr
08-14-2007, 12:56 AM
Or use curly brace syntax

echo {$row_Blog['avatar']};


$row[avatar]
Wouldn't you need to have that in double quotes to access it that way? Else, it'll first be interpreted as a constant. :confused:
"$row[avatar]";
http://www.php.net/types.array

No, it will be parsed as long as it's in double quotes. You only need the curly braces if you use single quotes in the array output statement.
ie.:

$arr = array('test' => 'text');
echo $arr['test'] . " $arr[test] {$arr['test']}";
//text text text

StupidRalph
08-14-2007, 01:05 AM
Gotcha.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum