html - Change css class using php variable -
Here you need help because in the title, I am trying to change the CSS classes using PHP variables I am So basically I want to make a loop which enchances some code. But I want the div squares in the first loop to be different - it should be hidden.
To clear this problem, I have given simple code. I do not know where the mistakes are, please advise.
& lt ;! DOCTYPE html public "- // W3C // DTD XHTML 1.0 Transcription // N" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" & gt; & Lt; Html xmlns = "http://www.w3.org/1999/xhtml" & gt; & Lt; Top & gt; & Lt; Meta http-equiv = "content-type" content = "text / html; charset = UTF-8" /> & Lt; Title & gt; Untitled document & lt; / Title & gt; & Lt; Style & gt; .hidden {Visibility: hidden; }. Visual {visibility: visible; }. First class {color: red; } & Lt; / Style & gt; & Lt; / Head & gt; & Lt; Body & gt; & Lt ;? Php $ case = 4; $ Page = ""; $ Class = ""; If ($ page == 0) {$ class = "hidden"; } And {$ square = "visible"; } ($ Page = 0; $ page & lt; $ case; $ page ++) {echo & quot; Div class = & amp; Quot; First class $ class & amp; Quot; & Gt; This page is $ Page & lt; Br / & gt; & Lt; / Div & gt; ";}? & Gt; & lt; / body & gt; & lt; / html & gt;
If you need to insert a condition in loop
for & lt; php ($ page = 0; $ page & lt; $ case; $ page ++) { If ($ page == 0) $ class = "hidden"; and $ square = "visible"; echo "& lt; Div class = 'first class $ square' & gt; This page is $ Page & lt; Br / & gt; & Lt; / Div> ";}? & Gt; Because there is a condition when $ page == 0 then it will give a hidden class, so if you put it just outside looping , The $ page never returns an int value, because at the top of the condition is $ page = "";
Comments
Post a Comment