FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


[URGENT!!] MySQL not Displaying Queries Correctly





polly-gone
I have a page that displays to me all the usernames that are linked to client accounts and all the usernames that are NOT linked to client accounts.

It runs the query and prints out the info of the linked accounts in the list like I want it to, but then it doesn't display the unlinked accounts. The header is appearing (which is in a div and not part of the PHP script) but nothing is appearing below it. I am not getting any errors either. Why does it only run one query?

-Nick Brick wall Brick wall Brick wall
AftershockVibe
Can you post the PHP code that runs the query?
sonam
I think, this is your problem.

Quote:
mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .



Read more here:
http://www.php.net/function.mysql-query

Sonam
polly-gone
Here is the actual page:

Code:
<?php
$action = $_GET['action'];
$link = $_GET['link'];
if($action == NULL || $action == '' || $action == ' ')
{
?>
<div id="dashblue" align="center"><div id="dashtitle"><h3>Please Choose an Option</h3></div></div>

<div id="dashwhite" align="center"><a href="?section=client&page=editaccounts&action=linked">List Linked Accounts</a></div>
<div id="dashblue" align="center"><a href="?section=client&page=editaccounts&action=unlinked">List Unlinked Accounts</a></div>
<div id="dashwhite" align="center"><a href="?section=client&page=editaccounts&action=view">View Accounts</a></div>
<?php
}
////////////////////////////////////
else if($action == "linked")
{

?>
<div id="dashblue" align="center">
<div id="dashtitle"><h3>Current Linked Accounts</h3>
</div>
</div>
<br>
<?php
include "editaccounts/linked.php";
}
else if($action == "unlinked")
{
?>

<div id="dashblue" align="center">
<div id="dashtitle"><h3>Unlinked Accounts</h3>
</div>
</div>
<br>
<?php
include "editaccounts/unlinked.php";
}
?>


Here is Linked:
Code:

<?php
//open database connection
$color = 1;
$connection = mysql_connect($host, $user, $pass) or die('Unable to Connect! Please try again later!');
                     
//select database
mysql_select_db($db) or die('Unable to select database! Please try again!');

//generate and excute query
$query = "SELECT * FROM users WHERE accountNum != 0";
$result = mysql_query($query) or die("Error in Query: $query. " . mysql_error());



if( ($row = mysql_fetch_array($result)) > 0)
{
echo "<table align=\"center\" width=\"500\">";
echo "<tr id=\"dashblue\" padding=\"2\">";
echo "<td>id</td><td>Username</td><td>Account Number</td><td>Name</td><td>Contact</td><td>Phone Number</td></tr>";
     while($row = mysql_fetch_object($result))
       {
            $accountNum = $row->accountNum;
               $query = "SELECT name,contact,phone1 FROM customers WHERE accountNum = $accountNum";
               $customer = mysql_query($query) or die("Error in Query: $query. " . mysql_error());
            if($color == 1)
               {
                    echo "<tr id=\"dashwhite\" padding=\"2\">";
                      echo "<td>".$row->id."</td><td>".$row->username."</td><td>".$row->accountNum."</td><td>".$number->name."</td><td>".$number->contact."</td><td>".$number->phone1."</td></tr>";
                      $color = 0;
               }
               else if($color == 0)
               {
                    echo "<tr id=\"dashblue\" padding=\"2\">";
                      echo "<td>".$row->id."</td><td>".$row->username."</td><td>".$row->accountNum."</td><td>".$number->name."</td><td>".$number->contact."</td><td>".$number->phone1."</td></tr>";
                      $color = 1;
               }
       }
echo "</table>";      
}
mysql_close($connection);
//END CURRENT LINKED ACCOUNTS
?>


And here is unlinked:

Code:
<?php
//open database connection


$connection = mysql_connect($host, $user, $pass) or die('Unable to Connect! Please try again later!');

//select database
mysql_select_db($db) or die('Unable to select database! Please try again!');

//generate and excute query
$query = "SELECT * FROM users WHERE accountNum = 0";
$result = mysql_query($query) or die("Error in Query: $query. " . mysql_error());





if( ($row = mysql_fetch_array($result)) > 0)
{
$color = 1;
echo "<table align=\"center\" width=\"500\">";
echo "<tr id=\"dashblue\" padding=\"2\">";
echo "<td>id</td><td>Username</td><td>Contact</td><td> </td></tr>";
     while($row = mysql_fetch_object($result))
       {
            if($color == 1)
               {
                    echo "<tr id=\"dashwhite\" padding=\"2\">";
                      echo "<td>".$row->id."</td><td>".$row->username."</td><td>".$row->contact."</td><td><a href=\"http://atomicdingo.us/index.php?section=client&page=linkAccount&id=".$row->id."\">Link Account</a></td></tr>";
                      $color = 0;
               }
               else if($color == 0)
               {
                    echo "<tr id=\"dashblue\" padding=\"2\">";
                      echo "<td>".$row->id."</td><td>".$row->username."</td><td>".$row->contact."</td><td><a href=\"http://atomicdingo.us/index.php?section=client&page=linkAccount&id=".$row->id."\">Link Account</a></td></tr>";
                      $color = 0;
               }
       }
echo "</table>";      
}
mysql_close($connection);
?>


If I click on linked, I can view all the linked accounts. If I go to unlinked, it displays the header an column headers, but it is a no go on the results.

-Nick Confused Confused Confused
sonam
Try to use single quote in your query. Maybe sql read your 0 (zero) like NULL not like number.

Code:
$query = "SELECT * FROM users WHERE accountNum = '0' ";


Sonam
polly-gone
It is doing something else weird. I just noticed that on the linked page, it only shows 2 out of the 3 accounts that it is supposed to. The first account it not shown. I added a second dummy account that is not linked with a spot earlier in the database, and the later entry shows but the earlier one does not. It is not that is isn't running queries, it is just it is cutting off the first one. What can I do to fix this?

-Nick Eh? Eh? Eh?
polly-gone
Does anyone know why it is not showing all the results?

-Nick Confused Confused Confused
MrBlueSky
Code:

if( ($row = mysql_fetch_array($result)) > 0)
{
echo "<table align=\"center\" width=\"500\">";
echo "<tr id=\"dashblue\" padding=\"2\">";
echo "<td>id</td><td>Username</td><td>Account Number</td><td>Name</td><td>Contact</td><td>Phone Number</td></tr>";
     while($row = mysql_fetch_object($result))



This probably goes wrong: mysql_fetch_array() gets the first line, and mysql_fetch_object the second, but you never do anything with the first. Try this:

Code:

if( mysql_num_rows($result) > 0)
{
echo "<table align=\"center\" width=\"500\">";
echo "<tr id=\"dashblue\" padding=\"2\">";
echo "<td>id</td><td>Username</td><td>Account Number</td><td>Name</td><td>Contact</td><td>Phone Number</td></tr>";
     while($row = mysql_fetch_object($result))
polly-gone
Thanks. I will try that.

-Nick Smile Smile Smile
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.