Page 1 of 1
How to find a query error, no data being displayed
Posted: Mon Mar 12, 2007 7:48 am
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.
Posted: Mon Mar 12, 2007 8:08 am
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);
Posted: Mon Mar 12, 2007 9:11 am
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?
Posted: Mon Mar 12, 2007 9:50 am
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.
Posted: Mon Mar 12, 2007 9:54 am
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.
Posted: Mon Mar 12, 2007 10:06 am
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>";
}
Posted: Mon Mar 12, 2007 10:21 am
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.
Posted: Mon Mar 12, 2007 10:24 am
by feyd
You'll be wanting to change your password to the database now too.

Posted: Mon Mar 12, 2007 10:32 am
by crazytopu
lol. it was already a changed password, i put to entice you guys!
