Jump to content

Recommended Posts

Hi,

 

I will really need some help here. I have posted this similar topic quite a number of times, however no one could actually give me a solution.

 

Currently when I execute the code, it seems like "mysqli_num_rows($data3) !== 1", therefore my {else} command was executed instead.

 

"else {echo '<p class="error">There was a problem accessing your profile.</p>';}"

 

 

I have no idea what went wrong, and if you look at my attachment.jpg, there are 3 columns

1) overall_level_subject_id

2) tutor_id

3) subject_level_id

 

The thing is that, there are similar tutor_id appearing in this table and it may not be in sequence, take for example...

 

overall_level_subject_id: 10

tutor_id: T532uu

subject_level_id: 11

 

overall_level_subject_id: 51

tutor_id: T532uu

subject_level_id: 12

 

 

I'm not too sure if you guys understand what I am explaining. But I really need help in this area! Please advice!

 

<?php
/*************************Teaching Subjects*************************/	
$query3 = "SELECT subject_level_id FROM tutor_overall_level_subject WHERE tutor_id = '" . $_GET['tutor_id'] . "'";

  $data3 = mysqli_query($dbc, $query3)
  or die(mysqli_error($dbc));

  if (mysqli_num_rows($data3) == 1) {

echo '<div id="panel4">';

	echo'<table><tr>';
	$count = 0; // Start your counter
	while($row3 = mysqli_fetch_array($data3)) {

		if ($count % 5 == 0) { 
			echo "</tr><tr>"; $count = 0;
		}
		echo '<td class="label">' . $row3['subject_level_id'] . '</td><td>' . $row3['subject_level_id'] . '</td>';
		$count++; 
	} 
	echo '</tr></table><br/>'; 

echo '</div>'; //End of panel 4

} //End of IF for $query and $data (Teaching Subjects)

else {
	echo '<p class="error">There was a problem accessing your profile.</p>';
}
?>

 

[attachment deleted by admin]

Start by echoing or use var_dump() on mysqli_num_rows($data3) so that you know exactly what it is. If it is zero, find out exactly what value is in $_GET['tutor_id'] (use var_dump()) and find out why that doesn't match an entry in your table. If it is greater-than 1, find out why you have duplicate data in your table.

Hi PFMaBiSmAd,

 

Thanks for your reply,

 

I have tried var_dump in "$data3 = var_dump(mysqli_query($dbc, $query3))".

 

It has returned me with this value...object(mysqli_result)#5 (0) { }

 

Which I don't quite understand what it means.

 

 

 

Suffice to say, why I have duplicated tutor_id in my table, it's because,

each tutor_id carries different subject_level_id. Therefore there can be many similar tutor_id tagged to only one unique subject_level_id. Below is the example. Could you kindly advice what is the next step to solve the problem?

 

1) overall_level_subject_id

2) tutor_id

3) subject_level_id

 

overall_level_subject_id: 10

tutor_id: T532uu

subject_level_id: 11 (Represent 'English')

 

overall_level_subject_id: 51

tutor_id: T532uu

subject_level_id: 12 (Represent 'Math')

 

Try:

 

echo mysqli_num_rows($data3);

 

This will show you the number of rows being returned.  My guess is that you are getting the error message because your query is returning more than one row with the same tutor_id.

 

Right now your code will only execute if your query returns one row and one row only.  Looking at your code, I think that maybe instead of this:

if (mysqli_num_rows($data3) == 1) {

you might want this:

if (mysqli_num_rows($data3) > 0) {

 

But maybe I'm not understanding what you're trying to do.

Hi mikosiko,

 

I understand you have given me an answer, but it's not completely helpful as it was just stating the fact not a solution.

 

Hi hoogie & PFMaBiSmAd,

 

Correct me if I am wrong. I always think that

if (mysqli_num_rows($data3) == 1), what does this mean?

 

Does it mean "mysqli_num_rows($data3)" will search through the sql table, and if tutor_id == 1, then they will pull out the results?

 

Thanks

 

 

 

 

 

The php manual contains a description of all the php functions - http://www.php.net/manual/en/mysqli-result.num-rows.php

 

There's no reason why you need to guess what any function does.

The php manual contains a description of all the php functions - http://www.php.net/manual/en/mysqli-result.num-rows.php

 

There's no reason why you need to guess what any function does.

 

wow PFM,,, but that is fact no completely helpful... not a solution  ;)

Hi mikosiko,

 

I understand you have given me an answer, but it's not completely helpful as it was just stating the fact not a solution.

 

genzedu... read my signature.... what do you want... the fish or learn how to fishing?  .... part of be a programmer (and sometime the most important) is learn how to debug your own code... specially when you are getting help and clues from others... if you are not capable or you don't know how to do it... just say so and ask

 

Correct me if I am wrong. I always think that

if (mysqli_num_rows($data3) == 1), what does this mean?

 

Does it mean "mysqli_num_rows($data3)" will search through the sql table, and if tutor_id == 1, then they will pull out the results?

 

It means that IF there is exactly one row in the variable $data3 THEN it will execute the rest of the code in the IF block.

 

If $data3 has less or more than 1 row, it will not execute the code and will go instead to the ELSE block.

 

I think the others are right, though - it sounds like you may need to do a little more research to understand how these things work.  If you need a good place to start learning, I really like this guide: http://www.tuxradar.com/practicalphp

It's easy to read and will give you a good idea of why things work the way they do.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.