- 25,298
- Somewhere.
Originally posted by MistaX
But the car won Monte Carlo 4 times or somthing!
but keep in mind the Stratos was mid-engined... 240hp on 2 wheels in the snow and ice...
Originally posted by MistaX
But the car won Monte Carlo 4 times or somthing!
Originally posted by MistaX
But the car won Monte Carlo 4 times or somthing!
Originally posted by gt2_gs
i wonder if giles seen my post...
Originally posted by GilesGuthrie
I think you want to do this after the mysql_query statement:
$noofrows = mysql_numrows($result)
for($i = 0; $i<$noofrows; $i++)
{
$myrow = mysql_fetch_row($result);
printf("<tr><td>%s %s</td><td>%s</td></tr>\n", $myrow[1], $myrow[2], $myrow[3]);
}
Make sense? Or does that send you off in a different direction?
Originally posted by MistaX
Look what i started.....
Originally posted by PunkRock
i'm sure they were crazy things to drive...
![]()
Lanica StratosOriginally posted by GCstyle
Haha...... what the heck is that thing??![]()
Originally posted by gt2_gs
Yeah, but wont that just print it out right where its at?
Originally posted by MistaX
Lanica Stratos
Originally posted by GilesGuthrie
Yes. You hadn't mentioned the str_replace() at this point!![]()
If you have while ($myrow = mysql_fetch_row($result)) , this will set $myrow to be equal to the fetched row, and this will always be true - it's an operator, not a condition. By the same token, if you write this as a condition, i.e. while ($myrow == mysql_fetch_row($result)) , this will never be true, so the while statement will not run.
You've written the code to format the output from the while loop into table cells. Your printf() statement will write the data out to the browser immediately. But you are implying that you wish to transform the data you're fetching before it's sent to the browser, which your code won't do.
I think you may need to think about this as being a set of discrete steps, starting with fetching the raw data from the database, and ending with writing the transformed data to the browser. Think of it in as many small steps as possible, rather than as few big steps. I'm getting tied up in your logic, and I think you might be trying to do too much at once.
Or alternatively I'm just stupid!
Originally posted by gt2_gs
well, to better tell you what i am trying to do is this, i am trying to read in data from a database, and replace {string} with a list of things in a mysql database.
Example:
i have this table:
Name -- Area -- Yadda ydda..
-----------------------------
Terd -- Jabb -- yadda..
Terd3 -- adsf -- asdf
I want to read in every row and all its contents in to replace {string} in the data read in from the database, then print it out... is it possible?
Originally posted by GilesGuthrie
Is {string} constant, or is it variable?
So you're putting data into the database that contains placeholders for other data?Originally posted by gt2_gs
{string} is read in with the data from the database, say the data in a row in the db is this:
BLablabl here is the data, kiss my ass.. {string}
And the {string} when read in would be replaced before getting printed out
Originally posted by GilesGuthrie
So you're putting data into the database that contains placeholders for other data?
Originally posted by gt2_gs
...do you get what i am saying? or have i lost you?
OK, now I get it.Originally posted by gt2_gs
no, the data is being read in from the database, but before it is printed out for the user to see, the {string} is changed to data from another database, as a list..
Originally posted by GCstyle
Well you defnitely lost me.......
Hehe, you're talking Chinese to me, man.![]()
Originally posted by GilesGuthrie
OK, now I get it.
You're reading a Haystack from the database, which contains a needle. You want to replace the needle, with a newneedle, which is also in the database.
But newneedle itself consists of a number of records which you wish to bind together to preformat before using this as the newneedle in your str_replace() call.
This is a two stage process which you're probably going to do with nested for or while loops. Get the code that generates the newneedle working first, then put it in a function, which you can call from within str_replace, kind of like this:
function generatenewneedle($oldneedle)
{
[ the code to generate the new needle goes here]
return $newneedle;
}
$haystack = get the data from the database
$needle = placeholder (you have to define this when you're entering the haystack into the database)
$stringtoprint = str_replace($needle, generatenewneedle($needle), $haystack);
echo $stringtoprint;
It's worth taking time trying to build the string first, before trying to print it.
Originally posted by gt2_gs
You kinda confused me with all the needle stuff... can you kindly re-elaborate?