This for loop displays only the last entry of the student record

This for loop displays only the last entry of the student record

Content Index :

This for loop displays only the last entry of the student record
Tag : python , By : Eugenio
Date : January 12 2021, 09:11 PM

This might help you You are using the same variable inside the for loop. on each iteration the last entered student get deleted and replaced with the new data. You should use an array (or any other suitable data structure for your use case) and add a new Student in the array on every iteration.
this code should work:
arr = list()
for i in range(n):

No Comments Right Now !

Boards Message :
You Must Login Or Sign Up to Add Your Comments .

Share : facebook icon twitter icon

PHP,MYSQL while loop only displays the last record

Tag : php , By : Grik
Date : March 29 2020, 07:55 AM
will be helpful for those in need Each time you iterate, you overwrite $info variable. You have to add rows to $info array.
$dbhost = 'localhost';    
$dbuser = 'root';    
$dbpass = '';  
$dbname = 'moviefone';    
$con = mysql_connect($dbhost, $dbuser, $dbpass);  
mysql_select_db($dbname, $con);    

// Check connection    
if (mysqli_connect_errno()) {  
    echo "Failed to connect to MySQL: " . mysqli_connect_error();    

$data = mysql_query("SELECT * FROM new_hindi") or die(mysql_error());
while ($row = mysql_fetch_array($data)){


Defining a delete(student st[], int *itemcount) function to delete a target record from the array of student objects

Tag : c , By : user176445
Date : March 29 2020, 07:55 AM
I wish this help you I'm trying to learn C programming so i was trying to do some practices. as you see below the search function only returns 1 or -1 and the variable index is being used to determine whether the target student exists or not. but after that it is again being used to determine whether it is the last, in the middle, or the first item in the array. how can index have that numeric value when we already assigned the returned value from the search function to it? please help me figure this out. thank you.
how can index have that numeric value when we already assigned 
the returned value from the search function to it?
if (strcmp (st[i].stnumber, id) == 0)
    found = i;
. . .
return found;

Bookshelf.js - After updating record, initial page load/query displays old record. After refresh data displays correctly

Tag : javascript , By : Lord Zantor
Date : March 29 2020, 07:55 AM
wish helps you You are writing you saving data like synchronous code, so the save() may (and often will) happen AFTER the refresh(). Try changing that to:
    Table.where({id: req.param.id}).fetch()
    .catch(function (err) {
    .then(function (results) {
        return results
          .set('other_column', null)
    .then(function (results) {  // results should now include the saved data
        // Redirect to orders page

Select student record based on foreach loop

Tag : chash , By : johntynan
Date : March 29 2020, 07:55 AM
Any of those help I am working on MVC. I need to selecr list of students based on enrolled department wise and display them on different divs departmentalize, based on enrolled department in view. My database sample Schemas is as follow , You can do it like this (I implemented your issue !!):
DB Tables
public ActionResult NewStudentFeeStatus()
            ViewBag.DeparmentList = db.tblDepartments.ToList();
            List<tblStdEnrollment> enrollmentList = (from p in db.tblStdDetails
                                                     join e in db.tblStdEnrollments on p.ID equals e.Stdref_id
                                                     select e).ToList();
            return View(enrollmentList);
@model IEnumerable<tblStdEnrollment>    

<!DOCTYPE html>

    <meta name="viewport" content="width=device-width" />
        @foreach (var item in @ViewBag.DeparmentList)
            foreach (var student in Model.Where(s => s.Depart_ref_id == item.ID).ToList())

PHP, mySQL, and Smarty template. while loop only displays 1 database entry

Tag : php , By : arbeitandy
Date : March 29 2020, 07:55 AM
wish of those help Just like what I've said in the comments, the reason why you're only getting the last row value is because every iteration inside your loop, the values gets overwritten.
A way that you can do is to create a container, then use your while loop and put them all inside first. After you're done, then ->assign() it inside the template and make your loop presentation and logic and other stuff that you need to do.
// Backend

$data = array(); // initialize a simple container
$query = "SELECT * from recipes";
$result = mysqli_query($db_server, $query);

if ($result->num_rows > 0) {
    // fetch rows
    while($row = $result->fetch_assoc()) {
        $data[] = $row; // push them inside

// assign user information to template
$tpl->assign('values', $data);

// Front end

<div class="content">
    {foreach from=$values key=k item=value}
Related Posts Related QUESTIONS :
  • Logging with two handlers - one to file and one to stderr
  • How to do pivot_table in dask with aggfunc 'min'?
  • How to split a string by a specific pattern in number of characters?
  • Python 3: how to scrape research results from a website using CSFR?
  • Setting the scoring parameter of RandomizedSeachCV to r2
  • How to send alert or message from view.py to template?
  • How to add qml ScatterSeries to existing qml defined ChartView?
  • Django + tox: Apps aren't loaded yet
  • My css and images arent showing in django
  • Probability mass function sum 2 dice roll?
  • Cannot call ubuntu 'ulimit' from python subprocess without using shell option
  • Dataframe Timestamp Filter for new/repeating value
  • Problem with clicking select2 dropdownlist in selenium
  • pandas dataframe masks to write values into new column
  • How to click on item in navigation bar on top of page using selenium python?
  • Add multiple EntityRuler with spaCy (ValueError: 'entity_ruler' already exists in pipeline)
  • error when replacing missing ')' using negative look ahead regex in python
  • Is there a way to remove specific strings from indexes using a for loop?
  • select multiple tags by position in beautifulSoup
  • pytest: getting AttributeError: 'CaptureFixture' object has no attribute 'readouterror' capturing stdout
  • Shipping PyGObject/GTK+ app on Windows with MingW
  • Python script to deduplicate lines in multiple files
  • How to prevent window and widgets in a pyqt5 application from changing size when the visibility of one widget is altered
  • How to draw stacked bar plot from df.groupby('feature')['label'].value_counts()
  • Python subprocess doesn't work without sleep
  • How can I adjust 'the time' in python with module Re
  • Join original np array with resulting np array in a form of dictionary? multidimensional array? etc?
  • Forcing labels on histograms in each individual graph in a figure
  • For an infinite dataset, is the data used in each epoch the same?
  • Is there a more efficent way to extend a string?
  • How to calculate each single element of a numpy array based on conditions
  • How do I change the width of Jupyter notebook's cell's left part?
  • Measure distance between lat/lon coordinates and utm coordinates
  • Installing megam for NLTK on Windows
  • filter dataframe on each value of a samn column have a specific value of another column in Panda\Python
  • Threading with pubsub throwing AssertionError: 'callableObj is not callable' in wxPython
  • Get grouped data from 2 dataframes with condition
  • How can I import all of sklearns regressors
  • How to take all elements except the first k
  • Whats wrong with my iteration list of lists from csv
  • Tensorflow Estimator API save image summary in eval mode
  • How to Pack with PyQt - how to make QFrame/Layout adapt to content
  • How do I get certain Time Range in Python
  • python doubly linked list - insertAfter node
  • Open .h5 file in Python
  • Joining a directory name with a binary file name
  • python, sort list with two arguments in compare function
  • Is it possible to print from Python using non-ANSI colors?
  • Pandas concat historical data using date minus some number of days
  • CV2: Import Error in Python OpenCV
  • Is it possible to do this loop in a one-liner?
  • invalid literal for int() with base 10: - django
  • Why does my code print a value that I have not assigned as yet?
  • the collatz func in automate boring stuff with python
  • How to find all possible combinations of parameters and funtions
  • about backpropagation deep neural network in tensorflow
  • Sort strings in pandas
  • How do access my flask app hosted in docker?
  • Replace the sentence include some text with Python regex
  • Counting the most common element in a 2D List in Python
  • shadow
    Privacy Policy - Terms - Contact Us © scrbit.com