Jump to content

[SOLVED] Can't get CSS working with imported PHP


iQ::

Recommended Posts

Hey guys new to this forum so first of all hello to all.

 

I got a small problem not sure how to fix it, basically i've got 2 files, say file 1 and file 2.

File 1 is the main file and a php file and is the one that has the html code to load up the css file,

File 2 is the extra php code that is imported into file 1 via the required call.

 

The problem is that in file 2 I use php to create some html tags, mainly tables and the contents inside but the css rules aren't being applied to these tables and it's content, however the CSS rules still work on all the html tags on file 1. I'm guessing it's because file 2 it's being imported inside file 1?

 

The CSS rules as usual is loaded up in the <head> tag in file 1 and file 2 is imported later on in the <body> tag.

Anyone care to help me out please?

 

thank you.

 

 

Link to comment
Share on other sites

oh right sorry, this is it:

 

function getRecords($query, $table, $no_of_records, $pos)
{		
	//apply the given query on the given table with the limit clause, if unsuccessful generate an error message
	$result = mysql_query($query . $table . " LIMIT " . $pos . "," . $no_of_records)
	 or die(errorMessage('Error Encountered, the following error was recieved:'));

	if(@mysql_num_fields($result)>0 && mysql_num_rows($result)>0)
	{
		echo '<table border="1" width="100%" cellpadding="5" cellspacing="5">';	

		//create the column headers and have it formatted
		echo '<thead>
					<tr><th>Record No</th>';

		for($i=0; $i<mysql_num_fields($result); $i++)
		{
			echo '<th>' . mysql_field_name($result, $i) . '</th>';
		}
		echo '</tr></thead>';

		echo '<tbody>'; //create the table body and seperate from table headers

		for($i=1; $i<=mysql_num_rows($result); $i++) //loop through each field of the recordset
		{
			$row = mysql_fetch_row($result); //retrieve a row from the resultset
			echo '<tr>';

			$counter = $pos+$i; //keeps a track of the record number in the result

			//put the record number besides the actual record
			echo '<td class="recordNo">' . $counter . '</td>'; 

			foreach($row as $cell)
			{
				echo '<td>' . $cell . '</td>';
			}
			echo '</tr>';
		}
		echo '</tbody>';

		echo '</table>';
		mysql_free_result($result);
	}
}

 

and the actual css code is this:

 

body {
font-family: arial;
font-size: small;
}

table { 
border-width: 0px; 
padding: 5px; 
width: 100%
} 

table.navbar {
margin: 0px 0px 50px 0px;
padding: 0px 0px 0px 0px;
border-width: 0px;
}

td { 
text-align: center;
padding: 5px;
margin: 5px
} 


td.recordNo {
font-family: Arial;
color: Navy;
font-weight: bold
}

th {
text-align: center;
padding: 5px;
margin: 5px;
font-family: arial;
color: yellow;
font-size: large;
font-weight: bold;
background-color: black
}
a { text-decoration: none }
a:link { color: Blue } 
a:visited { color: Blue } 
a:hover { color: Red } 
a:active { color: Cyan }

Link to comment
Share on other sites

try

 

function getRecords($query, $table, $no_of_records, $pos)
{		
	//apply the given query on the given table with the limit clause, if unsuccessful generate an error message
	$result = mysql_query($query . $table . " LIMIT " . $pos . "," . $no_of_records)
	or die(errorMessage('Error Encountered, the following error was recieved:'));

	if(@mysql_num_fields($result)>0 && mysql_num_rows($result)>0)
	{
		echo "<table border=\"1\" width=\"100%\" cellpadding=\"5\" cellspacing=\"5\">";	

		//create the column headers and have it formatted
		echo "<thead><tr><th>Record No</th>";

		for($i=0; $i<mysql_num_fields($result); $i++)
		{
			echo "<th>.mysql_field_name($result, $i) .</th>";
		}
		echo "</tr></thead>";

		echo "<tbody>"; //create the table body and seperate from table headers

		for($i=1; $i<=mysql_num_rows($result); $i++) //loop through each field of the recordset
		{
			$row = mysql_fetch_row($result); //retrieve a row from the resultset
			echo "<tr>";

			$counter = $pos+$i; //keeps a track of the record number in the result

			//put the record number besides the actual record
			echo "<td class=\"recordNo\">' . $counter . "</td>"; 

			foreach($row as $cell)
			{
				echo "<td>.$cell.</td>";
			}
			echo "</tr>";
		}
		echo "</tbody>";

		echo "</table>";
		mysql_free_result($result);
	}
}

Link to comment
Share on other sites

wow thanks a lot, that worked.

 

So it was because I was using single quotes instead of double quotes?

 

i'm still quite new to php, it's been about a month i've started learning, guess there are many little details I need to catch.

 

the main reason I used single quotes was because I thought it would be quicker instead of having to escaping each double quote in the html tag.

 

So could you guys tell me an explanation on how single quotes cancelled out the css rules? will help me in the future before I use single quotes on anything and after this will be the end of my query.

 

thanks

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.