I am using this code to pull out data from database. But the $bathc_no variable is not fetching more than 1 row.

Suppose, I have 3 rows in my mysql, Where the $batch_no for the 1st row is "13", 2nd row is "12" and for the 3rd is "15".

I put whatever value for $profile_id varialble, the result(only $batch_no) always comes for 1st row, that is 13. Rest of the code($student_name, $sex, $birth_date) is working fine with the variour $profile_id value but only the $batch_no.

I need various $batch_no for various $profile_id.

Please help me.

$profile_pull = mysql_query("SELECT * FROM student_profiles WHERE id='$profile_id'");
$profile_count = mysql_num_rows($profile_pull);
if ($profile_count > 0 ) {
    while ($row = mysql_fetch_array($profile_pull)) {
        $student_name = mysql_prep(ucwords($row["student_name"]));
        $batch_no = $row["batch_no"];
        $sex = ucwords($row["sex_of_the_student"]);
        $birth_date = $row["birth_date"];
Member Avatar

You'd only expect one row with this if you've got a WHERE clause. No need for a while loop.

Also stop using mysql_* functions - they've been deprecated - use mysqli or PDO.

Can you show me an example please?

Member Avatar

Example of what?