alexarpad2003 Posted October 13, 2011 Report Share Posted October 13, 2011 Am urmatorul cod :<?php$note="10(10.02.2011), 4(12.03.2011), 5(10.02.2011)";$note1=explode(",",$note);$count=count($note1);echo "numar note : ".$count;?>Cum as putea sa ii dau explode la $note altfel incat sa-mi returneze doar notele(10, 4, 5) ca apoi sa pot face media (10+4+5):3 ? Quote Link to comment Share on other sites More sharing options...
ROFL Posted October 13, 2011 Report Share Posted October 13, 2011 <?php$suma = NULL;$note = array("10(10.02.2011)", "4(12.03.2011)", "5(10.02.2011)");$count = count($note);foreach($note as $nota){ $x = explode("(", $nota); $x = $x[0]; $suma += $x;}$media = $suma/$count;echo $media;?> 1 Quote Link to comment Share on other sites More sharing options...
tdxev Posted October 13, 2011 Report Share Posted October 13, 2011 or: $note="10(10.02.2011), 4(12.03.2011), 5(10.02.2011)";$note1= explode(",",$note);foreach($note1 as $value){ $x = explode('(', $value); $noteValues[] = $x[0];}$media = array_sum($noteValues) / count($noteValues);$count=count($note1);echo "numar note : ".$count;echo "<br/> Media: $media <br/>"; 1 Quote Link to comment Share on other sites More sharing options...
alexarpad2003 Posted October 13, 2011 Author Report Share Posted October 13, 2011 Merci mult +rep Quote Link to comment Share on other sites More sharing options...
alexarpad2003 Posted October 13, 2011 Author Report Share Posted October 13, 2011 Mai revin cu o intrebare :Am in db campuri care incep cu sem1_ , cum fac sa-mi afiseze doar aceste campuri dar cu conditia ca ele sa fie completate, dar sa-mi anuleze si textul care il scriu in html daca campurile sem1_ din db sunt goale. Exemplu :Limba romana : $row_user['sem1_romana']Matematica : $row_user['sem1_matematica']Informatica : $row_user['sem1_informatica']Afisare html:Limba romana : 10(10.02.2011), 4(12.03.2011), 5(10.02.2011)Matematica : Informatica : 10(10.02.2011), 4(12.03.2011), 5(10.02.2011)Deci vreau matematica sa nu-mi mai afiseze.Limba romana : 10(10.02.2011), 4(12.03.2011), 5(10.02.2011)Informatica : 10(10.02.2011), 4(12.03.2011), 5(10.02.2011) Quote Link to comment Share on other sites More sharing options...
UnixDevel Posted October 13, 2011 Report Share Posted October 13, 2011 where $matematica !="" sau !=NULLasa o pui in sql qery ..acuma depinde si de structura bazei de date Quote Link to comment Share on other sites More sharing options...
alexarpad2003 Posted October 13, 2011 Author Report Share Posted October 13, 2011 (edited) $get_user=mysql_query('SELECT * FROM database WHERE username="'.$_SESSION["s_username"].'" AND password="'.$_SESSION["s_password"].'" '); if(mysql_num_rows($get_user) > 0) { $row_user = mysql_fetch_array($get_user);......... <table cellspacing="0" cellpadding="0"> <tr> <td width="30" align="center"></td> <td width="160" align="center">Limba romana</td> <td width="440" align="center">'.$row_user['sem1_romana'].'</td> <td width="90" class="media">'.$medie_romana.'</td> </tr> <tr> <td width="30" align="center"></td> <td width="160" align="center">Matematica</td> <td width="440" align="center">'.$row_user['sem1_matematica'].'</td> <td width="90" class="media">11111</td> </tr> <tr> <td width="30" align="center"></td> <td width="160" align="center">Informatica</td> <td width="440" align="center">'.$row_user['sem1_informatica'].'</td> <td width="90" class="media">11111</td> </tr>..........Stiu ca trebuie pusa o conditie(if), dar nu stiu cum sa o scriu.Deci daca '.$row_user['sem1_matematica'].' nu rezulta nimic, vreau ca randul <tr> <td width="30" align="center"></td> <td width="160" align="center">Matematica</td> <td width="440" align="center"> '.$row_user['sem1_matematica'].'</td> <td width="90" class="media">11111</td> </tr>sa nu mi-l afiseze.LE : Nimeni nimic ? O idee macar, nu vreau mura in gura. Edited October 14, 2011 by alexarpad2003 Quote Link to comment Share on other sites More sharing options...
Robert1995 Posted October 15, 2011 Report Share Posted October 15, 2011 (edited) $get_user=mysql_query('SELECT * FROM database WHERE username="'.$_SESSION["s_username"].'" AND password="'.$_SESSION["s_password"].'" ');Sa vedem ce faci tu e cea mai mare porcarie care am vazut-o in viata mea , stii ce e ala "id" ? ala se stocheaza in sesiune nimic altceva , sesiunea se poate fura , cum ai pus tu username si password acolo , "periclitezi " ( nu stiu daca am scris bine ) securitatea site-ului , inainte sa te apuci sa scrii cod , macar o carte citesteEdit : Uite o baza de date frumoasa care daca o stii integra face niste query-uri , poate un join ?toata chestia asta e basic SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;USE `mydb` ;-- ------------------------------------------------------- Table `mydb`.`user`-- -----------------------------------------------------CREATE TABLE IF NOT EXISTS `mydb`.`user` ( `id` INT NOT NULL AUTO_INCREMENT , `username` VARCHAR(100) NOT NULL , `password` VARCHAR(100) NOT NULL , PRIMARY KEY (`id`) )ENGINE = InnoDB;-- ------------------------------------------------------- Table `mydb`.`materie`-- -----------------------------------------------------CREATE TABLE IF NOT EXISTS `mydb`.`materie` ( `id` INT NOT NULL AUTO_INCREMENT , `nume` VARCHAR(100) NOT NULL , PRIMARY KEY (`id`) )ENGINE = InnoDB;-- ------------------------------------------------------- Table `mydb`.`medie`-- -----------------------------------------------------CREATE TABLE IF NOT EXISTS `mydb`.`medie` ( `id` INT NOT NULL , `user_id` INT NOT NULL , `materie_id` INT NOT NULL , `nota` FLOAT NOT NULL , `creation_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`id`) , INDEX `fk_medie_user` (`user_id` ASC) , INDEX `fk_medie_materie1` (`materie_id` ASC) , CONSTRAINT `fk_medie_user` FOREIGN KEY (`user_id` ) REFERENCES `mydb`.`user` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT `fk_medie_materie1` FOREIGN KEY (`materie_id` ) REFERENCES `mydb`.`materie` (`id` ) ON DELETE NO ACTION ON UPDATE NO ACTION)ENGINE = InnoDB;SET SQL_MODE=@OLD_SQL_MODE;SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS; Edited October 15, 2011 by Robert1995 Quote Link to comment Share on other sites More sharing options...