function getMaterias($idCarreras, $pDibujo)
{
    $sql = 'SELECT DISTINCT  `semestre` FROM  `Materias` WHERE  `idCarreras` = ' . $idCarreras;
    try {
        $db = conectar();
        $stmt = $db->query($sql);
        $datos = $stmt->fetchAll();
        foreach ($datos as $row) {
            $semestre = $row['semestre'];
            $mate = (string) getMate($idCarreras, $semestre);
            echo '<div class="col-lg-4 col-md-6">
     <div class="panel panel-primary">
     <div class="panel-heading">
     <div class="row">
     <div class="col-xs-3">
     <i class="' . $pDibujo . '"></i>
     </div>
     <div class="col-xs-9 text-right">
     <div class="huge">' . $semestre . '</div>
     <div>Semestre</div>
     </div>
     </div>
     </div>
     <a href="#">
     <div class="panel-footer">

     <a class="dropdown-toggle" data-toggle="dropdown" href="#" data-sem="' . $semestre . '" data-car="' . $idCarreras . '">
     <span class="pull-left">Materias</span>
     <span class="pull-right">                                    <i class="fa fa-arrow-circle-right"></i>
     </span>
     <div class="clearfix"></div>
     </a>
     <ul class="dropdown-menu dropdown-messages" id="mat' . $semestre . '" >
     ' . $mate . '   
     </ul>
     </div>
     </a>
     </div>
     </div>
     </div>';
        }
        $db = null;
    } catch (PDOException $e) {
        echo 'Error: ' . $e->getMessage();
    }
}
function getMate($idCarreras, $semestres)
{
    $sql = 'SELECT * FROM  Materias WHERE  idCarreras=' . $idCarreras . ' AND semestre =' . $semestres;
    try {
        $db = conectar();
        $stmt = $db->query($sql);
        $datos = $stmt->fetchAll();
        foreach ($datos as $row) {
            $idCarreras = $row['idCarreras'];
            $Nombre = $row['Nombre'];
            $Creditos = $row['Creditos'];
            $semestre = $row['semestre'];
            echo '
     <li>
        <a href="#">
          <div>
            <strong>' . $Nombre . '</strong>
          </div>
        </a>
      </li>
     <li class="divider"></li>  ';
        }
        $db = null;
    } catch (PDOException $e) {
        echo 'Error: ' . $e->getMessage();
    }
}
$pidCarreras = $_GET["idCarreras"];
$psemestre = $_GET["sem"];
getMate($pidCarreras, $psemestre);