0

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

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by bcpaul
0

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.

0

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.

0

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 ?

0

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

0

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

This question has already been answered. 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.