How many replies can we get??

Status
Not open for further replies.
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... :eek: these guys were brave... i think the Stratos had a bit more power in the rallies, something like 360-370hp... the beggining of Group B.
 
Originally posted by MistaX

But the car won Monte Carlo 4 times or somthing!

The street version wouldn't have. Hang on. I've got a book on rally cars downstairs. And some more beers. Bear with me, I'll get back to you!
 
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?

Yeah, but wont that just print it out right where its at?

I need it to be called by an str_replace()... it would be like this:

$var = str_replace("{data}","$while",$result);


Where $while would be this:

while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td></tr>\n", $myrow[1], $myrow[2], $myrow[3]);
}

So that i could call it in its respective place to replace it in the document..
 
cj_8185.jpg
 
OK, here we go. From Reinhard Klein's Rally Cars:
Lancia Stratos HF
First Round: 1972 Tour de Corse
Group: 4
Engine: V6 65deg
Position: ML
Capacity: 2418cc
BHP@RPM: 240@7800
NM@RPM: 275@6000
Weight: 960KG

Lancia Stratos HF 24v
Group 4
Engine: V6 65deg
Position: ML
Capacity: 2418cc
BHP@RPM: 290@8000
NM@RPM: 300@6000
Weight: 970KG

Hope that helps you!
 
Originally posted by gt2_gs


Yeah, but wont that just print it out right where its at?

Yes. You hadn't mentioned the str_replace() at this point! :)

I need it to be called by an str_replace()... it would be like this:

$var = str_replace("{data}","$while",$result);


Where $while would be this:

{
printf("<tr><td>%s %s</td><td>%s</td></tr>\n", $myrow[1], $myrow[2], $myrow[3]);
}

So that i could call it in its respective place to replace it in the document.. [/B][/QUOTE]

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 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!

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 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?

Is {string} constant, or is it variable?
 
Originally posted by GilesGuthrie


Is {string} constant, or is it variable?

{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 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
So you're putting data into the database that contains placeholders for other data?
 
Originally posted by GilesGuthrie
So you're putting data into the database that contains placeholders for other data?

yeah, then 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 gt2_gs
...do you get what i am saying? or have i lost you?

Well you defnitely lost me....... :confused:
Hehe, you're talking Chinese to me, man. :D
 
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..
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 GCstyle


Well you defnitely lost me....... :confused:
Hehe, you're talking Chinese to me, man. :D

It's PHP. It's the foundation stone of this site, and it rocks! Unfortunately, gt2 is trying to take his database, and get my mind to work out how to read and format the data, but I'm not sure I follow what he's trying to do, and I'm not that good at PHP anyway!

Still, it distracts me from the fact that I still haven't worked out what I want to do with my own site!
 
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.

You kinda confused me with all the needle stuff... can you kindly re-elaborate?
 
Originally posted by gt2_gs


You kinda confused me with all the needle stuff... can you kindly re-elaborate?

You're searching for a rusty old needle in a haystack. When you find the needle, you wish to replace it with a shiny new one.

Now YOUR trouble is that you're not sure what the old needle or the new needle look like, you're just planning on sorting it out when you get there.

As a result, you're trying to do too much in your call to str_replace(), which is the bit that does the searching through the haystack. My suggestion is that before you start searching, you actually work out what the old needle (the bit you're trying to find) and the new needle (the bit that you want to put in) actually are. This will allow you to write a simple call to str_replace(), which will make its life easier.

So you need to tell str_replace() what to look for, and what to replace that with, and I'm suggesting that you enter into a dialogue thus:

Take my string ($stringtoprint) and set it to the following:
Take the haystack, and look through it until you find something ... a rusty old needle ... and then replace that with ... a shiny new needle ...

The bits between the dots representing the PHP code going into a function to calculate what it is you're looking for, and what you're going to replace it with.
 
So it would be like this:


function inputreplace($old)
{
while ($myrow = mysql_fetch_row($result)) {
printf("<tr><td>%s %s</td><td>%s</td></tr>\n", $myrow[1], $myrow[2], $myrow[3]);
}
return $new;
}
$racerlist = mysql_query("SELECT * FROM `Racerlist` ORDER BY `Points` DESC",$sdb);
$string = "{input}";
$content = str_replace($string, inputreplace($string), $haystack);
echo $content;
 
Status
Not open for further replies.
Back