473,386 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Retrieving css from tables in mysql using php

gXion
5
hi there,,
I searched b4 I submit this post.

so,
let say:
if I have a css data stored in mysql.
the data looks like :
Expand|Select|Wrap|Line Numbers
  1. .name 
  2. {
  3. background-color: #0000EE;
  4. color: #0000EE
  5. text-decoration: italic;
  6. }
  7.  
  8. .age
  9. {
  10. background-color: #00FF00;
  11. color: #0000FF
  12. text-decoration: bold;
  13. }
  14.  
OK ?

now, if I want to split this data into a form ..
the form contains of tow tables..
each table name will be ( the class name ).

the properties will break into <td>'s.
here is a picture of what I want but could'nt do ( I made it in MS Word ) :



how can i do that with php ?
is it about preg_match_all() ?
if so, what will be the table structure and php code ?

thank you even if you don't have an answer ..
your solutions helped me many times when I was a Guest.
I hope you help my as a Member.
Mar 19 '08 #1
7 1682
ronverdonk
4,258 Expert 4TB
Please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 19 '08 #2
arggg
91
So you're wanting to display what is in the database into a table or you are wanting whatever css is in the database to be the css the site runs off of?
Mar 19 '08 #3
gXion
5
ronverdonk
sorry ,, i sweer the god i would do that but i frogot.

So you're wanting to display what is in the database into a table or you are wanting whatever css is in the database to be the css the site runs off of?
I want to display what is in the database into a table. ( like the picture above )
the first choise :)

breaking data into <td>'s.
to display the current css settings [ not using the css in <style> tag ].
just to show it ( in the admin settings site );
thanks.
Mar 19 '08 #4
Atli
5,058 Expert 4TB
Hi.

I'm not entire sure what you are talking about...

Are you trying to parse actually CSS code into PHP and echo the the results in a table?
To do that you may want to familiarize yourself with some of the String Functions. Most important of which are stripos, substr and explode
Unless you want to go with some sort of regex solution, in which case I'm close to useless :P

Is the CSS data already parsed in a table inside your database?
If that is the case, assuming each row has a column for each CSS attribute, you would simply have to:
Expand|Select|Wrap|Line Numbers
  1. # Query the data
  2. $tableName = "myTable";
  3. $result = mysql_query("SELECT atrribute1, attribute2, (...) FROM $tableName");
  4.  
  5. # Display table
  6. echo "<table><tr><td colspan=2>$tableName</td></tr>";
  7. while($row = mysql_fetch_assoc($result))
  8. {
  9.     foreach($row as $_k => $_v) 
  10.     {
  11.       echo "<tr><td>$_k</td><td>$_v</td></tr>";
  12.     }
  13. }
  14. echo "</table>";
  15.  
If none of this is of any help, please try to explain exactly where and how your data is stored.
Mar 20 '08 #5
gXion
5
Hi.

I'm not entire sure what you are talking about...

Are you trying to parse actually CSS code into PHP and echo the the results in a table?
To do that you may want to familiarize yourself with some of the String Functions. Most important of which are stripos, substr and explode
Unless you want to go with some sort of regex solution, in which case I'm close to useless :P
well, this is something.

I want exactly what you understand ( parse actually CSS code into php .. etc ).
I don't want to create a unique table for css.
just one column with type MEDIUMTEXT in a table.

in fact I tried this php code :
( forget about mysql right now , let's make the next code working, if so, i can try it in mysql myself )

[PHP]<?php

$css_is = "

body
{
background: #FEFDF0;
color: #000000;
font: bold 12pt arial;
margin: 0px 0px 0px 0px;
padding: 0px;
}

.special
{
background: #FAF1D5 url(images/design-body.jpg) repeat-x top left;
color: #000000;
font: bold 8pt tahoma;
}

";
/*

NOW we have a text variable which contains CSS code. Which we want to break it into <td>s like
<table><tr>
<td>body></td>
<tr>
<td>background</td><td>#FAF1D5 url(images/design-body.jpg) repeat-x top left</td>
</tr>
and so on.

*/

$css_parsed = explode("\n",$css_is);
foreach($css_parsed as $css_now)
{
// my stupid old code was here;
}
?>[/PHP]

lets say when I use echo ,it prints the { symbol as well . I don't now how to extract only the class name and the class properities into

[PHP]$some_array[$class_name][$class_properities][/PHP]

I tried also [PHP]preg_match_all("/[(.*)][\{(.*)\}]/",$css_is ,$css_parsed );[/PHP]
now it prints $css_parsed like separated letters each letter printed in one line .

what i want from this code : is to create a html table filled in with $some_array.

I don't want to cry.

hope i explained it well.
Mar 20 '08 #6
gXion
5
so .. ?************************
Mar 25 '08 #7
Atli
5,058 Expert 4TB
Forgive the delayed answer. I have been away for a while.
To answer your question...

You will simply have to build a code that dissects the CSS code and cuts it into usable pieces.

There is always the possibility of using some elaborate regex solution, but that is a whole another bowl of wax.

So, using PHP's String functions, we could start by cutting each class into it's own array element by exploding the CSS file on each end bracket:
Expand|Select|Wrap|Line Numbers
  1. // Cut the raw CSS text into classes
  2. $rawClass = explode("}", $cssString);
  3.  
Then, to clean this up, we could cut each class into two elements, the first containing the name and the second the raw text containing it's members:
Expand|Select|Wrap|Line Numbers
  1. // Create class array
  2. $classes = array();
  3.  
  4. // Loop through all the raw classes
  5. foreach($rawClass as $_v)
  6. {
  7.     // Make sure that the class isn't empty
  8.     $_v = trim($_v);
  9.     if(empty($_v)) continue;
  10.  
  11.     // Cut the raw class
  12.     $rawClassBuffer = explode("{", $_v);
  13.  
  14.     // Create the class buffer and add the name
  15.     $classBuffer = array();
  16.     $classBuffer['Name'] = trim($rawClassBuffer[0]);
  17.  
Now we would seperate each member of each class and seperate that into name and value:
Expand|Select|Wrap|Line Numbers
  1.     // Seperate each line of members
  2.     $rawMember = explode(";", $rawClassBuffer[1]);
  3.  
  4.     // Create member buffer
  5.     $members = array();
  6.  
  7.     // Seperate the name and value for each member
  8.     foreach($rawMember as $_v2)
  9.     {
  10.         // Make sure the member isn't empty (again)
  11.         $_v2 = trim($_v2);
  12.         if(empty($_v2)) continue;
  13.  
  14.         // Seperate the names and values
  15.         $rawMemberBuffer = explode(":", $_v2);
  16.  
  17.         // Add a name and value for each member to the member array
  18.         $memberBuffer = array();
  19.         $memberBuffer['Name'] = trim($rawMemberBuffer[0]);
  20.         $memberBuffer['Value'] = trim($rawMemberBuffer[1]);
  21.  
  22.         $members[] = $memberBuffer;
  23.     }
  24.  
And to finish it off, we add the class members to the class buffer and the class buffer to the class array:
Expand|Select|Wrap|Line Numbers
  1.     // Add the members array to the class buffer
  2.     $classBuffer['Members'] = $members;
  3.  
  4.     // Add the class to the class array
  5.     $classes[] = $classBuffer;
  6. }
  7.  
And finally, now that we have an array, to display it we could simply do:
Expand|Select|Wrap|Line Numbers
  1. // Show each class as a table
  2. foreach($classes as $_class)
  3. {
  4.     // Print table header and class name
  5.     echo "<table style='width: 250px;' border='1'>";
  6.     echo "<tr><td colspan='2' style='text-align:center;'>{$_class['Name']}</td></tr>";
  7.  
  8.     // Show each member
  9.     if(count($_class['Members']) > 0)
  10.     {
  11.         foreach($_class['Members'] as $_member)
  12.         {
  13.             // Print row and columns for names and values
  14.             echo "<tr><td>{$_member['Name']}</td><td>{$_member['Value']}</td></tr>";
  15.         }
  16.     }
  17.  
  18.     // Close table
  19.     echo "</table>";
  20. }
  21.  
Put that all together and provide a valid CSS string and you should see all your classes in neat little tables :)

Hope this helps.
Apr 2 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Bert Sierra | last post by:
Hello -- I have what appears to be a simple PHP+MySQL query, but Dreamweaver consistently generates PHP code which won't parse. I've stared at the PHP code for several hours now, and I can't...
1
by: evetommy | last post by:
Hi all, I'm trying to retrieve fields from my database with following mysql statement: $query = SELECT g_games.Title FROM g_collections, g_personal_reviews, g_games WHERE...
0
by: Stefan Hinz | last post by:
Jim, >> Does MySQL automatically handle deleted row cleanup, or is it necessary to >> periodically do this manually for tables with a lot of deletions? If it's >> manual, what are the SQL...
0
by: Stormblade | last post by:
Hey all, I have an existing JSP web application which retrieved data from a SQLServer database and displayed it. The data contained Unicode chars. This worked fine. I changed databases/JDBC...
1
by: kbs | last post by:
Hi all, i'm new here, and I just beggining with c# so.. I'm brazilian, and I already get connect to mysql using MySQLDriverCS, but I can't display data on a datagrid or thro an aspx file. can...
10
by: Krakatioison | last post by:
Hi everyone, can someone point me to download of an example for saving and retrieving to/from MYSQL database. Or did anyone of you tried this and could share your code with me. I've got some data...
3
by: 2401 members, members can post | last post by:
Dear Madams and Sirs, Ever had to split a website + SQL Tables ? Have a UNIX pc-linux-gnu on i686 + FEDORA 1) We have to split a sub-domain for the main domain name. 2) We have to build a...
7
by: scan87 | last post by:
Hello everybody, I have problem and its very urgent, please. I am using phpMyAdmin. The problem:- I have two tables:
2
by: amit2781 | last post by:
Hi, I have created 4 tables in 'amit' database and then I deleted them. Still I able to get information about the table_schema for the table deleted. After drop table when I fire a query for...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.