Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8971085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:52:14+00:00 2026-06-15T17:52:14+00:00

I have a code which fetches data from a mysql table and converts it

  • 0

I have a code which fetches data from a mysql table and converts it into pdf document, the code is working fine except it is skipping row 1.

Here is the code from which i have removed the pdf generation process since the problem is in the loop which is fetching data.

Please help.

<?php
    session_start();
if(isset($_SESSION['user']))
{
    $cr = $_POST['cour'];
    $s = $_POST['sem'];
    require('fpdf.php');
    include('../includes/connection.php');
    $sql = "SELECT * FROM `student` WHERE AppliedCourse ='$cr'";
    $rs = mysql_query($sql) or die($sql. "<br/>".mysql_error());
    if(!mysql_fetch_array($rs))
    {
        $_SESSION['db_error'] = "<h2><font color = 'RED'>No such course found! Pease select again.</font></h2>";
        header('Location: prinrepo.php');
    }
    else {

    for($i = 0;$i <= $row = mysql_fetch_array($rs);$i++)
     {
            $formno[$i] = $row ['FormNo']; 
            $rno[$i] = $row ['rollno'];
            $snm[$i] = $row ['StudentNm'];          
            $fnm[$i] = $row ['FathersNm'];
            $mnm[$i] = $row ['MothersNm'];
            $addr[$i] = $row['Address'];
            $pic[$i] = $row['imagenm'];
            $comm[$i] = $row['SocialCat'];

        echo $formno[$i]."<br />";
        echo $rno[$i]."<br />";
        echo $snm[$i]."<br />";
        echo $fnm[$i]."<br />";
        echo $mnm[$i]."<br />";
        echo $addr[$i]."<br />";
        echo $pic[$i]."<br />";
        echo $comm[$i]."<br />";
        echo "<br />";
    }
    }
    mysql_close($con);
    }
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T17:52:15+00:00Added an answer on June 15, 2026 at 5:52 pm

    You are fetching the first row outside of your for() loop then you miss it.

    After mysql_query() your should use mysql_num_rows() to check if there are any rows in your result and then fetch them in the for loop.

    More info here : http://php.net/manual/fr/function.mysql-num-rows.php

    Your code would look like this :

    $sql = "SELECT * FROM `student` WHERE AppliedCourse ='$cr'";
    $rs = mysql_query($sql) or die($sql. "<br/>".mysql_error());
    if(0 == mysql_num_rows($rs)) {
        $_SESSION['db_error'] = "<h2><font color = 'RED'>No such course found! Pease select again.</font></h2>";
        header('Location: prinrepo.php');
    } else {
        for($i = 0;$i <= $row = mysql_fetch_array($rs);$i++)
         {
            // Your code
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Java code I have embedded a SQL query which fetches data from
I have a repeater which fetches data from a database and shows some labels
I have a button on my ASP.NET page, which fetches some data from my
I have some code that fetches some data from the database, database codepage is
I have an NSOperation which fetches some objects from a core data persistent store
I have an application that currently fetches data from mySQL DB. And I have
I have a PHP script which fetches data from Salesforce via the Salesforce API
I have an asp.net website which contains a Thread that fetches some data from
I have written an app which fetches data from a server. I am not
I have this code, which fetches date from web, in text format. Here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.