Re: Duplicate table results

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

 



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



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

  Powered by Linux