Just a question really.. I enter my data in to the table but I don’t include any html (of course). Well then now I am in pickle because I can not Bold the keywords. I want to automatically bold keywords.
Can this be done? can I provide links like this too?
I heard of a few ways to do this but I don’t know if they are relevent here is what I want to do:
I am going to provide results from my database for this week. Now here is the important part I would like every time erie or bands or events pops up for it to be parsed as bold. So I want to take the result and alter them so everytime bands or any other keywords comes up they automatically have the tags <strong></strong> wrapped around them. What can I do???
[code=php]
<?php
//connects to my database for future querys
function dbconnect() {
global $connection;
$db_name = "markbad_markbadsql";
$connection = @mysql_connect ("localhost", "markbad_drpl1", "n4x4q37IhCez")
or die ('I cannot connect to the database because: ' . mysql_error());
$db = mysql_select_db ($db_name, $connection)
or die ('I cannot connect to the database because: ' . mysql_error());
}
// Shows a regular listing of events from the past week.
function eventreg($connection) {
global $display_block;
$table_name = "events";
$sql = "SELECT * FROM $table_name WHERE date
BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
$result = mysql_query($sql)
or die (mysql_error());
$display_block ="";
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row['date']);
$bar = ($row['bar']);
$updated = ($row['updated']);
$details = ($row['details']);
$map_url = ($row['map_url']);
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}
}
// Displays events in the form of links so the user can pick them
function showsingle($connection) {
global $display_block;
$table_name = "events";
//Build the query and execute
$chk_id = "SELECT id FROM $table_name WHERE id = '$_GET[id]'";
//Check the result of the id
$chk_id_res = @mysql_query($chk_id) or die(mysql_error());
$chk_id_num = @mysql_num_rows($chk_id_res);
if ($chk_id_num != 1) {
$display_block = "<p>A error has occured when searching for the listing</p>";
exit;
} else {
$sql = "SELECT date, bar, updated, details, map_url FROM $table_name WHERE id = '$_GET[id]'";
//create result variable
$result = mysql_query($sql) or die(mysql_error());
//while loop to gather variables from result.
while ($row = mysql_fetch_array($result)) {
$date = $row['date'];
$bar = $row['bar'];
$updated = $row['updated'];
$details = $row['details'];
$map_url = $row['map_url'];
}
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}
}
function sidemenu($connection) {
global $nav_block;
$table_name = "events";
$sql = "SELECT id, bar FROM $table_name WHERE date
BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
$result = @mysql_query($sql) or die(mysql_error());
$num = @mysql_num_rows($result);
if ($num < 1) {
$nav_block = "<p>I am sorry there is no results</p>";
} else {
$nav_block .= "<ul class="menu">";
//if results are found loop through them and make a form selection block list.
while ($row = mysql_fetch_array($result)) {
$id = $row['id'];
$bar = $row['bar'];
$nav_block .= "<li><a href="index.php?id=$id">$bar</a></li>";
}
$nav_block .= "</ul>";
}
}
function showall($connection) {
global $display_block;
$table_name = "events";
$sql = "SELECT * FROM $table_name
";
$result = mysql_query($sql)
or die (mysql_error());
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row['date']);
$bar = ($row['bar']);
$updated = ($row['updated']);
$details = ($row['details']);
$map_url = ($row['map_url']);
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}
}
?>
[/code]
[code=php]<?php
require("listingsfunc.php");
if (!$_GET['id']) {
dbconnect();
eventreg($connection);
sidemenu($connection);
} if ($_GET['show_all_erie_pa_bars']) {
dbconnect();
showall($connection);
} else if ($_GET['id'] != "") {
dbconnect();
sidemenu($connection);
showsingle($connection);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<? echo "$nav_block"; ?>
<br />
<a href="Untitled-4.php?show_all_erie_pa_bars=yes" title="Show All Erie Bars Listings">Show All Listings</a>
<br />
<br />
<? echo "$display_block"; ?>
<br />
<br />
</body>
</html>
[/code]
<i>
</i>SELECT REPLACE("look at my hands","my","your");
look at your hands
[/quote]
<i>
</i>SELECT REPLACE("look at my hands","my","<strong>my</strong>");
[CODE]SELECT REPLACE("Erie","Erie","<strong>Erie</strong>");[/CODE]
[CODE]SELECT REPLACE("bars","bars","<strong>Bars</strong>");[/CODE]
[code=php]
// assume $text has been populated with the desired text from the DB
$text = preg_replace('/w(erie|bands?|events?)w/i', "<strong>$1</strong>", $text);
[/code]
[code=php]
// Shows a regular listing of events from the past week.
function eventreg($connection) {
global $display_block;
$table_name = "events";
$sql = "SELECT * FROM $table_name WHERE date
BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
$result = mysql_query($sql)
or die (mysql_error());
$display_block ="";
//While loop will create an array called $row
while ($row = mysql_fetch_array($result)) {
// get individual elements from events
$date = ($row['date']);
$bar = ($row['bar']);
$updated = ($row['updated']);
$details = ($row['details']);
$map_url = ($row['map_url']);
////////////////////Right Here///////////////////////////
$details = preg_replace('/w(erie|bands?|events?)w/i', "<strong>$1</strong>", $details);
////////////////////Right Here///////////////////////////
$display_block .= "
<h4>$bar <span class="date"> $updated</span></h4>
<p>$details</p>
<div align="right"><span class="map"><a href="$map_url" target="_blank" title="Erie Bar :: $bar">Get Directions</a></span></div>
";
}
}
[/code]
So this changes all of the words in my database?
Is that ok to do?
I don't currently use stripslashes or addslashes so am I still allright?
and is there any way just to echo the results after a query instead of me having to run a script to change it after it is in the database everytime?(if it replaces this stuff in the database)
can I run something like for replacing Erie
[CODE]SELECT REPLACE("Erie","Erie","<strong>Erie</strong>");[/CODE]
and
[CODE]SELECT REPLACE("bars","bars","<strong>Bars</strong>");[/CODE]
this is case sensitive too right?[/QUOTE]
[code=php]
$sql = "SELECT REPLACE(events,"".$searchterm."","<strong>".$searchterm."</strong>") FROM your_table";
[/code]
Now mind you, NogDog and I are giving you two very different approaches to solving this problem. NogDog is recommending a regular expression search which can be cumbersome to manipulate especially if you're dealing with a group environment. My code is recommended for a system w/ a slightly more powerful database but the code tends to be a little easier to understand.[/QUOTE]
[code=php]
$sql = "SELECT REPLACE(events,"".$searchterm."","<strong>".$searchterm."</strong>") FROM your_table";
$result = mysql_query($sql);
while($row=mysql_fetch_array($result,MYSQL_NUM)){
echo $row[0]."<br />";
}//while
[/code]
[code=php]
$sql = "SELECT * FROM $table_name WHERE date
BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
[/code]
[code=php]
$table_name = events
$searchterm = "(bands || band || Erie || bars || bar )";
$sql = "SELECT REPLACE(details,"".$searchterm."","<strong>".$searchterm."</strong>") FROM $table_name WHERE date
BETWEEN DATE_SUB(CURDATE(), INTERVAL 6 DAY) and DATE_ADD(CURDATE(), INTERVAL 1 DAY)";
//details is the details of the event (where I want all the bold text)
[/code]
<strong>(bands || band || Erie || bars || bar )</strong>[/quote]
<strong>(bands || band || Erie || bars || bar )</strong>[/QUOTE]
[CODE]
Vocab Table
|_______________|
Field name: |bold | em |
|_______________|
Data : |"words"|"emword"|
------------------
[/CODE]
0.1.9 — BETA 6.16