Re: Duplicate table results

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Barry,

$dbarray = array();
     while($row = mysql_fetch_array($result)) {
               array_push($dbarray, $row['fileName']);
         }

That was the difference.
The while($row =

Best,
Karl


On Jul 6, 2011, at 12:41 PM, Barry Stear wrote:

Hmmm i didn't even see a different in the code between the first post and second. Guess I missed something. Glad you got it working though!

On Wed, Jul 6, 2011 at 1:54 AM, Karl DeSaulniers <karl@xxxxxxxxxxxxxxx> wrote:
I love the teddy bear effect...

Corrected Code::: (or at least it works now :)
(database.php)

/**
   * getFiles - Returns all uploaded images for a print order. F

   * If query fails, NULL is returned.
   */
function getFiles($username, $fileID){ //to just get the current upload files $q = "SELECT fileName FROM ".UPLOADS." WHERE username = '".mysql_real_escape_string($username)."' AND (OrderID = '".mysql_real_escape_string($fileID)."' OR UpID = '".mysql_real_escape_string($fileID)."') ORDER BY fileID ASC";

     $result = $this->query($q);
     if(!$result || (mysql_numrows($result) < 1)){
        return NULL;
     }
     /* Return result array */
     $dbarray = array();
     while($row = mysql_fetch_array($result)) {
               array_push($dbarray, $row['fileName']);
         }
      return $dbarray;

  }

(session.php)

$fileInfo = array();
$fileInfo = $database->getFiles($subusername, $subUpID);
$subfileName1 = $fileInfo[0];
$subfileName2 = $fileInfo[1];
$subfileName3 = $fileInfo[2];
$subfileName4 = $fileInfo[3];

Best,
Karl


On Jul 6, 2011, at 12:13 AM, Karl DeSaulniers wrote:

Hello All,
I am wondering if you can help untie the knot in my head.
I have a table that stores the reference to an uploaded file on an order form.
Each upload has an upload ID as well as an Order ID
So say I upload 4 files on this form for an order.
All the files are getting uploaded correctly and the info is getting into the database correctly.
My problem is reading that info back out.


UPLOADS TABLE
fileID
Username
OrderID
UpID
fileName
timestamp

There can be multiple rows that have the same Upload ID and Order ID.
So I am trying to get each of the fileName(s) from each row according to the username and F_ID (F_ID can be the Upload ID or Order ID)

My Code:::

(database.php)

/**
   * getFiles - Returns all uploaded images for a print order.
   * If query fails, NULL is returned.
   */
  function getFiles($username, $F_ID){
$q = "SELECT * FROM ".UPLOADS." WHERE username = '".mysql_real_escape_string($username)."' AND (OrderID = '".mysql_real_escape_string($F_ID)."' OR UpID = '".mysql_real_escape_string($F_ID)."') ORDER BY fileID ASC";
     $result = $this->query($q);
     if(!$result || (mysql_numrows($result) < 1)){
        return NULL;
     }
     /* Return result array */
     $dbarray = mysql_fetch_array($result);
     return $dbarray;
  }


I am also trying to put the results into a multidimensional array, but
It only returns the first row though. What am I missing/doing wrong?

(session.php)

$fileInfo = array();
$fileInfo[] = $database->getFiles($subusername, $subUpID);
$subfileName1 = $fileInfo[0]['fileName'];
$subfileName2 = $fileInfo[1]['fileName'];
$subfileName3 = $fileInfo[2]['fileName'];
$subfileName4 = $fileInfo[3]['fileName'];

The following prints out:

Upload ID: UKcwbelR
File Name 1:3534.eps
File Name 2:
File Name 3:
File Name 4:

TIA

Karl DeSaulniers
Design Drumm
http://designdrumm.com


Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
<a href="http://www.c28.com/?adid=st&iid=19467";>
<img src="http://www.c28.com/images/banner_88x31.gif"; border="0" width="88" height="31"></a>

Karl DeSaulniers
Design Drumm
http://designdrumm.com


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux