473,387 Members | 3,820 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,387 software developers and data experts.

while() and MySQL

I have a database where I use the while() command to iterate through each
row and their resultant arrays to populate a table as the while() command
is executed.

I would like to have in the database a "pointer" that says something like
$MyString, but in the PHP $MyString is given a URL of an image. So every
time during the while() command it comes across the text $MyString it
instead substitutes it for the URL instead of echoing $MyString.

I have tried putting the URL of the image in a few fields directly into the
database, whilst this method does work, it is not the solution I want as
the database fields would start becoming large to cope with the URL instead
of a short VARCHAR declaration.

Does anyone have an idea how to get the text to be substituted while the
while() command is going through an array? The array cannot be "messed"
around with, it has to stay in the order it is being read out of for
display into a table.

My current code looks like:

$Yes = '<img src="tick.png">';

while ($row = @mysql_fetch_array($result))
{
$FName = $row['FeatureName'];
$AccountType1 = $row['Coll-1'];
$AccountType2 = $row['Coll-2'];
$AccountType3 = $row['Coll-3'];
$AccountType4 = $row['Coll-4'];

$entry .= "<tr class=\"BottomLine\"><td
style=\"text-align:left;\"><B>$FName</B></td><td>$AccountType1</td>
etc.etc.
}

Thanks

Dariusz
Jul 17 '05 #1
6 1655
"Dariusz" <ng@lycaus.plusYOURSHIT.com> wrote in message
news:41***********************@ptn-nntp-reader01.plus.net...
I have a database where I use the while() command to iterate through each
row and their resultant arrays to populate a table as the while() command
is executed.

I would like to have in the database a "pointer" that says something like
$MyString, but in the PHP $MyString is given a URL of an image. So every
time during the while() command it comes across the text $MyString it
instead substitutes it for the URL instead of echoing $MyString.
I had a hard time following this and still don't know what it means.
I have tried putting the URL of the image in a few fields directly into the database, whilst this method does work, it is not the solution I want as
the database fields would start becoming large to cope with the URL instead of a short VARCHAR declaration.
This makes no sense to me. What are you trying to store where?
Does anyone have an idea how to get the text to be substituted while the
while() command is going through an array? The array cannot be "messed"
around with, it has to stay in the order it is being read out of for
display into a table.
The text from where?
My current code looks like:

$Yes = '<img src="tick.png">';
This is the only reference I see to an IMG tag.
while ($row = @mysql_fetch_array($result))
{
$FName = $row['FeatureName'];
$AccountType1 = $row['Coll-1'];
$AccountType2 = $row['Coll-2'];
$AccountType3 = $row['Coll-3'];
$AccountType4 = $row['Coll-4'];
Which of these fields is giving you trouble? What's in them?
$entry .= "<tr class=\"BottomLine\"><td
style=\"text-align:left;\"><B>$FName</B></td><td>$AccountType1</td>
etc.etc.
}


I didn't see $MyString anywhere in that example. Nor did I see an example of
the expected input and output.

Try again with a clearer example. Short, complete. I, for one, have no idea
what you tried to ask.

- Virgil
Jul 17 '05 #2
*** Dariusz escribió/wrote (Tue, 14 Sep 2004 15:43:16 GMT):
I would like to have in the database a "pointer" that says something like
$MyString, but in the PHP $MyString is given a URL of an image. So every
time during the while() command it comes across the text $MyString it
instead substitutes it for the URL instead of echoing $MyString.


Do you mean str_replace() ??
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ Las dudas informáticas recibidas por correo irán directas a la papelera
-+ I'm not a free help desk, please don't e-mail me your questions
--
Jul 17 '05 #3
In article <L1****************@newssvr22.news.prodigy.com>, "Virgil Green" <vj*@DESPAMobsydian.com> wrote:
Okay, I'll try re-writing the text.

Basically, if I have in the database "$MyString" entered as text, when the
while() loop is processing the array to make a HTML table, every time it
comes across "$MyString" text from ANY part of ANY array, it should write
the contents of the $MyString variable already declared instead of just
writing the text "$MyString" into the table which the loop constructs as it
reads the database. The way the table is constructed can't be changed.

So when the PHP is processed, the HTML should read:

<td><img src="yes.png"></td>
<td>sometext</td>
<td>moretext</td>
<td><img src="yes.png"></td>

and not

<td>$MyString</td>
<td>sometext</td>
<td>moretext</td>
<td>$MyString</td>

Hope that is a bit clearer.

Dariusz
Jul 17 '05 #4
> So when the PHP is processed, the HTML should read:

<td><img src="yes.png"></td>
<td>sometext</td>
<td>moretext</td>
<td><img src="yes.png"></td>

and not

<td>$MyString</td>
<td>sometext</td>
<td>moretext</td>
<td>$MyString</td>


echo or print or whatever command you use with double quotes"text" instead
of single quotes 'text'.
$name="Dariusz";
echo 'Hi, my name is $name';
results in: Hi, my name is $name
but
echo "Hi, my name is $name";
results in Hi, my name is Dariusz

Polaris.



Jul 17 '05 #5
In article <41**********************@dreader2.news.tiscali.nl >, "Polaris" <as*********@hotmail.com> wrote:
echo or print or whatever command you use with double quotes"text" instead
of single quotes 'text'.


I have already thought of this problem, but it was not it.

However, I have since done a LOT of digging and found a partial solution
which if solved would be ideal.

Current code:

while ($row = @mysql_fetch_array($result))
{
$FName = $row['FeatureName'];
if (in_array("Yes", $row))
{
$row = '<img src="tick.png" width="38" height="18">';
}
$AccountType1 = $row['Coll-1'];
$AccountType2 = $row['Coll-2'];
$AccountType3 = $row['Coll-3'];
$AccountType4 = $row['Coll-4'];

$display_entry .= "<tr class=\"BottomLine\">
<tdstyle=\"text-align:left;\"><B>$FName</B></td>
<td>$AccountType1</td>
<td>$AccountType2</td>
<td>$AccountType3</td>
etc...
So now as the array is being read, every time the word "Yes" is
encountered, it is replaced in Coll-1, Coll-2, Coll-3, Coll-4. The problem
is though that is is not 100% working. Instead of replacing the entire
string (which in this case is a URL for an image), it is just echoing "<"
(minus quotes). Playing about I find that it is only echoing the first
character of the string.

So I have a table that had a lot of Yes's replaced by < instead of the url
which would show that graphic.

Any suggestions?

Dariusz
Jul 17 '05 #6
"Dariusz" <ng@lycaus.plusYOURSHIT.com> wrote in message
news:41***********************@ptn-nntp-reader02.plus.net...
In article <L1****************@newssvr22.news.prodigy.com>, "Virgil Green" <vj*@DESPAMobsydian.com> wrote: Okay, I'll try re-writing the text.

Basically, if I have in the database "$MyString" entered as text, when the
while() loop is processing the array to make a HTML table, every time it
comes across "$MyString" text from ANY part of ANY array, it should write
the contents of the $MyString variable already declared instead of just
writing the text "$MyString" into the table which the loop constructs as it reads the database. The way the table is constructed can't be changed.

So when the PHP is processed, the HTML should read:

<td><img src="yes.png"></td>
<td>sometext</td>
<td>moretext</td>
<td><img src="yes.png"></td>

and not

<td>$MyString</td>
<td>sometext</td>
<td>moretext</td>
<td>$MyString</td>

Hope that is a bit clearer.


Just barely. Where did the text '<img src="yes.php">' come from? Is the
variable name you want to use always $MyString? Is that the only variable?
Are you trying to use any "variable" placed inside the data in your
database? Where does $MyString get populated?

That said, I suspect you want to use a regular expression to find any string
in your data that starts with $ up to the next space. That can then be
extracted into a variable. You can then use $$ syntax to reference a field
of the same name. That can be used to so a str_replace into the original
data.

$myfield = (some regular expression extraction I don't want to look up right
now);
$mydata = $$myfield;
$newdata = str_replace($myfield, $mydata, $dbfdata);
echo $newdata;

Just a thought and a guess. No testing has even been attempted.

- Virgil
Jul 17 '05 #7

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

Similar topics

4
by: Damien Renwick | last post by:
I have a php script which simply stops midway through a while loop that processes records returned by a MySQL query. The HTML page continues trying to load the page but the php has stopped running...
0
by: Christian.Gruber | last post by:
>Description: It would be nice if general query logging could be switched on and off while the MySQL server is running, and not only at startup time. While debugging an application that uses...
0
by: Moritz Steiner | last post by:
Ok, but this only works for the current session, if I close and restart = the client the settings are reset... -----Urspr=FCngliche Nachricht----- Von: Victoria Reznichenko =20 Gesendet:...
0
by: Sagar, Sanjeev | last post by:
------_=_NextPart_000_01C34BD8.C9973A3A Content-Type: text/plain Hello All, I am using Mysql 4.0.13-max-log on Solaris 2.8 If I run mysqldump like below /usr/local/mysql/bin/mysqldump -u...
0
by: Brian Reichert | last post by:
On another mailing list, there is a discussion about whether or not it is adequate/proper to manage the MySQL server process via a watchdog script (namely, DJB's daemontools). The point behind...
4
by: James E Koehler | last post by:
I can't get the WHILE statement to work in MySQL. The version of MySQL that I am using is: Ver 12.16 Distrib 4.0.6-gamma, for Win95/Win98 (i32) running on Windows MX. Here is the relevant...
1
by: Haffi | last post by:
hi, I have a proplem creating a new user and/or adding additional information for root user in MySQL Administrator 1.0.19. When I do I get this message: error while storing the user information....
1
by: Trygve Lorentzen | last post by:
Hi, my webservice is running on Win2000 SP4, IIS 5.0 fully patched, connecting to a MySQL database and mainly returning Typed DataSet's from webmethods. After running for a while, generally a...
5
by: gooderthanyou | last post by:
Alright i've looked a ton of topics and most of them are unresolved... configure: error: Cannot find MySQL header files under usr/local/mysql. Note that the MySQL client library is not bundled...
0
by: hikinchi | last post by:
i have problem to connect vb and mysql... 1) i want to build program to compare data from text file and from mysql. I don't know how to use command from vb to through into mysql.. anyone can help...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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.