0

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"];
    }
}

Edited by pritaeas: Not a code snippet.

2
Contributors
3
Replies
20
Views
3 Years
Discussion Span
Last Post by diafol
0

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.

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.