Page 1 of 2

while - extract line - do

Posted: Fri Nov 03, 2006 12:33 pm
by ianhull
Hi Guys,

I am getting my results from a MySQL database like this.

Code: Select all

$result= mysql_query($query);

while ($line = mysql_fetch_array($result))    
{
extract($line);

// here I need to write all the records to a text file on the server
// the text file needs to be named from the sessionid like 3445454454.txt

}
If any of you guys can help with this it would be great.

Thanks in advance.

Posted: Fri Nov 03, 2006 12:35 pm
by RobertGonzalez
Do you know the field names coming from the database? If so, why not do this...

Code: Select all

<?php
$result= mysql_query($query);

while ($line = mysql_fetch_array($result))   
{
    $field1 = $line['field1']; // Or use it directly in echo/writes
    // here I need to write all the records to a text file on the server
    // the text file needs to name from the sessionid
}
?>

Posted: Fri Nov 03, 2006 12:44 pm
by ianhull
Thanks Everah,

Here is exactly what I am trying to achieve,

I did not mention earlier as I just wanted to fine out how to write text to a file while...

I am trying to write a .css stylesheet from the results of the database

I do not want the stylesheet to be visible on right click of the page view source etc.

I would like to like to the style sheet for smaller code on my page.

Any idea how to achieve this?

I would like to write it out like this.

Code: Select all

#Property'.$id.'{
	position:absolute;
	width:344px;
	height:206px;
	z-index:1;
	background-attachment: scroll;
	background-color: #FFFFFF;
	background-image: url(images/'.$picture1.');
	background-repeat: no-repeat;
	background-position: left top;
	top: 188px;
	left: 248px;
}
#Property'.$id.'{
	position:absolute;
	width:344px;
	height:206px;
	z-index:1;
	background-attachment: scroll;
	background-color: #FFFFFF;
	background-image: url(images/'.$picture1.');
	background-repeat: no-repeat;
	background-position: left top;
	top: 188px; //This top needs to be + 100 for each new record.
	left: 248px;
}
Is this possble?

Posted: Fri Nov 03, 2006 12:46 pm
by pickle

Code: Select all

$result = mysql_query($query);
$fh = fopen($_SESSION['mySessionID'].'.txt','a+');//w+ mode would work too, but a+ doesn't truncate
flock($fh,LOCK_EX);

while($line = mysql_fetch_array($result))
{
    //this is where you would create the string out of $line.  I'm not sure what format you'd want
    //you could use a foreach loop to make sure you get all the field names & values

   fwrite($fh,$whateverStringYouComeUpWith);
}
flock($fh,LOCK_UN);
fclose($fh);

Posted: Fri Nov 03, 2006 12:54 pm
by ianhull
Has anyone ever done anything like this with css?

Posted: Fri Nov 03, 2006 12:56 pm
by pickle
Probably.

However, I don't really think it matters what kind of text you're transferring does it?

Posted: Fri Nov 03, 2006 1:11 pm
by RobertGonzalez
Do you have to write the information? Why can't you just incorporate the database selected info into the output of a page (even a CSS page perhaps)?

Posted: Fri Nov 03, 2006 1:29 pm
by ianhull
My database is a property website.

I am trying to make it all really fast loading by using .css and layers.

When people right click on my page i do not want loads of code displayed //aparently it is beter for search engines too

Thats why im trying to display my properties for sale using css and php

the php part will get the image names etc and then also set the height and position for the layer
I want the css file to be included as alink so that not too much code is displayed.

Thanks for any more help,

I have been messsing with the

Code: Select all

fwrite($fh,$styler);
the file is created and contains style info but I am now trying to display and set the height.

I could do with more help on this.

Thanks.

Posted: Fri Nov 03, 2006 1:57 pm
by RobertGonzalez
ianhull wrote:When people right click on my page i do not want loads of code displayed //aparently it is beter for search engines too
I am assuming you mean when they view source? If that is the case, what is to stop them from actually loading your css file into the address bar and viewing it that way?
ianhull wrote:I want the css file to be included as a link so that not too much code is displayed.
Typically this has been handled by the css file being an actual PHP file and passing it a get param...

Code: Select all

<link rel="stylesheet" href="path/to/css.php?style=blue" type="text/css" />
So now the PHP file generates a CSS output and shows the styles that you want.

Is this what you are after?

Posted: Fri Nov 03, 2006 2:20 pm
by ianhull
It does not matter that people will see me .ccs if the navigate to it.

My main objective is to try and have as little code on the page as possilbe so that the page loads faster and is search eninge friendly

Here is property ccs information what I need outputting

Code: Select all

#Picture1 {
	position:absolute;
	width:107px;
	height:80px;
	z-index:1;
	left: 256px;
	top: 139px;
	background-attachment: scroll;
	background-image: url(images/'.$picture1.');
	background-repeat: no-repeat;
	background-position: left top;
}
#Property_title1 {
	position:absolute;
	width:369px;
	height:22px;
	z-index:2;
	left: 369px;
	top: 138px;
	font-weight: bold;
}
#Property_Description1 {
	position:absolute;
	width:369px;
	height:54px;
	z-index:3;
	left: 369px;
	top: 166px;
}
#Picture2 {
	position:absolute;
	width:107px;
	height:80px;
	z-index:1;
	left: 256px;
	top: 339px;
	background-attachment: scroll;
	background-image: url(images/'.$picture1.');
	background-repeat: no-repeat;
	background-position: left top;
}
#Property_title2 {
	position:absolute;
	width:369px;
	height:22px;
	z-index:2;
	left: 369px;
	top: 339px;
	font-weight: bold;
}
#Property_Description2 {
	position:absolute;
	width:369px;
	height:54px;
	z-index:3;
	left: 369px;
	top: 366px;
}
And this is the code that wil be displayed on my page.

Code: Select all

<link href="1dc02dfc9a7eb0e15a27dcac7a4ee36e.css" rel="stylesheet" type="text/css" />


<div id="Picture1"></div>
<div id="Property_title1">Luxury 2 Bedroomed Apartment</div>
<div id="Property_Description1">This property consists of blah blah blah<a href="property_details/?id=1">More Information</a></div>

<div id="Picture2"></div>
<div id="Property_title2">Luxury 5 Bedroomed Detatched</div>
<div id="Property_Description2">This property consists of blah blah blah<a href="property_details/?id=2">More Information</a></div>
This will make page loading really fast and very SE friendly

If anyone can help with achieving this it would be great and very much apreciated.

Posted: Fri Nov 03, 2006 2:33 pm
by RobertGonzalez
I am at a loss. I have never heard that less code is more SE friendly. I have also never heard that your page will load faster if your CSS is in an external file as opposed to inside the HTML. It is the same amount of text that the browser reads, and it is usually in unparsed comments with the <style> tags, so I cannot see how there is a benefit, Speed-wise or SEO-wise to moving everything into an external file (don't get me wrong, I'd do the same thing, just for modularity, not for optimization of loading and ranking).

Anyhow, I am not sure I can effectively answer your questions. Sorry.

Posted: Fri Nov 03, 2006 3:17 pm
by pickle
Whether the CSS file is loaded dynamically via PHP or through a static CSS file makes no difference with regards to SEO. I'm not sure why you're going to all the trouble of dynamically generating the CSS file at run time, rather than just making a plain jane, actual CSS file?

Are you doing something special in the database that makes it easier for you to generate CSS? That's about the only reason I can think of why you'd be doing it this way.

Posted: Fri Nov 03, 2006 3:31 pm
by ianhull
No nothing special,

I would just like to create a dynamic ccs property website with as little html code as possible.

Posted: Fri Nov 03, 2006 3:38 pm
by pickle
Then save yourself a LOT of trouble & just use a static CSS file.

Posted: Fri Nov 03, 2006 3:46 pm
by ianhull
sorry you did not understand...

dynamic, database driven with pagination and everything, css will get the record id from the database and use this information to poulate the css properties.

like this

Code: Select all

#Picture'.$id.' {
	position:absolute;
	width:107px;
	height:80px;
	z-index:1;
	left: 256px;
	top: 139px;
	background-attachment: scroll;
	background-image: url(pictures/'.$picture1.');
	background-repeat: no-repeat;
	background-position: left top;
}