Jump to content
alexarpad2003

Medie (php)

Recommended Posts

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/>";

  • Upvote 1
Link to comment
Share on other sites

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)

Link to comment
Share on other sites


$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 by alexarpad2003
Link to comment
Share on other sites


$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 citeste

Edit :

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 by Robert1995
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...