Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Select Specific Snippet Of Text, Replace With A Database Result


I'm having some problems trying to do something; I just can't think of a way to do it. Basically, I want to search for a specific snippet of text in a body of text, then replace it with the requested database result with some thrown in HTML.

Users will be able to type the following (or something along these lines, depending on what works best): [image=12345]Insert caption here[/image]

Then I need it to search for the requested image in the appropriate table and return the image's url (for an example, let's say the table is called "images", and the columns required are "imageid" and "imageurl". Code:




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Select Specific Phrase From MYSQL Database
I am working on a World of Warcraft guild's website and I am trying to create a page where players can select different kinds of gear, i.e. the gear with the most Stamina.

All the player's items are stored in the database and every item have a field in the Items-table containing the item's tooltip. This could look something like:

Boots of the Nexus Warden
Soulbound
Feet Cloth
97 Armor
+27 Stamina
+17 Intellect
Durability 35 / 35
Equip: Improves spell hit rating by 18.
Equip: Increases damage and healing done by magical spells and effects by up to 21.

I then want to select the item with i.e. the most Stamina for all the different slots; Head, Chest, Legs etc.

If I write this:
$query = mysql_query("SELECT substring(item_tooltip, LOCATE('Stamina', item_tooltip)) AS maxor FROM roster_items WHERE member_id = ེ'") or die(mysql_error());

It returns the following:
Stamina +17 Intellect Durability 35 / 35 Equip: Improves spell hit rating by 18. Equip: Increases damage and healing done by magical spells and effects by up to 21.

But I want for it to show the leading characters also (in this case "+27 " before "Stamina") and then not show anything else after the phrase "Stamina". So it shows "+27 Stamina" and nothing else for the above mentioned item. How do I accomplish this?

And then, secondly how do I then get it to show only the item with the most Stamina after it selected the above?

Hope this makes any sense.

I've tried to search these forums and found something a little along the lines of my problem but haven't been able to adjust them to my needs and I therefore need your help which will be greatly appreciated.

MySQL - Select Specific Row Based On Unique ID
I am building a photography website in html, and have a pre-formated table in which i want to put a thumbnail pic, the date of the pic, the name, and links to different sizes of the image. In a MYSQL database i have a table with four columns: ID (INT, auto-increment), ImageName (VARCHAR), FileName (VARCHAR), Date (VARCHAR).

I'm just getting started with PHP, and i want to either:

have the information automatically inserted into my pre-made table via a php loop command

or

write a script which will allow me to only enter the id# and will subsequently insert the name and the date into my table, and which might display the image of the filename.

I hope this is clear enough, I've bought quite a large book on PHP and have been browsing forums in an attempt to learn, but i can't find an example that inserts it into a pre-existing table.

SELECT Error: No Database Selectedin Query: SELECT * FROM Schedule
I got the above error message after reading FAQ #10 which applied to my first error. The thing is, I thought I had selected a database. This script is copied from a tutorial, and I'm just too new at this to spot my error. PHP Code:

SELECT Result Sets 20 At A Time
This might be easy but I am trying to list result sets from a SELECT query 20 at time and I am not sure how to handle it.

I want to be able to say
'Displaying results 1-20 of 329' with a link to the next 20.

Select Result On Empty Table?
can't remember how to do this, doing a select on a db like so.

$query = "SELECT user_id FROM tool_user WHERE user_name = '$user_name'";
$query = mysql_query($query) or die("eek");

which will work if there is at least one entry in the database table, however how do i return a result id the table is empty? do i need to use @mysql_query($query) and then something after that?

Hide Specific Text
I was wondering whteher anybody knows a code to hide a specific text on a site which u cannot control.

For Example, i am currently with a free hosting provider, and they put a simple text on my site saying "Free Web Hosting by something" Is there a way to hide this?.

It is not on my actual coding for the page therefore i cannot remove it. I thought there might be a way to block this text or something. It can be a code of any sort like php, html, asp or whatever. I just need to hide this.

Formatting Text For A Specific Width
I have a text file that will be written to with data from end users (text datatype).

The text document is formatted such that there is a column of text around 200px wide, set in the middle of the page.

Is there a way I can (or function that will) format a string (perhaps a paragraph or two) so that it will fit in this text document? Mind that the string is not a constant - it is entered by end users so I can't exactly hard code.
.

MySQL UNION: Only The First Select Statement Returns A Result.
I am attempting to join multiple select statements into a single query.
However, I am not able to extract the result of any of the UNIONED selects.











$query1 = mysql_query ("
(
SELECT SUM(deposits) AS total_deposits
FROM table1
)

UNION ALL
(
SELECT SUM(withdrawals) AS total_withdrawals
        FROM table1
)
")
or die (mysql_error());

$result1 = mysql_fetch_array($query1);
extract($result1);




When I echo the results of the second select statement I get nothing.


echo  $total_withdrawals;

Store Result Of SELECT Stament To Be Used To UPDATE Another Table
im trying to update a field of a table which is done through the results of a select statement. I need to be able to a store the results of the select statement which can then be used to determine if an update another table is initiated. This is where i have got so far: Code:

Text Replace
I have two paragraphs on a page that I want to replace. I've used preg_match_all() to get these paragraphs into an array. This works without issue and was simple as the paragraphs are between HTML comments. The code's shown below. Code:

Is There A Php Command To Take A Specific Field From A Delimited Line Of Text?
I have a string which is multiple fields delimited by commas.

I would like a php command that says... take the 3rd field for
example.

ie. If MYVARIABLE has the data "hello,there,big,world".

I would like to be able to say, pickup the 3rd field "big" without
knowing the character positions or lengths.

How To Echo A Single, Specific Line From A Text File
How do I echo a single, specific line from a text file?  Let's say, for example, the second line?

Search For A Specific Word Inside A Text File?
Basically what i'm trying to do is when a user inputs login/password information at a login page, I want PHP to search inside verify.txt and if it finds the login/password combination then allows the user to proceed. Is this possible? And if so, which functions would I use to get the job done?

Also, how can I save the login name so that it can be passed to/included in a url?

How Do I Replace Text In A String...
I have a form setup to take text from a user and insert it into a MySQL database. The problem lies when the user uses an apostrophe in his text.

The apostrophe causes the mysql_query statement to end early because it thinks the apostrophe is part of the syntax, not knowing it's only part of the value.

Example:

If the user submits the text "I'm from the Shire!" when it's submitted to MySQL it thinks the statement ends at I' and thus causes a failed query.

How can I escape or process these text strings to avoid this?

Replace Text With An Image?
is there anyway to use file_get_contents to search for a text in a websites source code and then when it finds the text stated it displays an image?

Search And Replace In Text File
I have a text file with 30 or so lines. Each line has this format:

sometext somevalue. They are separated by a single space.

I want to search in the file for "sometext" and replace "somevalue" with a particular string.

Eregi Search And Replace For Some Text
I'm trying to do a search and replace for some text. For example, I have a word that is 'history', I want to replace every occurence of 'history' with:

<a href="history.html">history</a>

Now, that's easy, I can do that - however, as 'history' could also be 'History', I want to ensure that the format of 'history' stays the same. For example: $strRep = 'history'

$str = eregi_replace($strRep, '<a href="history.html">'.$strRep.'</a>, $my_other_string);

That's fine - however if history is capitalised (History), then I have a problem:

$str = eregi_replace($strRep, '<a href="history.html">'.$strRep.'</a>, $my_other_string);

because the above example would lowercase History to history.

Replace A Line In A Text File
I would like to replace a single line in a text file. The initially i only had to have a single line so I could just use fputs to rewrite the entire file.  Now I have three lines and want to selectively replace one of them..

Dictionary Search Definition Replace Of Text
I'm trying to search a weather report for matches to the keys in my associative dictionary array and replace them with the $term => $definition.

following is my code. again, any advise appreciated.

REF: full php source PHP Code:

Replace Text Outside Html Syntax Regexp Php
how can i replace text outside a html syntax by using reg exps in php?

I mean i have a text like
<h3>heading</h3>
<p>text</p>
<table>
<tr>
<td>cell1</td>
<td>cell2</td>
</tr>
</table>
or any html code.

now i want all the text outside the syntax (here: heading, text,
cell1, cell2) replaced by a special code like <img...>.

how can i code a reg exp pattern in php, that replaces each character
in the "real text" by an other piece of code, but doesnot change any
of the syntax statements?

Find And Replace Text In Preg_match Array
I'm trying to change a font color html code once my preg_match_all reads the file. Now the code only shows up when a winner has been posted for that tour. Otherwise it's not visible. So I want to search the preg results which is $matches, for the "font color=3FFF5E" and replace it with "font color=FFFFFF". If the code is not found, continue what it was doing. Code:

Preg_Replace, Replace Bits Of Body Text Such As 'XML' With An Acronym
I've got this:

$thebody = preg_replace("/(s¦()".$acronymsfind."()¦s)/",$acronymsreplace,$thebody);

I'm trying to replace bits of body text such as 'XML' with an acronym, but I only want to replace the specific acronyms that start with either:
- a space (s)
- a bracket (( or ))
- a speech mark or inverted comma (" ')

and may end with a full stop (period - .)

I'm not doing right and I've done as much googling and php book reading but still can't do it!

Format Result Text Using Passthru Of System
I tried to use the Passthru and System function to resolve some whois
information.

echo passthru('whois 62.69.168.12') .'<br>'
-or-
$whois = system('whois 62.69.168.12', $retval);

It works fine, but all the result text is at one line. How can i format this
output correctly ?

Search And Replace Database Sites Column
Im trying to search and replace database sites column options with $snr which is set by the user.

Login Snippet
I would like to create a login feature for the Site Admin i.e Me and fellow DJ´s.

But i want it so, when we log it, a picture on the index.html page (DJ Playing Now) will change to the corresponding one. I.E when i log in it displays "djscousey.jpg"  when MC MiniMat logs in it displays mcminimat.jpg etc. etc.

I really am a learner at php, so i thought maybe you guys could put me in the right direction..

Small PHP Snippet
As you can see from the code below its reading from the database fine, it will show two of the first entries in the db. Theres a small peice of code i remember but cant find it, where you can add to the bottom of the script where if there are new entries it will add to the list automatically. Code:

Printing Database Result In Textbox...
I have a textbox with the value $name. I get the $name variable from a database. The result from the database is for example "john anderson" If I echo "$name", I get the correct result(john anderson), but when putting the result in a textbox, only the first word appears. If the result containes any spaces, the word after won't appear. what is wrong?

Xpdf - PHP Script Or Snippet
Will appreciate any example of subject script calling xpdf, any platform...

Print Output Based On Database Result
What I am trying to do is print out an existing text file based on what is in my database.

I want to show/print the contents of text1.inc (which is located in my includes directory) if the database contains query shows it contains "yes" and I want to show/print the contents of text2.inc (which is located in my includes directory) if the database contains query shows it contains "no". Code:

Wrapping Text In SELECT
I have created a SELECT statement with options from a query but I need to wrap the text in one of the fields in the query so it doesn't all appear on one line. How can I go about doing this? code:

echo("<SELECT>");
while($dbrow=mysql_fetch_array($result)){
printf("<OPTION> %s: '%s'", $dbrow["name"], $dbrow["review"]);
printf("</OPTION>");
}
printf("</SELECT> );

Sometimes the $dbrow["review"] will be a couple of lines when it is typed in but when it appears in the SELECT it is all on one line.

CSV File-based Address Book Code Snippet?
Since I'm a PHP newbie and the only address book apps I found
through Google require MySQL or PostgreSQL, I figured I'd ask if
someone has come code handy.

I'd just like to keep a list of addresses in a CSV file (ie. columns
last name, first name, e-mail, office #, etc.) so as to ease backing
up, and read/update this list from a PHP script.

I guess it's pretty much just a loop to read + parse, and a form to
update, but if someone has the code handy, I'm interested :-)

How To Select The First 2 Paragraphs From A Text File
I have a text file which I want to include on the home page of my site but I would only like the first couple of paragraphs.  Is there a way I can select only the first 2 paragraphs even if the text file has many paragraphs? This is only the basic version so far that reads the text file and displays it:

<?php
$myFile = "testFile.txt";
$fh = fopen($myFile, 'r');
$theData = fread($fh, filesize($myFile));
fclose($fh);
echo $theData;?>

Echo Only Select Text From String
I want to echo a single sentence from about the middle of the string what is the easiest way to do this?

Filling A Text Area With Options From A Select Tag
I read a ACCESS db table and the values from one column i use to fill a select tag (all the code is in a php file inside a iFrame tag): Code:

SELECT Statement Results Into Text File
I am trying to create a text file based off the results of a query statement from a database. See code below:

$itemq = "SELECT sdlitm, sddsc1, sduorg, sdlnid, sduncs FROM F4211 WHERE sddoco = $ordernum AND sddcto LIKE '$ordertype' ORDER BY sdlnid";
$result3 = odbc_exec($connect, $itemq);
    while (odbc_fetch_row($result3)){
    $partnum = odbc_result($result3, 1);
    $desc1 = odbc_result($result3, 2);
    $qty = odbc_result($result3, 3)/100;
    $position = odbc_result($result3, 4);
    $uncs = odbc_result($result3, 5);
    $extcost = $uncs*$qty;
    $total = ($total + ($uncs * $qty));
    $filename = "$reportnumber.txt";
    $fp = fopen($filename, "w");
    fwrite($fp, "Activity Number: $reportnumber
");
    fwrite($fp, "Warranty Type: $reason
");
    fwrite($fp, "Customer Name: $custname
");
    fwrite($fp, "$qty $partnum $desc1
");
    fclose($fp);

Everything works fine until I get to the line:

fwrite($fp, "$qty $partnum $desc1
");

This line should actually print multiple lines into the text file as these are the line items from an order. There could be anywhere from 1 to 20 lines written to the text file. As it stands, the only line items written to the text file are those of the last line found on the order. The entrie script dealing with the text file are still within the confines of the while statement curly braces. How do I write these lines out in the text file??

Select Menu OnChange To Update Text Boxes
I've a select menu filled from mySql, So when I change the selection.. I want to change 3 text boxes also by the same row of database that is = to the row of the select menu.

So i tried a lot but failed.. cuz I cant send to javascript the updated values when the selected menu change.

Database Value Select In Combo Box!
This function is intended to display the current database field value as selected.. along with other values as general options.

I can't figure out how to get it work. Help is appreciated!!

function retrieve_category()
{
$cat = mysql_query("SELECT category_id FROM category");
while ($current_row = mysql_fetch_row($cat))
{
$row = $current_row[0];
if ($row == $id)
{
printf("<option selected>%s</option>
",$current_row[0]);
}
else
{
printf("<option>%s</option>
",$current_row[0]);
}
}
}

Populating A Select Box From A Database
I have a subscription database that allows you to edit a subscribers data. For example, you enter a search term like "Bob" and it returns a list of everyone named Bob. You click the one you want and it goes to a subscriber detail page, where all of his data is populated to a form. You can directly edit this form and click save to overwrite it.

The only issue is the select boxes (drop downs) - say I have four options in the drop down box, red, blue, green and black. On my details page for bob I end up with five, I have those four PLUS whatever was saved for his color, so it shows up twice. If Bob is green, my select box looks like:

Green
Red
Blue
Green
Black

How can I make it so that Green only shows up once?

Select One Record From A Database
I am trying to select one record from a database. This databse has like 10 tables. I do not know which table this record is in. What php and mysql syntax would I use to accomplish this?

Randomly Select From Database?
this might seem like a stupid question, i should be able to do this. but on the front page of my site i want a thing to show a few users. but i dont want it to show the same people over and over. i want it to select different people each time. any ideas?

Select From Drop List To Fill Table Column With Text -- HOW ?
I want viewers to compare state laws on a single subject.

Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the column below.
The viewer can select states from the drop down lists above the other two
columns as well. If the viewer selects only one, only one column fills. If
the viewer selects two states, two columns fill. Etc.

I could, if appropriate, have a separate htm page with the text for each
state -- california.htm for example. When the viewer selects California from
the drop down list, the column below would "fill" with California.htm.

Or, I could conceivably use a text or mysql database with two fields for
each record: state_name and law_text -- but it would probably be easier to
use separate htm files, since there will only be about 20 states involved,
and the "database" would never have a large number of records.

The table width would be 100% and each cell would be @33%

My site is designed with FP 2002 and runs on Apache/FreeBSD. I have just had
Apache-ASP installed but I have not yet configured or used the module.

Selective Echoing And Database Select
I have written a search engine for business listings for the company I work for. Each listing is in a database, and that works fine. The problem though is two-fold.

The first part of the problem is that not all listings utilise every column of the database, and this leaves gaps when echoing the results. This is not what i had in mind, Any ideas/help would be appreciated.

The second part of the problem is related to the first in that there is a link for any listing that has a website, but not every listing has a website, so every listing having a "Visit our Site" link is impractical and shoddy. Also, i'm not sure how to echo the url from the database effectively in the first place.

Editing Mysql Database Row With Select Box
I have a small site, this small site has a few categories, now I can add items through my online admin area fine and delete them fine, but when it comes to editting them I am having some trouble, everything is working fine except the category column, because it is a drop down box I do not know how to have the category selected during the creation progress selected all the other info is loaded.

Multiple Select From Database Where Clause
I have a website with a database full of category names...I want to be able to chose lets say 5 of these categories and use a select from database clause where I could simply enter the category names I want to use but am not sure how I would go about doing it.

I can get the list to display just the Aprilia category using the code below:

$data1->q("SELECT * FROM categories WHERE cat_name = 'Aprilia' ORDER BY cat_name asc");

However...how could I get my site to display Aprilia, Ducati, Honda, Suzuki, Yamaha?

Using PHP And MYSQL To Select From Database Using Images
I'm trying to update a main page with a list of details matching a selection from a display of images that are displayed in a small window that have been selected from an image group using a select box in the main window, however I don't know how to do this and the main page is not receiving anything when clicking on an image so it's refreshing with empty data. 

I've seen many many pages giving examples of how to do this with select boxes or how to do this if only one entry uses an image shown in the small window, but the image display window is displaying many different small images not a select box and the database itself has multiple entries that use the same image.  Can anyone help?  I have a few instant chat programs if someone wishes to discuss this with me in real-time to see what it is I'm trying to achieve.

Tick Box, Select And Update Database.
I am trying to change the value in table with a tick box. If the tick box is selected it changes the value in the field to 'y' and if it is not selected it changes the field to 'n'.

First of all I need to bring back the current state of the field and then I need to be able to update it from 'y' to 'n' as many times as I want. Code:

Database Search -text Database...
Can anybody tell me how to search a flat file database delimited by |. I have exploded the data and managed to get it into a table but want to restrict the final table contents by a search.

The table code at the moment is below - I'd be using a htm file to submit the data. and hopefully be able to search by partial searches eg big would return big and bigfoot. Code:

Population Select Menu Using Php And Database Values
I have no idea how to go about this. so i would apreciate some help i want to populate the values in a html select menu from database values in one table

so i want all the values from 1 particular field in the database to be displayed in the select menu as separate options.

Displaying A List Of Categories From A Database In A Select Box
Could someone please tell me why this outputs nothing

<select name=categories>
<?
$cat_array = get_categories();
foreach($cat_array as $this_cat)
{
echo "<option value="";
echo $this_cat["category_id"];
echo """;
echo ">";
echo $this_cat["category_name"];
echo "
";
}
?>
</select>

==========================================================

function get_categories()
{
//get the list of categories from the database

$conn = mysql_pconnect("localhost", "user", "pwd");
$query = "select * from categories";
$result = mysql_query($query);
if(!$result)
return false;

$num_cats = mysql_num_rows($result);
if($num_cats == 0)
return false;

$result = db_result_to_array($result);
return $result;
}

//A function that returns a query to the database as an array
function db_result_to_array($result)
{
$res_array = array();
for($count=0; $row=@mysql_fetch_array($result); $count++)
$res_array[$count] = $row;

return $res_array;
}


Copyright © 2005-08 www.BigResource.com, All rights reserved