467,081 Members | 1,231 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,081 developers. It's quick & easy.

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
  • viewed: 1482
Share:
6 Replies
"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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Damien Renwick | last post: by
reply views Thread by Christian.Gruber@biomax.de | last post: by
reply views Thread by Moritz Steiner | last post: by
reply views Thread by Sagar, Sanjeev | last post: by
reply views Thread by Brian Reichert | last post: by
4 posts views Thread by James E Koehler | last post: by
5 posts views Thread by gooderthanyou@gmail.com | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.