473,395 Members | 1,473 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,395 software developers and data experts.

mysql related question

Hi group,

just wondering:

I have a database, containing the following fields:

name
address
zip
email

and a template for my page, containing the following tags:

[[name]] [[address]] [[zip]] [[email]]

Would there be a quick way to replace those tags with the data read from the
database without doing this:

$line=mysql_get_row($res) ; // provided we already have connection and data
selected
$html_to_show=preg_replace("/\[\[name]]/",$line[0],$html_to_show);
$html_to_show=preg_replace("/\[\[address]]/",$line[1],$html_to_show);
$html_to_show=preg_replace("/\[\[zip]]/",$line[2],$html_to_show);
$html_to_show=preg_replace("/\[\[email]]/",$line[3],$html_to_show);

(never mind the preg here or any typo's. this is a quick question)

Reason for me to ask, though code above works:
I need to create something dynamic. I would like to scan and replace every
instance in my template, looking like a tag ( [[some_tag_name]] ) by
the value of it's corresponding fieldname from my table.
I am really wondering how, but there's got to be an easier way to do this.
Currently I have 61 fields in one table and that kinda works towards RSI if
I have to code it all like this.
Anyone with a good suggestion, apart from reading the manual? (I am already
doing that)

Thank you very much in advance,

Michel

PS: sorry for double posting this.
Jul 17 '05 #1
5 1883
maybe instead of building your own template system (based on preg_replace)
try to use some simple (!) existing one: try Xipe
(PEAR::HTML_temnplate_Xipe). It works this way that you don't operate on a
bunch of $template->setValue($someValue), but simply auto-input the values
of the template-variables with existsing-ones in php. This means that you
can use php-arrays as well in the template.

i.e. in the template file you can have:

(...SOME HTML...)<strong><{$_myArray['name']}</strong>(...SOME HTML...)

and on the php code BEFORE compiling this template you have to create an
array $_myArray with at last one value $_myArray['name']. This can be done
ie with:

while ($row = mysql_fetch_rows($result)) {

$_myArray['name'] = $row[0];
// etc.
}

cheers
andrew
Hi group,

just wondering:

I have a database, containing the following fields:

name
address
zip
email

and a template for my page, containing the following tags:

[[name]] [[address]] [[zip]] [[email]]

Would there be a quick way to replace those tags with the data read from
the database without doing this:

$line=mysql_get_row($res) ; // provided we already have connection and
data selected
$html_to_show=preg_replace("/\[\[name]]/",$line[0],$html_to_show);
$html_to_show=preg_replace("/\[\[address]]/",$line[1],$html_to_show);
$html_to_show=preg_replace("/\[\[zip]]/",$line[2],$html_to_show);
$html_to_show=preg_replace("/\[\[email]]/",$line[3],$html_to_show);

(never mind the preg here or any typo's. this is a quick question)

Reason for me to ask, though code above works:
I need to create something dynamic. I would like to scan and replace every
instance in my template, looking like a tag ( [[some_tag_name]] ) by
the value of it's corresponding fieldname from my table.
I am really wondering how, but there's got to be an easier way to do this.
Currently I have 61 fields in one table and that kinda works towards RSI
if I have to code it all like this.
Anyone with a good suggestion, apart from reading the manual? (I am
already doing that)

Thank you very much in advance,

Michel

PS: sorry for double posting this.


Jul 17 '05 #2
Hi dude, thanks for responding.
trick though is that the time I need to start using these classes, is as
good as the time it takes to do this myself, probably, with some info.
Latter, though sticks in my mem and I would have actually learned a deal.

Thanks for pointing me to this solution though. never hurts to see more
resources.

Mich

"Andrzej Bednarczyk" <an*****@kreo9.NOSPAM.com> wrote in message
news:40******@news.home.net.pl...
maybe instead of building your own template system (based on preg_replace)
try to use some simple (!) existing one: try Xipe
(PEAR::HTML_temnplate_Xipe). It works this way that you don't operate on a
bunch of $template->setValue($someValue), but simply auto-input the values
of the template-variables with existsing-ones in php. This means that you
can use php-arrays as well in the template.

i.e. in the template file you can have:

(...SOME HTML...)<strong><{$_myArray['name']}</strong>(...SOME HTML...)

and on the php code BEFORE compiling this template you have to create an
array $_myArray with at last one value $_myArray['name']. This can be done
ie with:

while ($row = mysql_fetch_rows($result)) {

$_myArray['name'] = $row[0];
// etc.
}

cheers
andrew
Hi group,

just wondering:

I have a database, containing the following fields:

name
address
zip
email

and a template for my page, containing the following tags:

[[name]] [[address]] [[zip]] [[email]]

Would there be a quick way to replace those tags with the data read from
the database without doing this:

$line=mysql_get_row($res) ; // provided we already have connection and
data selected
$html_to_show=preg_replace("/\[\[name]]/",$line[0],$html_to_show);
$html_to_show=preg_replace("/\[\[address]]/",$line[1],$html_to_show);
$html_to_show=preg_replace("/\[\[zip]]/",$line[2],$html_to_show);
$html_to_show=preg_replace("/\[\[email]]/",$line[3],$html_to_show);

(never mind the preg here or any typo's. this is a quick question)

Reason for me to ask, though code above works:
I need to create something dynamic. I would like to scan and replace every instance in my template, looking like a tag ( [[some_tag_name]] ) by the value of it's corresponding fieldname from my table.
I am really wondering how, but there's got to be an easier way to do this. Currently I have 61 fields in one table and that kinda works towards RSI
if I have to code it all like this.
Anyone with a good suggestion, apart from reading the manual? (I am
already doing that)

Thank you very much in advance,

Michel

PS: sorry for double posting this.

Jul 17 '05 #3
I use something like the following:
$pageoutput = preg_replace('/\[\[\s*(.*?)\s*\]\]>/ie',"get_replacement('\\1')",
$template);
// I think the "]" needs escaped? ie "\]" above?
// you just had "]"... I could be wrong
function get_replacement($what)
{
/*
obviously here is where you would lookup "what"
in your database or whatever
*/
return $what;
}
Jul 17 '05 #4
Aye Brad,

Thanks for your input. The brackets " ] " do not need to be pre-ed by \,
only the left brackets do " [ " needs to be "\[".....

I will have a look at what you're suggesting and get back with results.....

Mich

"Brad Kent" <bk***********@yahoo.com> wrote in message
news:7a*************************@posting.google.co m...
I use something like the following:
$pageoutput = preg_replace('/\[\[\s*(.*?)\s*\]\]>/ie',"get_replacement('\\1')", $template);
// I think the "]" needs escaped? ie "\]" above?
// you just had "]"... I could be wrong
function get_replacement($what)
{
/*
obviously here is where you would lookup "what"
in your database or whatever
*/
return $what;
}

Jul 17 '05 #5

"michel" <no@spam.please> wrote in message
news:ca**********@news.cistron.nl...
Hi group,

just wondering:

I have a database, containing the following fields:

name
address
zip
email

and a template for my page, containing the following tags:

[[name]] [[address]] [[zip]] [[email]]

Would there be a quick way to replace those tags with the data read from the database without doing this:

$line=mysql_get_row($res) ; // provided we already have connection and data selected
$html_to_show=preg_replace("/\[\[name]]/",$line[0],$html_to_show);
$html_to_show=preg_replace("/\[\[address]]/",$line[1],$html_to_show);
$html_to_show=preg_replace("/\[\[zip]]/",$line[2],$html_to_show);
$html_to_show=preg_replace("/\[\[email]]/",$line[3],$html_to_show);

(never mind the preg here or any typo's. this is a quick question)

Reason for me to ask, though code above works:
I need to create something dynamic. I would like to scan and replace every
instance in my template, looking like a tag ( [[some_tag_name]] ) by
the value of it's corresponding fieldname from my table.
I am really wondering how, but there's got to be an easier way to do this.
Currently I have 61 fields in one table and that kinda works towards RSI if I have to code it all like this.
Anyone with a good suggestion, apart from reading the manual? (I am already doing that)


strtr() is probably the best function to use in this case.

$row = mysql_fetch_assoc($res);
foreach($row as $name => $value) {
$tr["[[{$name}]]" = htmlspecialchars($value);
}
$html_to_show = strtr($html_to_show, $tr);
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Xenophobe | last post by:
I know this isn't a MySQL forum, but my question is related to a PHP project. I have two tables. table1 table2 "table1" contains 2 columns, ID and FirstName:
0
by: MJL | last post by:
This is a mysql/php question (but a little more on the mysql side.) The two are so closely related these days, I thought it would be ok to ask here. I installed on my Suse Linux system mysql 4.0...
8
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU...
0
by: bruce | last post by:
Hi... Update.... We have the following setup in our httpd.conf file. We've tried to give what's related to the issue. We're trying to set up a virtual host for a test project. The behavior...
175
by: Sai Hertz And Control Systems | last post by:
Dear all, Their was a huge rore about MySQL recently for something in java functions now theirs one more http://www.mysql.com/doc/en/News-5.0.x.html Does this concern anyone. What I...
15
by: Cheryl Langdon | last post by:
Hello everyone, This is my first attempt at getting help in this manner. Please forgive me if this is an inappropriate request. I suddenly find myself in urgent need of instruction on how to...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
27
by: gerrymcc | last post by:
Hello, I'm a php/mysql beginner... Is there any way of making the mysql command line client full-screen? Sometimes it's easier to use the client than go thru php, but since it's only about 80...
10
by: Caffeneide | last post by:
I'm using a php script which performs three xml queries to other three servers to retrieve a set of ids and after I do a query to mysql of the kind SELECT * FROM table WHERE id IN ('set of ids');...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.