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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with a function call within a CSS element 2

Status
Not open for further replies.

MamaLoca

Programmer
Aug 29, 2005
48
HI, I just stumbled across you site while looking for a solution to a CSS issue I'm having.

I am trying to add some advertisments to a website I'm working on. I have created a CSS element to contain the ads. the container works just fine with text in it. the red outline is the element.

But then I want to use a function to generate random ads from a database but when I add the function call it is no longer within the element. instead the generated content is top left.


This is the line in the PHP file
Code:
<div id=\"rightcontent\" style=\"color:white; font-size:x-large; \">".ranAd()."</div>

and here is the CSS element definition:
Code:
#rightcontent {
        float:right;
	top:0px;
	overflow:hidden;	
	border-color:red;
	border-style:dotted;
	z-index:-1;
	}

I'm at a lose here, why doesn't CSS play nice with PHP in this case?
 
Yeah, there's an echo in the function, Have I been barking up the wrong tree?

Code:
function ranAd(){ 
$host = "blah";
 $user = "blah";
 $pass = "blah";
 $db = "blah";
 
 $conn = mysql_connect($host, $user, $pass) or die("0: " .mysql_error());
//connect to database
mysql_select_db($db, $conn) or die("1: " . mysql_error()); 


$query = "SELECT `ID` FROM `affiliates` ";

//execute SQL query and get result
$sql_result = mysql_query ($query) or die ('2' .mysql_error());
$rows= mysql_fetch_array($sql_result);


//Increments through rows 
for ($cnt=0; $cnt < 7; $cnt++){

$query = "SELECT `code` FROM `affiliates` WHERE ID =  '".rand(0, 100)."'";
$sql_result = mysql_query ($query) or die ('3: ' .mysql_error());
$ad = mysql_fetch_array($sql_result);
echo stripcslashes($ad["code"])."<br />";
}
}
 
Chris, Wait I mis understood

Yes
Code:
<div id=\"rightcontent\" style=\"color:white; font-size:x-large; \">".ranAd()."</div>
is in an echo thus the ".ranAd." is isolated out with the ".." sequence. have I got that wrong?
 
Well, the PHP is getting the data from the database the problem is it is displaying in the top left corner above the google ads block, instead of the container it's suppose to be in


And I'm not sure why it's not inside the container. The php works fine but I guess I will have to put the function into the code of each page instead of calling it. I can do that.
 
If you look at the page source of the final page (the one you gave us, you will see that in your div called ad, you only have two javascript scripts, one to define the variables and one to load the script from google. Looks like this script from google does not put the executed JS into your container but simply in the body element. I don't know how you could fix that since all the code is from google and resides on their server.
 
No the Google ad is fine, it's the affiliate ads In my database I'm talking about.

Yes the google ad is outside the main container. I put it there on purpose. what I want is for my affiliate ads to be on the oposite side of the main content. and in the case that the page witdth is to small it slides in behind the main content. The .js files are Googles own I just plugged it into the site as I got it from google. But that is, I think, unrelated to my issue with the function call that is suppose to be to the right of the content showing up at top left.

Incidentally, it shows up there no matter where on the page I place the code.

perhaps I'm not making this clear enoughm, but I guess I'm not sure how to put it.

Life would be so much easier if I only had the source code.
 
It looks like the function is being called before the HTML code is being streamed because it's actually above the DTD.

Difficult to work why without seeing the whole code.


Chris.

Indifference will be the downfall of mankind, but who cares?
Woo Hoo! the cobblers kids get new shoes.
People Counting Systems

So long, and thanks for all the fish.
 
well, lookie there. That is wierd but I'm beginning to understand

The pages use an included header, footer and include to generate the tops, bottoms and certain unique elements such as the function we are discussing so the function is executing at the include statement (which, by the way is before the header include, DUH) not at the call.

NOW, the call to ranAd() is throwing an error so I better skedaddle and spend some time figgerin this out why my call is incorrect, it ain't fixed but it ain't CSS after all.

Thanks for askin' all the right question guys. [thumbsup]

Life would be so much easier if I only had the source code.
 
Something to bear in mind when dealing with this kind of problem in the future...

Your browser does not know, or care, that a page (or part of it) has been generated by php. All it sees is a stream of HTML from the server. If your stuff isn't appearing where/how you want it to, you should do a View Source on the page you get in your browser, see where the HTML needs to be changed, and adjust your PHP accordingly.

I think a lot of people coming to php from javascript forget the fundamental difference between a server-side language and a client-side one.

-- Chris Hunt
Webmaster & Tragedian
Extra Connections Ltd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top