Hi all,

Been pulling my hair out on this one. I have a simple query:

$query = ("
		
		SELECT
			
			course_code,
			student_grade,
			start_date
					
		FROM
			ccdata
				
		WHERE
				
			student_id = '$local_id'
				
		AND
		
			
			start_date= '20091023'
			")
$result2 = $mysqli->query($query, MYSQLI_STORE_RESULT);

	
//$total_courses_I = $result2->num_rows; 
	
		
while ($obj2 = $result2->fetch_row())
{	
		$course_code = $obj2[0];
		$ypos += 5;
		$data = $course_code ;	
		$pdf->SetXY($xpos, $ypos) ;
		$pdf->Cell(32.5,5,$data,1,1,'L',true);
		$row_c ++;
}

start_date is a text field
According to PHPMYADMIN I have 4 courses for this date and student.
When I run this it only shows 3.

If I change the query from:
start_date= '20091023'
to
(SUBSTRING(start_date ,1,4) = '$school_year') //school year =2009

It then shows this missing course + plus others for other dates in 2009.

The start_date in phpmyadmin is 20091023 for 4 courses....

Why can't I query that exact string and get all four records?

Also if i uncomment num_rows then it says 4 too!!! But only three are shown

If mysql_num_rows say 4, then something must be wrong with your function, fetch_row. Post your function and we will try to find out what is missing.

Thanks for the reply.

The function fetch_row is a member function of mysqli class (improved extension of mysql). It should not be failing on this simple query.

The pdf is the popular free pdf php class. It should not have anything to do with this...i think.

My bad, sorry. I had never used mysqli. Thanks to you, I checked how it works and it did work.

$mysqli = new mysqli("localhost", "root", "", "test2");

if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$result = $mysqli->query("SELECT * from b");
echo "Total number of records: ".$result->num_rows."<br />";
while ($row = $result->fetch_row()) { 
	print "<pre>";
	print_r($row);
	print "</pre>";
}
$result->close();
$mysqli->close();

Are you sure you are not overwriting the data in pdf ? If you print $obj2, does it print 4 records ?

Yeah there must be something fishing going on in fpdf...i will look into it and post here.

Okay, I took out the pdf class stuff and it works fine. I will head over to that forum...thanks for the help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.