$result = mysql_query ("select * from table");
while ($row = mysql_fetch_object ($result))
{
$dscore = strtok ($row->score, "-");
$oscore = strstr ($row->score, "-");
$oscore = ereg_replace ("\-", "", $oscore);
if ($dscore > $oscore)
{
show me the money! err, rows
}
else
{
}
}
$row->score is formatted like xxx-xxx (ie: 500-300), the strok and strstr seperates them to make them their own variable. My question is: how can I find the number of rows that contain a score $dscore that is higher then $oscore? I can't (at least I think I can't) find this out through the mysql_query since it finds out what row->score is AFTER the query.
Unfortuantly that will just say "111", which is half right, since it's displaying 1 three times, and there are 3 rows that match what I'm looking for, but how can I make it display "3" instead? I'm awful with arrays, I haven't used them much before, and I suspect that's what I'm gonna be using for this
sorry I can't get this to display the plus sign. There should be two plus signs after $dscoreTotal and $oscoreTotal; This will increment $dscoreTotal by one.
if you need both part as separate values why don't you store them like that? Two fields, both ints, called dscore and oscore and you can do all this with simple sql.
how many records with dscore>oscore are there SELECT count(*) from table WHERE dscore>oscore
get all those record SELECT * from table WHERE dscore>oscore
sum them up SELECT SUM(dscore), SUM(oscore) from table WHERE dscore>oscore
maximum scores SELECT MAX(dscore), MAX(oscore) from table
volka wrote:if you need both part as separate values why don't you store them like that? Two fields, both ints, called dscore and oscore and you can do all this with simple sql.
When I designed the database and entered all the rows, I didn't plan on retreiving the way I am now. I was going to pull the info just as $row->score and it would display it as xxx-xxx, but the new site I'm working on is much different than the old one. I didn't feel like modifying 30plus (damn forum bug) rows
First alter the table to add the fields (allow NULL value)
change INSERT,UPDATE,REPLACE-statements to also insert the numerical values
write a simple script that updates existing records
replace the SELECT statements and/or insert code right after the ..._fetch_... statements that will add the score-field to the result set, created by $...dscore.'-'.$...oscore (would be easier with the array-version of ..._fetch_... ), even if there is already such a field.
find code that uses $...score and replace it by code that uses $...dscore and $...oscore
when certain that all code has been replaced you can change the db-field-settings to NOT NULL and remove the $...score=$dscore.'-'.$oscore