Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
| Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 13th, 2007, 12:18 PM
Registered User
 
Join Date: Nov 2003
Location: Newmarket, Ontario, Canada.
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using the same query twice

 I've got a billing query, and then a billing result. How can I use the billing result twice? or can I? I mean is there a clean way of doing this or do I have to do 2 separate queries?

Here's the code in question:

$billingQuery = "SELECT * FROM Billing WHERE UID = '$userData[UID]'";
$billingResult = mysql_query($billingQuery)or die("#164;billingQuery error: ".mysql_error());
$billingCount = mysql_num_rows($billingResult);


while($billingData = mysql_fetch_array($billingResult)){
    foreach($billingData as $key => $value){
        echo "$key => $value <br>";
    }
}

if($billingCount >= 1){
echo "<br>found $billingCount!! <br>";
// now the following array should have the same data as $billingData, but doesn't
$billingDataPrime = mysql_fetch_array($billingResult);
echo $billingDataPrime['Last_Pmt']."<br>";
}

The best ideas are not the simple ones, they're the complex ones made easy.
 
Old June 17th, 2007, 11:13 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: South San Francisco, CA, USA.
Posts: 128
Thanks: 0
Thanked 1 Time in 1 Post
Default

cottager,
Try this:

  $uid = trim($userData[UID]);
  // SELECT * FROM Billing WHERE UID = '$userData[UID]'

  $sql = "SELECT * ";
  $sql .= "FROM Billing ";
  $sql .= "WHERE UID = '" . $uid . "'";
  $rst = @$con->query($sql);


  if($rst == false)
  {
    echo "<h4>Error: " . mysqli_error($con) . "</h4>";
  }
  elseif(@mysqli_num_rows($rst) == 0)
  {
    echo "<h4>Query completed. No results returned.</h4>";
  }
  else
  {
    /* Display results */

    echo "<table border='1'>";
    echo " <thead>";
    echo " <tr>";

    // Get fieldnames as table headers from the result query:
    $fields = mysqli_fetch_fields($rst);
    foreach($fields as $field)
    {
      echo "<th>&nbsp;" . $field->name . "&nbsp;</th>";
    }

    echo " </tr>";
    echo " </thead>";
    echo " <tbody>";

    // Get Number of rows from the result query:
    for ($i=0; $i<mysqli_num_rows($rst); $i++)
    {
      echo "<tr>";

      // In each row get values for each columns from the result query:
      $row = mysqli_fetch_row($rst);
      foreach($row as $value)
      {
        echo "<td>&nbsp;" .$value. "&nbsp;</td>";
      }
      echo "</tr>";
    }

    echo " </tbody>";
    echo "</table>";
  }





Similar Threads
Thread Thread Starter Forum Replies Last Post
Output Query to txt file from SQL Query everest SQL Server 2005 4 November 22nd, 2007 01:49 AM
how to make a query from an existing query raport SQL Language 3 November 13th, 2006 08:59 PM
I solved insert query.now see this Update Query. amit_mande@yahoo.com VB.NET 2002/2003 Basics 2 September 21st, 2006 12:48 AM
Syntax error in query. Incomplete query clause. dispickle ADO.NET 3 April 16th, 2004 01:04 PM
Error on Make-Table Query In Union Query rylemer Access 1 August 20th, 2003 07:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.