Re: [PHP-DB] PHP Objects and SQL Results

2010-02-12 Thread Eric Lee
On Sat, Feb 13, 2010 at 3:26 AM, Paul devine...@msn.com wrote:

 Hi all,

 I'm currently having a problem correctly formatting a table within a while
 loop.  I'm using an object to store the results of a query, and using the
 while to iterate through it each row to produce the output:

 $query = SELECT * FROM foo WHERE UserID =  .$uID .  ORDER BY bar;
 $result = mysql_query($query);

 while($obj = mysql_fetch_object($result))
 {
$obj-bar;
 }

 To properly format the table, I need to check the value of bar in the next
 iteration of the object (but have to do it on the current one). Using an
 array, I would do:

 next($obj);
 if($obj[bar] == something)
 {
//do things
 }
 prev($obj);

 Is there an equivalent to object?  I've tried the above method, but nothing
 happens.  I've also tried type casting it to an array, without success.

 Is there anyway to iterate through this?


Paul

Is this the one you want ?

$sql = 'select id, name from test';
$result = mysql_query($sql);
$rows = array();
$row = null;
while ($row = mysql_fetch_object($result))
{
$rows[] = $row;
}

reset($rows);

for ($i = 0, $c = sizeof($rows) - 1; $i  $c; $i++)
{
next($rows);
if (current($rows)-name)
{
// something to do
}
prev($rows);

echo current($rows)-id, ' ', current($rows)-name, \n;

next($rows);
}

if (current($rows))
{
echo current($rows)-id, ' ', current($rows)-name, \n;

}

Regards,
Eric,


 Thanks,
 Paul

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




Re: [PHP-DB] PHP Objects and SQL Results

2010-02-12 Thread Eric Lee
On Sat, Feb 13, 2010 at 7:46 AM, Paul Hollingworth devine...@msn.comwrote:

 Thanks for the code Eric, it seems to loosely provide the functionality
 that I'm after.

 Just out of interest though, is there no other way to find the next result
 row in an object apart from dumping it into an array?


Paul

Apologize  !

I think no. The resource returned by mysql_query acts like a pointer (or
cursor on database side) that point to the current record
in result set. Before it is able advanced to the next the record must
retrieved first.

Might some design patterns  be help for your situation.
And wait for some php pros that master in this area.


Regards,
Eric



Thanks,
 Paul


 Eric Lee wrote:

 On Sat, Feb 13, 2010 at 3:26 AM, Paul devine...@msn.com wrote:

  Hi all,

 I'm currently having a problem correctly formatting a table within a
 while
 loop.  I'm using an object to store the results of a query, and using the
 while to iterate through it each row to produce the output:

 $query = SELECT * FROM foo WHERE UserID =  .$uID .  ORDER BY bar;
 $result = mysql_query($query);

 while($obj = mysql_fetch_object($result))
 {
   $obj-bar;
 }

 To properly format the table, I need to check the value of bar in the
 next
 iteration of the object (but have to do it on the current one). Using an
 array, I would do:

 next($obj);
 if($obj[bar] == something)
 {
   //do things
 }
 prev($obj);

 Is there an equivalent to object?  I've tried the above method, but
 nothing
 happens.  I've also tried type casting it to an array, without success.

 Is there anyway to iterate through this?


 Paul

 Is this the one you want ?

 $sql = 'select id, name from test';
 $result = mysql_query($sql);
 $rows = array();
 $row = null;
 while ($row = mysql_fetch_object($result))
 {
$rows[] = $row;
 }

 reset($rows);

 for ($i = 0, $c = sizeof($rows) - 1; $i  $c; $i++)
 {
next($rows);
if (current($rows)-name)
{
// something to do
}
prev($rows);

echo current($rows)-id, ' ', current($rows)-name, \n;

next($rows);
 }

 if (current($rows))
 {
echo current($rows)-id, ' ', current($rows)-name, \n;

 }

 Regards,
 Eric,


  Thanks,
 Paul

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




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




Re: [PHP-DB] Upload_File

2010-02-10 Thread Eric Lee
On Wed, Feb 10, 2010 at 7:35 PM, Gunawan Wibisono landavi...@gmail.comwrote:

 u should type the error here
 and attach the file not type in msgbox below

 what permision for upload folder?

 On Wed, Feb 10, 2010 at 6:16 PM, Bilal Ahmad 
 engg.bilalma...@googlemail.com
  wrote:

  Hi I am trying to make a form to provide option to user to upload a file
 on
  a server.Here is the code for my upload.php. It checks all the conditions
  etc.. . This code works fine on localhost , and file is uploaded
  successfully. But when I use this script online on my server, it gives me
  error. couldn't figure out what is error.
  What I think is error in move_upload_file, but it isn't returning any
  error.
  File permissions on upload folder are 755.
 
 
 
  if((!empty($_FILES['uploaded_file'])) 
 ($_FILES['uploaded_file']['error']
  == 0)){
 
   $ok = 0;
   $filename = basename($_FILES['uploaded_file']['name']);
 
   $ext = substr($filename, strrpos($filename, '.') + 1);
 
   if (($ext == jpg || gif || png) 
 ($_FILES[uploaded_file][type]
  == image/jpeg || image/gif || image/png) 
  ($_FILES[uploaded_file][size]  2097152) ){
 
   $newname = 'upload/'.$filename;
 
   if (!file_exists($newname)) {
 
 if
  ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
 $ok = 1;
   echo It's done! The file has been saved as: .$newname;
 } else {
   echo Error: A problem occurred during file upload!;   //This
 one
  executes when ever i try to upload file on server.
 }
   } else {
  echo Error: File .$_FILES[uploaded_file][name]. already
  exists;
   }
   } else {
 echo Error: Only .jpg images under 2MB are accepted for upload;
   }
  } else {
   echo Error: No file uploaded;
  }
 


 Bilal

hmmm .. Some advice
is the  $_FILES  filled correcly
check if the apache server user able access to the upload folder
Check if the tmp is writable by apache user


Regards,
Eric,




   Thanks
  Bilal Farooq Ahmad
 



 --
 akan ada dimana mulut terkunci dan suara tak ada lagi..
 saat itu gunakanlah HP untuk melakukan SMS!!
 - ini aliran bedul.. bukan aliran aneh.
 tertawa sebelum tertawa didepan RSJ..



Re: [PHP-DB] FW: Oracle Finalizes Acquisition of Sun

2010-01-28 Thread Eric Lee
hmm, that' true now !!

Shall the mysql db become paid software !!



Regards,
Eric,


On Thu, Jan 28, 2010 at 11:44 PM, Bastien Koert phps...@gmail.com wrote:

 [snip]
 [/snip]

 PS We will now proceed to fire some 20,000 employees as they will no
 longer be needed.
 --

 Bastien

 Cat, the other other white meat

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