[solved] stupid css and php question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tom.cull
Forum Commoner
Posts: 32
Joined: Tue Sep 06, 2005 9:31 am

[solved] stupid css and php question

Post by tom.cull »

hey - very new to this all, am slowly getting my head around it all!

one quick question - hopefulyl you can point me in the right direction.

I use an external css to format all the text on my site however it does not format text from a php echo - is there something extra i need to do?

thanks
Last edited by tom.cull on Fri Sep 16, 2005 5:51 am, edited 1 time in total.
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

<style>
.bold{
font-weight:bolder;
}
</style>
<span class = 'bold'>I should be bold</span>

Code: Select all

<?php
echo "<span class = 'bold'>I should be bold as well</span>";
?>
both of them work in the same way
User avatar
mendingo
Forum Commoner
Posts: 28
Joined: Sun May 23, 2004 1:27 pm

Post by mendingo »

The browser sees the HTML and CSS coming from the server. It has no idea if the code was straight HTML or created by PHP.

In other words, it doesn't matter whether you've echoed the code from php or not.

Use your web browser to view the resultant HTML code and see if you can tell why it is ignoring the css style.

Failing that, post your PHP here.
tom.cull
Forum Commoner
Posts: 32
Joined: Tue Sep 06, 2005 9:31 am

Post by tom.cull »

hmm - ok here is the code.

When looking at the results the page is formatted OK APART from everything outputting from an echo:



Code: Select all

<?php

if ($submit) {

$username="xxxx";
$password="xxxx";
$database="xxxx_xxxx";

$location_area=$_POST['location_area'];
$car_pbracket=$_POST['car_pbracket'];

mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if ($location_area == '*') $location_area = "location_area"; 
else $location_area = "'$location_area'"; // notice the single quotes inside the double quotes 

if ($car_pbracket == '*') $car_pbracket = "car_pbracket"; 
else $car_pbracket = "'$car_pbracket'"; // notice the single quotes inside the double quotes



// retrieve all the rows from the database
   $query = "SELECT * FROM xxx_xxxWHERE (location_area LIKE $location_area) AND (car_pbracket LIKE $car_pbracket) AND (list_status='active')";
   
   $results = mysql_query( $query );

   // print out the results
   if( $results )
   {
      while( $contact = mysql_fetch_object( $results ) )
      {
         // print out the info
         $id = $contact -> id;
         $contact_nlast = $contact -> contact_nlast;
         $contact_nfirst = $contact -> contact_nfirst;
		 $car_make = $contact -> car_make;
		 $car_model = $contact -> car_model;
         echo( "<a href=\"showdetails.php?id={$id}\">{$id} . {$contact_nfirst}, {$contact_nlast} - {$car_make}, {$car_model}</a><br />" ); 
      }
   }
   else
   {
      die( "Trouble getting contacts from database: " . mysql_error() );
   }
}

?>


</body>
</html>
The html that is out put is :

Code: Select all

....
<p>&nbsp;</p>

<a href="showdetails.php?id=1">1 . Tom, Cull - Fiat, Punto</a><br /><a href="showdetails.php?id=8">8 . Steve, Wood - , </a><br /><a href="showdetails.php?id=3">3 . Curt, ockleford - Renault, Clio</a><br /><a href="showdetails.php?id=6">6 . Test234, Tets234 - , </a><br /><a href="showdetails.php?id=7">7 . Richard, Bevan - ford, mondeo</a><br /><a href="showdetails.php?id=9">9 . Steve, Wood - Rover, 18</a><br /><a href="showdetails.php?id=10">10 . Emily, Cull - Rover, </a><br />

</body>
</html>
ideas? thanks
User avatar
raghavan20
DevNet Resident
Posts: 1451
Joined: Sat Jun 11, 2005 6:57 am
Location: London, UK
Contact:

Post by raghavan20 »

Code: Select all

echo( "<a href=\"showdetails.php?id={$id}\">{$id} . {$contact_nfirst}, {$contact_nlast} - {$car_make}, {$car_model}</a><br />" );
I dont think you dont need curly braces around each variable. remove all of them. lets see how it comes

else try like

Code: Select all

<a href="showdetails.php?id=<?php echo $id; ?>"><?php echo $contact_nfirst.",".$contact_nlast."-".$car_make.",".$car_model?></a><br />
tom.cull
Forum Commoner
Posts: 32
Joined: Tue Sep 06, 2005 9:31 am

Post by tom.cull »

strange. I removed the curly brakets - not chahnge.

i did notice however that some of the css is working ie when I roll over the link it is displaying as specified - its just the type face that is not correct!

html is out put as :

Code: Select all

<a href="showdetails.php?id=1">1 . Tom, Cull - Fiat, Punto</a><br>
tom.cull
Forum Commoner
Posts: 32
Joined: Tue Sep 06, 2005 9:31 am

Post by tom.cull »

its ok - solved it - the echo wasnt outputting the HTML with <P> tags, meaning that the css didnt apply. I inserted <P> tags in to the echo and it works like a treat.
Post Reply