Forum Moderators: coopster

Message Too Old, No Replies

trying to use if statement before echo

used for address book i'm setting up

         

nofia

3:56 pm on May 29, 2008 (gmt 0)

10+ Year Member



i'm trying to set up an address book type site where some people have details listed and some don't, depending on certain variables

once i print the list of contacts i want to be able to click a name and see the contact details for that person pop up IF they have said yes to letting there info be seen.

i started with the code below and can't seem to get past the if $detail if section, any suggestions are welcome

$query1="SELECT `icontact_id`, CONCAT(`icfname`,' ',`iclname`) AS `names`, `ictitle`, `icmember`
FROM icontacts ";

$result1 = mysql_query($query1);

while($row = mysql_fetch_array($result1, MYSQL_ASSOC))

$detail= "if(`icmember` == yes)";
{"<a href=`details8.php`>($row[`icmember`])</a>";}
else
{"$row[`icmember`]";}

echo "ID :{$row['icontact_id']}"." "."NAME :{$row['names']}"." - "."TITLE :{$row['ictitle']}"." "."$detail <br>";

eelixduppy

4:52 pm on May 29, 2008 (gmt 0)



Hello and Welcome to WebmasterWorld!

The syntax you are using will not work. Try the following:


$detail = (icmember` == 'yes') ? '<a href="details8.php">('.$row['icmember'].')</a>' : $row['icmember'];

This is called a ternary conditional operator [us2.php.net].

d40sithui

4:54 pm on May 29, 2008 (gmt 0)

10+ Year Member



this looks relatively simple if i understand you correctly.

$details = "";
if($row['icmember']=="yes"){
$details = "<a href='details8.php'>".$row['icmember']."</a>";
}
else{
$details = $row['icmember'];
}

nofia

5:17 pm on May 29, 2008 (gmt 0)

10+ Year Member



thanks for your reply and yes it should be simple, but still not getting what i want,

after your reply d40sithui i got ( see below) and it doesn't show the id, name title or the yes no link to the details, but i am getting closer and had no error messages, , i'll keep trying

CONTACT DETAILS

ID : NAME : - TITLE :

nofia

2:37 am on May 30, 2008 (gmt 0)

10+ Year Member



i'm still having issues, i can't get the if statement to work. i get close but i'm missing something in the coding that would make the if statement work, i can get it to print without the if statement but not when using it.

check out my top post and see if you can help me out, thanks for any help you can give me

nofia

4:44 am on May 30, 2008 (gmt 0)

10+ Year Member



i'm still trying and changed things up a bit, but still not getting what i want. see below and maybe you can see what i'm doing wrong. for some reason i get all of the same message, either show detail or no detail, but i get the correct icmember printed out

$query1="SELECT `icontact_id`, CONCAT(`icfname`,' ',`iclname`) AS `names`, `ictitle`, `icmember`
FROM icontacts ORDER BY `icontact_id`";

$result1 = mysql_query($query1);

while($row = mysql_fetch_array($result1, MYSQL_ASSOC))
{
echo "<center>";

echo "ID :{$row['icontact_id']}"." "."NAME :{$row['names']}"." - "."TITLE :{$row['ictitle']}"." ";

if ($row['icmember'] == "yes")
echo "show detail {$row['icmember']}";
else
echo "no detail {$row['icmember']}";

echo "<br><br>";
echo "</center>";
}

eelixduppy

6:33 am on May 30, 2008 (gmt 0)



Is the case of the "yes" the same? Maybe you should be doing something like the following in your condition:

if ([url=http://www.php.net/strtolower]strtolower[/url]($row['icmember']) == "yes")

nofia

12:13 pm on May 30, 2008 (gmt 0)

10+ Year Member



thanks for the reply eelixduppy
but its not the yes no, its something in the part below that is not correct, first i want to just get the if to work and then add a link to it, but i can't even get it to work

if ($row['icmember'] == "yes")
echo "show detail {$row['icmember']}";
else
echo "no detail {$row['icmember']}";

my output is like this, the no after mixer should be a show detail

ID :33 NAME :roy rogers - TITLE :Audio Mixer no detail Yes

ID :34 NAME :lou ralls - TITLE :Gaffer no detail No

eelixduppy

12:37 pm on May 30, 2008 (gmt 0)




no detail [b]Yes[/b]

The "Yes" is capital, like I assumed. Try the code that I gave you in my last post.

nofia

1:05 pm on May 30, 2008 (gmt 0)

10+ Year Member



amazing, the fact that i didn't have a capital Y, caused me days of work, thank you, thank you, thank you, lesson learned

nofia

10:56 pm on May 30, 2008 (gmt 0)

10+ Year Member



ok now i need help with my next step, i want to see the details of one person at a time depending on whos name i click on also depending on the yes show detail question above. i want to link it to icontact_id and post it to a new page details1 which i already have set up. just need the icontact_id for the person whose details i want to see to post to the details1 page. i want to add to the if statement i already have. this is what i have so far and i'm stuck in the section around lines 7,8 9

{
echo "ID :{$row['icontact_id']}"." "."NAME :{$row['names']}"." - "."TITLE :{$row['ictitle']}"." ";

if (strtolower($row['icmember']) == "yes")
{echo "<a href=`details1.php`>Contact Info{$row['icmember']}</a>";
7echo "<form method==`post` action==`details1.php`>";
8echo "<select name == ($row['icontact_id']) >";
9echo "<input type==`submit` value==`Contact Details`>";
echo "</form>";}
else
{echo "{$row['icmember']} Contact Info";}
echo "<br><br>";
}