0

hi, i am a teacher. i have a list of students in my MySQL table. How to retrieve their names one by one, and while doing that there will be a text box to put their marks in.

3
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by Nyight
0

You could use a while-loop and the mysql_fetch_assoc-function

Edited by aralll: n/a

0

I tried but do not know where to put text box script

$result=mysql_query($query,$con);
while ($row = mysql_fetch_assoc($result)) {
echo $row["student_id"];
echo $row["student_name"];
}
0

This should get you started in the right direction.

<select>
<?php
$result = mysql_querey($query,$con);
while($row=mysql_fetch_assoc($result)){?>
	<option value="<?=$row["student_id"];?>"><?=$row["student_id"];?> - <?=$row["student_name"];?></option>
}
?>
</select>
0

I tried this, but there was an error message.

<select>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("exam", $con);
    $result = mysql_query("SELECT * FROM test1");
    while($row=mysql_fetch_assoc($result)){?>
    <option value="<?=$row["student_id"];?>"><?=$row["student_id"];?> - <?=$row["student_name"];?></option>
    }
mysql_close($con);
?>
</select>

This is my mysql

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
-- Database: `exam`

-- Table structure for table `test1`

CREATE TABLE IF NOT EXISTS `test1` (
  `student_id` int(4) NOT NULL AUTO_INCREMENT,
  `student_name` text NOT NULL,
  `subject1` int(3) DEFAULT NULL,
  `subject2` int(3) DEFAULT NULL,
  PRIMARY KEY (`student_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

-- Dumping data for table `test1`

INSERT INTO `test1` (`student_id`, `student_name`, `subject1`, `subject2`) VALUES
(1, 'Student 1', 0, 0),
(5, 'Student 2', 0, 0),
(10, 'Student 3', 0, 0),
(15, 'Student 4', 0, 0);
0

To start out with your error checking should look something more like

$con = mysql_connect("localhost","root","");
mysql_select_db("exam", $con) or die('could not connect: '.mysql_error());

Next I honestly hope you're merely omitting the password out of mysql_connect() as most put in asterisks or x's to represent they are adding it but are hiding it, etc...

Beyond that, you need to post the error so we know what to look for or what the problem could potentially be.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.