Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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.
Reply With Quote
  #2 (permalink)  
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>";
  }

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 01:49 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.