SQL resultaten optellen [SNEL!]

Gestart doorAntonn6 reacties25 weergaven

7 berichten · pagina 1 van 1

Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$totalcr_sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM `crlog` WHERE `user_id` = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" AND `credits` LIKE +% OR `bericht` = Aankoopgeschiedenis systeem opgestart AND `user_id` = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" OR `bericht` = Start aantal credits AND`user_id` = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]""[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$totalcr_rows[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$totalcr_sql[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$totalcr_rows[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) {[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$totalcr_row[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$totalcr_sql[/COLOR][COLOR= #007700])) {[/COLOR]
[COLOR= #0000BB]$cronll[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/str_replace"]str_replace[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"+"[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #DD0000]""[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$totalcr_row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]credits[/COLOR][COLOR= #007700]]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$cronll[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #FF8000]// Hoe tel ik elke $cronll te samen op???[/COLOR]
[COLOR= #007700]}
}[/COLOR]
?>


Ik wil de resultatan van de SQL optellen. Ik kan dit doen met SUM(), maar hij moet de plus wegwerken d.m.v. str_replace(). Dus dit is niet mogelijk. Iemand enig idee? Heb het nogal snel nodig bloos
0
Berichten
6.144
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$totalcr_sql = mysql_query("SELECT * FROM `crlog` WHERE `user_id` = ".$_SESSION[id]." AND `credits` LIKE +% OR `bericht` = Aankoopgeschiedenis systeem opgestart AND `user_id` = ".$_SESSION[id]." OR `bericht` = Start aantal credits AND`user_id` = ".$_SESSION[id]."");
$totalcr_rows = mysql_num_rows($totalcr_sql);
if ($totalcr_rows > 0) {
$i = 0;
while($totalcr_row = mysql_fetch_assoc($totalcr_sql)) {
$cronll = str_replace("+", "", $totalcr_row[credits]);
$i++;
echo $cronll;
// Hoe tel ik elke $cronll te samen op???
}
echo $i;
}
?>
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Jponsen schreef:
$totalcr_sql = mysql_query("SELECT * FROM `crlog` WHERE `user_id` = ".$_SESSION[id]." AND `credits` LIKE +% OR `bericht` = Aankoopgeschiedenis systeem opgestart AND `user_id` = ".$_SESSION[id]." OR `bericht` = Start aantal credits AND`user_id` = ".$_SESSION[id]."");
$totalcr_rows = mysql_num_rows($totalcr_sql);
if ($totalcr_rows > 0) {
$i = 0;
while($totalcr_row = mysql_fetch_assoc($totalcr_sql)) {
$cronll = str_replace("+", "", $totalcr_row[credits]);
$i++;
echo $cronll;
// Hoe tel ik elke $cronll te samen op???
}
echo $i;
}
?>

Ik wil niet weten de hoeveelste die is, maar $cronll is een getal. En ik wil elke cronll te samen optellen.
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je kunt ook gewoon deze query gebruiken, die heeft het als resultaat al bij elkaar opgeteld.

[COLOR= #0000BB]<?php
$totalcr_sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT SUM(credits) FROM `crlog` WHERE `user_id` = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" AND (`credits` LIKE +% OR `bericht` = Aankoopgeschiedenis systeem opgestart OR `bericht` = Start aantal credits)"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$cronll[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_result"]mysql_result[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$totalcr_sql[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR]
?>
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sjoerd schreef:
Je kunt ook gewoon deze query gebruiken, die heeft het als resultaat al bij elkaar opgeteld.
[COLOR= #0000BB]<?php
$totalcr_sql[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT SUM(credits) FROM `crlog` WHERE `user_id` = "[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$_SESSION[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]id[/COLOR][COLOR= #007700]].[/COLOR][COLOR= #DD0000]" AND (`credits` LIKE +% OR `bericht` = Aankoopgeschiedenis systeem opgestart OR `bericht` = Start aantal credits)"[/COLOR][COLOR= #007700]);[/COLOR]
[COLOR= #0000BB]$cronll[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_result"]mysql_result[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$totalcr_sql[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]);[/COLOR]
?>
Vriendje schreef:
Ik wil de resultatan van de SQL optellen. Ik kan dit doen met SUM(), maar hij moet de plus wegwerken d.m.v. str_replace(). Dus dit is niet mogelijk. Iemand enig idee? Heb het nogal snel nodig bloos
0
Berichten
13.482
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Maar hij werkt toch gewoon? Bij mij iig wel, ik heb het namelijk getest...

toevoeging op 16 januari 2012, 191444:
Desnoods kun je SUM(credits) nog vervangen door SUM(Replace(credits, +, )) , maar dat moet niets uitmaken..
0
Antonn

Lid · Topicstarter

Berichten
8.649
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Sjoerd schreef:
Maar hij werkt toch gewoon? Bij mij iig wel, ik heb het namelijk getest...
toevoeging op 16 januari 2012, 191444:
Desnoods kun je SUM(credits) nog vervangen door SUM(Replace(credits, +, )) , maar dat moet niets uitmaken..

Dus als er in de db +4 staat rekent die dat gewoon als 4? Ahja,snap al. Net als -4 xp ty. Check me laatste topics miss ns? xd voor mijn part kan hier slotje op!
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren