Jump to content

ginerjm

Members
  • Posts

    5,847
  • Joined

  • Last visited

  • Days Won

    83

ginerjm last won the day on April 19

ginerjm had the most liked content!

4 Followers

About ginerjm

  • Birthday 03/23/1952

Profile Information

  • Gender
    Male
  • Location
    Voorheesville NY

Recent Profile Visitors

61,585 profile views

ginerjm's Achievements

Prolific Member

Prolific Member (5/5)

312

Reputation

51

Community Answers

  1. Me neither. I think it might have something to do with large projects that involve many scripts and many variables and I'm thinking namespace is a way of avoiding collisions with names.
  2. Because I saw the binds I didn't even notice that he was using PDO. Surprised!! Yes - you are right. The array method is so much easier and using a list to capture the query results is even easier than the bind.
  3. Did you check if you got a row from your query? Do you have error checking enabled? // Attempt Log In $submit = $_POST[ 'submit' ]; if ( $submit == 'Log In' ) { $username = $_POST[ 'username' ]; $password = sha1( $_POST[ 'password' ] ); // echo "Your username is ".$username.' and your password is '.$password; $sql = $dbh->prepare( "select username from fr_admin where username = ? and password = ?" ); $sql->bindValue( 1, $username, PDO::PARAM_STR ); $sql->bindValue( 2, $password, PDO::PARAM_STR ); IF (!$sql->execute()) { print_r($sql->errorInfo()); EXIT(); } // execute ran. // did we get a row back? if ($sqlresults = $sql->fetch()) { $uname = $sqlresults[ 'username' ]; if ($uname == $username) // WHY THIS TEST??? YOU JUST ASSIGNED THE VALUE SO IT HAS TO BE == { $_SESSION[ 'admin' ] = 'authorized'; $_SESSION[ 'username' ] = $username; } else { echo '<p class="text-danger"><strong>There was a problem logging in. Please try again!</strong></p>'; } } This is the only part I think that we are interested in...
  4. Still discussing this when what I gave you days ago solved all of your problems? A single script that displayed the blank form, validated the data and processed it without using JS if you didn't want to.
  5. I have created a "grading table" that declared my low marks, high marks, grade and comment. I also have my result table with the following column label 'id','subjectid','studentid','grades', 'comments'; to store the input results. My problem now is to create the php code to store what ever score that is entered and compare it with the assigned grades in the database. Below is my code

       


     

    {
            
            $marks=array();
        $class=$_POST['class'];
        $studentid=$_POST['studentid']; 
        $mark=$_POST['marks'];
        $grades=$_POST['grades'];
        $comments=$_POST['comments'];
        //coding
        
        $sum=$mark*10; //total marks
            $avg=$sum;
            if($avg>=0&&$avg<=50)
                $grades="Fail";
            if($avg>50&&$avg<=70)
                $grades="C";
            if($avg>70&&$avg<=80)
                $grades="B";
            if($avg>80&&$avg<=90)
                $grades="A";
            if($avg>90)
                $grade="E";
        //end
        
        
        
         $stmt = $dbh->prepare("SELECT tblsubjects.SubjectName,tblsubjects.id FROM tblsubjectcombination join  tblsubjects on  tblsubjects.id=tblsubjectcombination.SubjectId WHERE tblsubjectcombination.ClassId=:cid order by tblsubjects.SubjectName");
         $stmt2=$dbh->prepare("SELECT id,StudentId,ClassId,SubjectId,marks,grades,comments from tblresult join grading on marks between lowmark and himark");
        
         $stmt->execute(array(':cid' => $class));
          $sid1=array();
         while($row=$stmt->fetch(PDO::FETCH_ASSOC))
         {
        
        array_push($sid1,$row['id']);
           } 
          
        for($i=0;$i<count($mark);$i++){
            $mar=$mark[$i];
          $sid=$sid1[$i];
          //my code 
        //$totalmarks=$marks*10;
        
        $sql="INSERT INTO  result(StudentId,ClassId,SubjectId,marks,grades,comments) VALUES(:studentid,:class,:sid,:marks,:grades,:comments)";
        $query = $dbh->prepare($sql);
        $query->bindParam(':studentid',$studentid,PDO::PARAM_STR);
        $query->bindParam(':class',$class,PDO::PARAM_STR);
        $query->bindParam(':sid',$sid,PDO::PARAM_STR);
        $query->bindParam(':marks',$mar,PDO::PARAM_STR);
        $query->bindParam(':grades',$grades,PDO::PARAM_STR);
        $query->bindParam(':comments',$comments,PDO::PARAM_STR);
        $query->execute();
        $lastInsertId = $dbh->lastInsertId();
        if($lastInsertId)
        {
        $msg="Result added successfully";
        }
        else 
        {
        $error="Please correct the error";
        }
        }
        }
        ?>
        
          <!-- My Grading starts from here -->
           
        <!-- grading stop here -->  
        
        
                <script>
        function getStudent(val) {
            $.ajax({
            type: "POST",
            url: "get_student.php",
            data:'classid='+val,
            success: function(data){
                $("#studentid").html(data);
                
            }
            });
        $.ajax({
                type: "POST",
                url: "get_student.php",
                data:'classid1='+val,
                success: function(data){
                    $("#subject").html(data);
                    
                }
                });
        }
            </script>
        <script>
        
        function getresult(val,clid) 
        {   
            
        var clid=$(".clid").val();
        var val=$(".stid").val();;
        var abh=clid+'$'+val;
        //alert(abh);
            $.ajax({
                type: "POST",
                url: "get_student.php",
                data:'studclass='+abh,
                success: function(data){
                    $("#reslt").html(data);
                    
                }
                });
        }
        </script>
        
        
            </head>
            <body class="top-navbar-fixed">
                <div class="main-wrapper">
        
                    <!-- ========== NAVBAR ========== -->
          <?php include('includes/topbar.php');?> 
                    <!-- ========== SIDEBARS & MAIN CONTENT ========== -->
                    <div class="content-wrapper">
                        <div class="content-container">
        
                            <!-- ========== LEFT SIDEBAR ========== -->
                           <?php include('includes/leftbar.php');?>  
                            <!-- /.left-sidebar -->
        
                            <div class="main-page">
        
                             <div class="container-fluid">
                                    <div class="row page-title-div">
                                        <div class="col-md-6">
                                            <h2 class="title">Result Page</h2>
                                        
                                        </div>
                                        
                                                                   </div>
                                    <!-- /.row -->
                                    <div class="row breadcrumb-div">
                                        <div class="col-md-6">
                                            <ul class="breadcrumb">
                                                <li><a href="dashboard.php"><i class="fa fa-home"></i> Home</a></li>
                                        
                                                <li class="active">Student Result</li>
                                            </ul>
                                        </div>
                                     
                                    </div>
                                    <!-- /.row -->
                                </div>
                                <div class="container-fluid">
                                   
                                <div class="row">
                                            <div class="col-md-12">
                                                <div class="panel">
                                                   
                                                    <div class="panel-body">
        <?php if($msg){?>
        <div class="alert alert-success left-icon-alert" role="alert">
         <strong>Good job!</strong><?php echo htmlentities($msg); ?>
         </div><?php } 
        else if($error){?>
            <div class="alert alert-danger left-icon-alert" role="alert">
                                                    <strong>Try again!</strong> <?php echo htmlentities($error); ?>
                                                </div>
                                                <?php } ?>
                                                        <form class="form-horizontal" method="post">
        
         <div class="form-group">
        <label for="default" class="col-sm-2 control-label">Class</label>
         <div class="col-sm-10">
         <select name="class" class="form-control clid" id="classid" onChange="getStudent(this.value);" required="required">
        <option value="">Select Class</option>
        <?php $sql = "SELECT * from classes";
        $query = $dbh->prepare($sql);
        $query->execute();
        $results=$query->fetchAll(PDO::FETCH_OBJ);
        if($query->rowCount() > 0)
        {
        foreach($results as $result)
        {   ?>
        <option value="<?php echo htmlentities($result->id); ?>"><?php echo htmlentities($result->ClassName); ?></option>
        <?php }} ?>
         </select>
                                                                </div>
                                                            </div>
        <div class="form-group">
                                                                <label for="date" class="col-sm-2 control-label ">Student Name</label>
                                                                <div class="col-sm-10">
                                                            <select name="studentid" class="form-control stid" id="studentid" required="required" onChange="getresult(this.value);">
                                                            </select>
                                                                </div>
                                                            </div>
        
                                                            <div class="form-group">
                                                              
                                                                <div class="col-sm-10">
                                                            <div  id="reslt">
                                                            </div>
                                                                </div>
                                                            </div>
                                                            
        <div class="form-group">
                                                                <label for="date" class="col-sm-2 control-label">Subjects</label>
                                                                <div class="col-sm-10">
                                                            <div  id="subject">
                                                            </div>
                                                                </div>
                                                            </div>
        
        
                                                            
                                                            <div class="form-group">
                                                                <div class="col-sm-offset-2 col-sm-10">
                                                                    <button type="submit" name="submit" id="submit" class="btn btn-primary">SUBMIT</button>
                                                                </div>
                                                            </div>
                                                        </form>

  6. Ok - this code says to show the field-container div if your field is not empty. And to show the 4 other divs if it is empty. Plus you have an extra </div> tag in the else part that is not necessary. PS - not a good idea to use the dash character in names, just use the underscore. As for adding things, of course you can. Just code them.
  7. Show me your new code . And what are the "two divs"? One choice is outputting a single incomplete div and the other is outputting 5 divs.
  8. So change the if to match what output you want. If plafrorm2 is empty (ie, == '') and you want to only show the one div then make it so. If it is the other way change the if to <> '' More importantly note how I altered your output style. Entering and leaving php mode to do output is such a tedious method of coding when you can avoid it by STAYING in php mode and using the echo. Or by reading up on php's "heredocs" command that makes it much easier to output html and non-php code as well as php code.
  9. So now that the 3 of us readers have shown 3 interpretations of the 'problem', we need to see what the OP can do to clear up our thoughts.
  10. This is how the code could look: if($game['platform2'] ==" ") echo "<div class='field-container'>"; else echo "<div class='field-container'> <div class='title'>Platform</div> <div class='information'>{$game['platform2']}</div> <div class='title'>Launcher</div> <div class='information'>{$game['launcher2']}</div> </div> "; Problem is - you say you want to check if 'platform2' has text in it but you are testing if it has a space in it. Perhaps you want to check if it is not equal to '' ?
  11. @mac_gyver - that was not the question he asked. Or at least I didn't read it into this topic. The original post showed data items which I took to mean they were existent records that just didn't have that 'word' value from the where clause.
  12. Why would you NOT want it in a database table? Having it in code means the user has to have access to your code in order to make changes. Having it in a db means you would only have to have an authorized user who can make necessary improvements getting at the values. Modifying code or modifying data? The better choice is always data until you begin talking about algorithmic changes.
  13. Why do you need this array? You will have a set of query results that will be rows (in an array format) that have all the data you asked for. You are not asking for anything complex here unless you and mac_gyver are in over my head. Change your query to use this: WHERE date_fld_name between '2021-01-01' and '2021-03-31' and you will get a range of records regardless of whether they have the word value you mentioned. Order it like you were doing. Then go thru them with a while loop and present the output. Why the array? I'm not trying to be difficult. I just don't see why this is becoming so convoluted.
  14. You originally showed us your results showing counts for those records that have a certain value in them. Then you said you wanted to see the recs that did not have that value as well. The suggestion I made was to skip the where clause which would show you all records in your table. Your latest posts seem to be heading somewhere else. Do you not want all the records? Or do you want only the records that are in a certain date range? Obviously that could easily be answered with a where clause examining the appropriate date field in your records. What else do you need from us?
  15. Drop the where clause then. No? You might also write your code to handle more issues such as a bad query or a query that doesn't run for some reason. And post the code here using the <> tag to put it into a more readable format, separate from your text. $q = 'SELECT DATE(`s_created_at`) , COUNT(*) as rec_cnt FROM `tickets` where subject LIKE "%Word%" GROUP BY `s_created_at` order by s_created_at DESC'; if (!$qrslts = $mysqli->query($q)) // check if query runs { echo "Query did not run"; (show mysqli error message also?) exit(); } // show the results now while ($row = $qrslts->fetch()) // not familiar with mysqli format here { echo "{$row1['s_created_at']} {$row['rec_cnt']}<br>"; }
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.