How to find a query error, no data being displayed

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

How to find a query error, no data being displayed

Post by crazytopu »

What other error mechanism can I to use to find what's wrong with this ?


Code: Select all

$query= 'SELECT username FROM member';

echo $query; 

if (!($query)) print mysql_error();
		$result = $connector->query($query);
		$num = mysql_num_rows($result);

echo "<br>num: ".$num."<br>";



$query= 'SELECT id FROM request';

echo $query; 

if (!($query)) print mysql_error();
		$result = $connector->query($query);
		$num = mysql_num_rows($result);

echo "<br>num: ".$num;

I get following echo result:






Code: Select all

SELECT username FROM member
num: 4
SELECT id FROM request
num: 4

and when I run the same query in the dabase through phpmyadmin I get 17 and 13 rows respectively. And there are indeed that many records in those tables.

Please help needed.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

$query= 'SELECT username FROM member';

echo $query;

if (!($query)) print mysql_error();
You're testing the string. It's like writing

Code: Select all

if ( !'SELECT username FROM member' )
doesn't make much sense, does it?
You want to test
$result = $connector->query($query);
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

oh yes, but i still get the same result:

Code: Select all

$query= 'SELECT username FROM member';

echo $query; 




if (!($result = $connector->query($query))) print mysql_error();
		$result = $connector->query($query);
		$num = mysql_num_rows($result);

echo "<br>num: ".$num."<br>";
Any clue?
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

This is crazy!

Could someone run this files on their server and see if you get the same result?

here is the zip files: http://kikorben.com/comp.zip

Code: Select all

<?php

require_once ('includes/DbConnector.php');

$connector= new DbConnector();
?>											
											
											


<?                 
$query= 'SELECT username FROM member';

echo $query; 

$result = $connector->query($query);
$num = $connector->num_rows();
echo  "<br>".$num; 

while($row = $connector->fetchArray($result)) {
	
	echo "<br>user names : ".$row['username']."<br>";

}


$query= 'SELECT id FROM request';

echo "<br>".$query; 

$result = $connector->query($query);
$num = $connector->num_rows();
echo  "<br>".$num; 

while($row = $connector->fetchArray($result)) {
	
	echo "<br>ID : ".$row['id'];

}



?>


and I get this result:



Code: Select all

SELECT username FROM member

user names : t
user names : topu
user names : absar
user names : oliur
SELECT id FROM request

ID : 1
ID : 2
ID : 4
ID : 5

But I got more records in the tables.
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

Why don't you try this without dbConnector and just use the mysql functions, I am guessing there is a limit clause being appended to your query.

Edit: Well I looked and your dbConnector class is pretty simple and doesn't look like its the problem.... really don't know what the issue is

Note: OMG for the love of god please indent your code, when I look at your dbConnector source I wanted to shove a knife into my eye.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Now its returning 14 rows or something which is right. So what was wrong!

I still would prefer to use a include file for easy future modification. I left some fields blank for db settings in the zip file so that wasnot the cause of eorr.

Code: Select all

<?php

$host = 'localhost';
$db = 'compquo';
$user = 'root';
$pass = 'flamflew';

mysql_connect ($host, $user, $pass)or mysql_error();//die ("Unable to connect to Database Server");
mysql_select_db($db)or die ("There is no such database");






?>											
											
											


<?                 
$query= 'SELECT username FROM member';

echo $query; 

$result = mysql_query($query);
$num = mysql_num_rows($result);
echo  "<br>".$num; 

while($row = mysql_fetch_array($result)) {
	
	echo "<br>user names : ".$row['username']."<br>";

}
Begby
Forum Regular
Posts: 575
Joined: Wed Dec 13, 2006 10:28 am

Post by Begby »

The includes are fine and a good way to do it, but sometimes its good to just write out the code manually to try and narrow down problems.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll be wanting to change your password to the database now too. ;)
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

lol. it was already a changed password, i put to entice you guys! :lol:
Post Reply