Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP IF then question

Status
Not open for further replies.

digatle

Technical User
Oct 31, 2003
85
US
I have the following code written so that I can display news in our company's format. What I'm trying to figure out is how to write an IF statement within this code to enable the **'d portioned to be seen or not be seen.

Here's the code:

<?php
while ($a_row = mysql_fetch_array( $divisionNews ) ) {
$title=$a_row['entry_title'];
$news=$a_row['entry_text'];
$plusnews=$a_row['entry_text_more'];

print &quot;$pageopen&quot;;
print &quot;$title&quot;;
print &quot;<div id=\&quot;content\&quot;><div class=\&quot;blog\&quot;><div class=\&quot;blogbody\&quot;>&quot;;
print &quot;$pagebody&quot;;
print &quot;<img align=\&quot;right\&quot; src=\&quot;&quot;.FS_IMAGE_SERVER.&quot;$siteID/news/$blogid.png\&quot;>&quot;;
print &quot;$news&quot;;

// ** NEED TO BE IF STATEMENT IF $plusnews HAS INFORMATION IN IT **

print &quot; [ <a href=\&quot;javascript:toggleParagraph();\&quot;>Expand</a> ]&quot;;
print &quot;<div id=\&quot;myPara\&quot; style=\&quot;display:none\&quot;>$plusnews</div>&quot;;

// CLOSE

print &quot;$pageend&quot;;
}
?>

How do I write the IF statement to say if $plusnews has content or a character, display the Expand option else goto CLOSE?

Digatle
 
Code:
if (isset($plusnews)){
    print &quot;  [ <a href=\&quot;javascript:toggleParagraph();\&quot;>Expand</a> ]&quot;;
    print &quot;<div id=\&quot;myPara\&quot; style=\&quot;display:none\&quot;>$plusnews</div>&quot;;
}

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
in place of the line that says:
// ** NEED TO BE IF STATEMENT IF $plusnews HAS INFORMATION IN IT **


the clsing if bracket replaces // CLOSE

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
Here's what I have now but the [ Expand ] still shows up. Is it because of my SQL statement that calls and looks for the $plusnews=$a_row['entry_text_more']; call?

<?php
while ($a_row = mysql_fetch_array( $divisionNews ) ) {
$title=$a_row['entry_title'];
$news=$a_row['entry_text'];
$plusnews=$a_row['entry_text_more'];

print &quot;$pageopen&quot;;
print &quot;$title&quot;;
print &quot;<div id=\&quot;content\&quot;><div class=\&quot;blog\&quot;><div class=\&quot;blogbody\&quot;>&quot;;
print &quot;$pagebody&quot;;
print &quot;<img align=\&quot;right\&quot; src=\&quot;&quot;.FS_IMAGE_SERVER.&quot;$siteID/news/$blogid.png\&quot;>&quot;;
print &quot;$news&quot;;

if (isset($plusnews)){
print &quot; [ <a href=\&quot;javascript:toggleParagraph();\&quot;>Expand</a> ]&quot;;
print &quot;<div id=\&quot;myPara\&quot; style=\&quot;display:none\&quot;><br>$plusnews [ <a href=\&quot;javascript:toggleParagraph();\&quot;</a> Shrink</a> ]</div>&quot;;
}
print &quot;$pageend&quot;;
}
?>
 
Bastien,

Actually it was my SQL that was the problem. Found out that a lot of the fields were in fact not NULL. Now if I can figure out this whole javascript issue so I can do more than one news on a page we'll be rockin!

Digatle
 
Having looked at the JS, I can see that you want to show/hide additional post data. One trick that I picked up was to actually show/hide the rows after the data was placed into a table. This made it very easy and browser compliance was less of an issue. What you want is a function that can show or hide table rows as needed. Then only the table rows need to be altered to reflect the required status and the js function only needs to be echoed once

sample found thru google

Code:
//**************************************
//     
// Name: Show/Hide Table Rows
// Description:Toggles the display of ro
//     ws in tables without reloading. Easily a
//     dapted to work with other tags.
// By: Joe McDonnell
//
// Assumes:Set up any table rows with a 
//     class name and a hidden style e.g. <t
//     r class=&quot;joe&quot; style=&quot;display:none&quot;>.P
//     ass the classname to the function to tog
//     gle visibility e.g. expandAll('joe').
//
//This code is copyrighted and has// limited warranties.Please see http://
//     [URL unfurl="true"]www.Planet-Source-Code.com/vb/scripts/Sh[/URL]
//     owCode.asp?txtCodeId=2232&lngWId=2//for details.//**************************************
//     

<SCRIPT LANGUAGE=JAVASCRIPT>
<!--


    function expandAll(varclass) {
    var myclass=varclass
    divColl = document.all.tags(&quot;tr&quot;);


        for (i=0; i<DIVColl.length; i++) {


            if (divColl(i).className == myclass) {
            divColl(i).style.display = (divColl(i).style.display == &quot;none&quot; ) ? &quot;&quot; : &quot;none&quot;;
        }
    }
}
//-->
</SCRIPT>

Bastien

Any one have a techie job in Toronto, I need to work...being laid off sucks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top