php-general Digest 13 Jan 2010 09:53:44 -0000 Issue 6536

Topics (messages 301027 through 301053):

Re: To add the final ?> or not...
        301027 by: Robert Cummings
        301028 by: Ashley Sheridan
        301029 by: tedd
        301030 by: Ashley Sheridan
        301031 by: Paul M Foster
        301032 by: Ashley Sheridan
        301034 by: Paul M Foster
        301035 by: Rolf Brejner
        301039 by: Robert Cummings
        301042 by: tedd

Re: array_count_values Problem
        301033 by: Alice Wei

any solution about array_walk with pass-by-reference UseData?
        301036 by: hack988 hack988

Re: Clean PHP 5.2.12 Build Core Dumping / Can't Build Port - FreeBSD 6.1
        301037 by: hack988 hack988
        301041 by: Don O'Neil

Re: 11 types of people in the world...
        301038 by: Daevid Vincent
        301040 by: Robert Cummings

Display just 1 record in a query
        301043 by: dealtek.gmail.com
        301044 by: Ryan Sun
        301045 by: Ashley Sheridan
        301046 by: Kim Madsen
        301047 by: Daevid Vincent
        301048 by: Kim Madsen
        301049 by: dealtek.gmail.com
        301050 by: Robert Cummings
        301051 by: Jochem Maas
        301052 by: Robert Cummings

Need Idea to make Backup
        301053 by: Jens Geier

Administrivia:

To subscribe to the digest, e-mail:
        [email protected]

To unsubscribe from the digest, e-mail:
        [email protected]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
Michael A. Peters wrote:
LinuxManMikeC wrote:
On Fri, Jan 8, 2010 at 1:24 PM, Daevid Vincent <[email protected]> wrote:
I'm having a debate with a co-worker about adding the final ?> on a PHP
page...

So everybody, when do we get to the real discussion?  Which end of an
egg do we break?


Depends upon how far away the Perl developer is when we throw it, and how much spin we put on it.

You'll want to know initial release speed and drag on the egg while in flight to calculate time so you can correctly determine how many spins occur over the throw distance.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:

> Michael A. Peters wrote:
> > LinuxManMikeC wrote:
> >> On Fri, Jan 8, 2010 at 1:24 PM, Daevid Vincent <[email protected]> wrote:
> >>> I'm having a debate with a co-worker about adding the final ?> on a PHP
> >>> page...
> >>>
> >> So everybody, when do we get to the real discussion?  Which end of an
> >> egg do we break?
> >>
> > 
> > Depends upon how far away the Perl developer is when we throw it, and 
> > how much spin we put on it.
> 
> You'll want to know initial release speed and drag on the egg while in 
> flight to calculate time so you can correctly determine how many spins 
> occur over the throw distance.
> 
> Cheers,
> Rob.
> -- 
> http://www.interjinn.com
> Application and Templating Framework for PHP
> 


There's always a chance that if thrown, the egg won't contact end-on.
Has anyone thought to factor this in?

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
At 5:24 PM +0000 1/12/10, Ashley Sheridan wrote:
On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:

-- egg snip-its

While on the subject of eggs and other non-php topics, here's a life trick.

If you don't know if an egg is hard-boiled, or not, try spinning it. A hard-boiled egg will spin while a raw egg will not.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
On Tue, 2010-01-12 at 12:52 -0500, tedd wrote:

> At 5:24 PM +0000 1/12/10, Ashley Sheridan wrote:
> >On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:
> 
> -- egg snip-its
> 
> While on the subject of eggs and other non-php topics, here's a life trick.
> 
> If you don't know if an egg is hard-boiled, or not, try spinning it. 
> A hard-boiled egg will spin while a raw egg will not.
> 
> Cheers,
> 
> tedd
> 
> -- 
> -------
> http://sperling.com  http://ancientstones.com  http://earthstones.com
> 


Is that just a cruel joke to get us all covered with raw egg? :p

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Tue, Jan 12, 2010 at 05:24:06PM +0000, Ashley Sheridan wrote:

> On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:
> 
> > Michael A. Peters wrote:
> > > LinuxManMikeC wrote:
> > >> On Fri, Jan 8, 2010 at 1:24 PM, Daevid Vincent <[email protected]>
> wrote:
> > >>> I'm having a debate with a co-worker about adding the final ?> on a PHP
> > >>> page...
> > >>>
> > >> So everybody, when do we get to the real discussion?  Which end of an
> > >> egg do we break?
> > >>
> > >
> > > Depends upon how far away the Perl developer is when we throw it, and
> > > how much spin we put on it.
> >
> > You'll want to know initial release speed and drag on the egg while in
> > flight to calculate time so you can correctly determine how many spins
> > occur over the throw distance.
> >
> > Cheers,
> > Rob.
> > --
> > http://www.interjinn.com
> > Application and Templating Framework for PHP
> >
> 
> 
> There's always a chance that if thrown, the egg won't contact end-on.
> Has anyone thought to factor this in?

Is that an African or European egg?

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---
On Tue, 2010-01-12 at 13:10 -0500, Paul M Foster wrote:

> On Tue, Jan 12, 2010 at 05:24:06PM +0000, Ashley Sheridan wrote:
> 
> > On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:
> > 
> > > Michael A. Peters wrote:
> > > > LinuxManMikeC wrote:
> > > >> On Fri, Jan 8, 2010 at 1:24 PM, Daevid Vincent <[email protected]>
> > wrote:
> > > >>> I'm having a debate with a co-worker about adding the final ?> on a 
> > > >>> PHP
> > > >>> page...
> > > >>>
> > > >> So everybody, when do we get to the real discussion?  Which end of an
> > > >> egg do we break?
> > > >>
> > > >
> > > > Depends upon how far away the Perl developer is when we throw it, and
> > > > how much spin we put on it.
> > >
> > > You'll want to know initial release speed and drag on the egg while in
> > > flight to calculate time so you can correctly determine how many spins
> > > occur over the throw distance.
> > >
> > > Cheers,
> > > Rob.
> > > --
> > > http://www.interjinn.com
> > > Application and Templating Framework for PHP
> > >
> > 
> > 
> > There's always a chance that if thrown, the egg won't contact end-on.
> > Has anyone thought to factor this in?
> 
> Is that an African or European egg?
> 
> Paul
> 
> -- 
> Paul M. Foster
> 


Hehe, a fan of Monty Python I see!

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
On Tue, Jan 12, 2010 at 06:08:59PM +0000, Ashley Sheridan wrote:

> On Tue, 2010-01-12 at 13:10 -0500, Paul M Foster wrote:
> 
>     On Tue, Jan 12, 2010 at 05:24:06PM +0000, Ashley Sheridan wrote:
> 

<snip>

>     >
>     >
>     > There's always a chance that if thrown, the egg won't contact end-on.
>     > Has anyone thought to factor this in?
> 
>     Is that an African or European egg?
> 
>     Paul
> 
>     --
>     Paul M. Foster
> 
> 
> 
> Hehe, a fan of Monty Python I see!

Heck yeah. I can even program in their language a little bit!

Paul

-- 
Paul M. Foster

--- End Message ---
--- Begin Message ---

----- Original Message ----- From: "Paul M Foster" <[email protected]>
To: "Ashley Sheridan" <[email protected]>
Cc: <[email protected]>
Sent: Tuesday, January 12, 2010 7:25 PM
Subject: Re: [PHP] POLL: To add the final ?> or not...


On Tue, Jan 12, 2010 at 06:08:59PM +0000, Ashley Sheridan wrote:

On Tue, 2010-01-12 at 13:10 -0500, Paul M Foster wrote:

    On Tue, Jan 12, 2010 at 05:24:06PM +0000, Ashley Sheridan wrote:


<snip>

    >
    >
> There's always a chance that if thrown, the egg won't contact end-on.
    > Has anyone thought to factor this in?

    Is that an African or European egg?

    Paul

    --
    Paul M. Foster



Hehe, a fan of Monty Python I see!

Heck yeah. I can even program in their language a little bit!

Paul

--
Paul M. Foster

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


I can't  find those egg-functions really - where do I look ?

REB
--- End Message ---
--- Begin Message ---
tedd wrote:
At 5:24 PM +0000 1/12/10, Ashley Sheridan wrote:
On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:

-- egg snip-its

While on the subject of eggs and other non-php topics, here's a life trick.

If you don't know if an egg is hard-boiled, or not, try spinning it. A hard-boiled egg will spin while a raw egg will not.

I didn't bother to try, but knowing about physics and fluids, I'm going to argue that your assertion is untrue. The raw egg will spin but will quickly slow down due to the internal drag of the viscous contents that will be spinning at a much slower rate. In contrast the hard boiled egg will not have this internal drag.

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
At 3:49 PM -0500 1/12/10, Robert Cummings wrote:
tedd wrote:
At 5:24 PM +0000 1/12/10, Ashley Sheridan wrote:
On Tue, 2010-01-12 at 12:22 -0500, Robert Cummings wrote:

-- egg snip-its

While on the subject of eggs and other non-php topics, here's a life trick.

If you don't know if an egg is hard-boiled, or not, try spinning it. A hard-boiled egg will spin while a raw egg will not.

I didn't bother to try, but knowing about physics and fluids, I'm going to argue that your assertion is untrue. The raw egg will spin but will quickly slow down due to the internal drag of the viscous contents that will be spinning at a much slower rate. In contrast the hard boiled egg will not have this internal drag.

Cheers,
Rob.

Truth is relative when debating the spin of an egg. Of course, just about everything you can hold, you can spin to some degree.

The point being, if you want a quick way to determine if an egg is hard-boiled, or not, then spinning it will provide convincing evidence as to which it is. The truth will be shown to those who try.

Cheers,

tedd

--
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com

--- End Message ---
--- Begin Message ---
Hi, 

  Thanks for the replies. 

  Turns out that I can assign a variable $array_count = 
array_count_values($friend_from), and I accessed the individual values by doing 

for ($i=0;$i<$total_num;$i++) {

    $friend_location = $friend_from[$i];  
    $count_friend = $array_count[$friend_location];      
    echo $count_friend . "\n";    
}

Thanks again. 

Alice

> Date: Tue, 12 Jan 2010 13:17:57 -0300
> Subject: Re: [PHP] array_count_values Problem
> From: [email protected]
> To: [email protected]
> CC: [email protected]
> 
> Hi,
> 
> The function array_count_values returns an array
> (http://php.net/array_count_values). So you are using it the wrong
> way, you should assign the return value to a variable and then access
> some index.
> 
> Regards,
> 
> Jonathan
> 
> On Tue, Jan 12, 2010 at 11:09 AM, Alice Wei <[email protected]> wrote:
> >
> > Hi,
> >
> >  I have a code in the following, after investigating more closely on how to 
> > use array_count_values():
> >
> >  //Calculate the number of elements in array
> > $total_num = count($friend_from);
> > $total_num2 = count(array_unique($friend_from));
> > for ($i=0;$i<=$total_num2;$i++) echo $friend_from[$i] . " " . 
> > array_count_values($friend_from[$i]) . "\n";
> >
> >  Neither of these two numbers, $total_num and $total_num2 are 0, but I only 
> > get something like this:
> >
> > Monroe, IN
> > Cherokee, OK
> > Cherokee, OK
> > Cleveland, OK
> > Greer, OK
> >  How come that I cannot get it to print out the individual 
> > array_count_values? Have I missed something here?
> >  Thanks for your help.
> >
> >
> > _________________________________________________________________
> > Hotmail: Trusted email with powerful SPAM protection.
> > http://clk.atdmt.com/GBL/go/196390707/direct/01/
                                          
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
http://clk.atdmt.com/GBL/go/196390710/direct/01/

--- End Message ---
--- Begin Message ---
In Online Document say's:
Users may not change the array itself from the callback function. e.g.
Add/delete elements, unset elements, etc. If the array that
array_walk() is applied to is changed, the behavior of this function
is undefined, and unpredictable.

So I'm use Use Optional param( [, mixed $userdata ])

here is my code
========================================================
$return=array();
$disable_full=array('a','b','c');
$disable_start=array('_','!','HTTP'/*,'ddd','ddd','ddd','ddd','ddd'*/);
$check_array=array("a"=>1,"_POST"=>'c',"HTTP"=>"f","ddd"=>array('fefe'));
array_walk($check_array,'walk_fun_with_foreach',&$return);

print_r($return);

function walk_fun_with_foreach(&$source,$key,$return){
        global $disable_full,$disable_start;
        //var_dump($key);
        if(is_array($source)){
                array_walk($source,'walk_fun_with_foreach',&$return);
        }else{
                
                if(in_array(strval($key),$disable_full)){
                        //exit;
                        return;
                }else{
                        foreach($disable_start as $key1 => $value){
                                if(strpos($key,$value)===0){
                                        //echo $key;
                                        return;
                                }
                        }
                }
                //echo $key;
                $return[$key]=$source;
        }
}
==========================================================
it's print :
Array ( [0] => fefe )

but in version php5.2.x and higher version,display Warning message:
Warning: Call-time pass-by-reference has been deprecated in

If I'm change
array_walk($check_array,'walk_fun_with_foreach',&$return);
to
array_walk($check_array,'walk_fun_with_foreach',$return);

and
declare function like
function walk_fun_with_foreach(&$source,$key,&$return)
no Warning Display
But result is not my needed.
Anyone has solution about is?I'm don't like use foreach for
instead,beacuse of some preformance reason.

--- End Message ---
--- Begin Message ---
1.add
WITHOUT_X11=yes
in /etc/make.conf
2.remove
X11BASE=""
from that file and

4.make all-depend-list
5.make clean all depend soft
6.make menuconfig set X11 disable
7.make &&make install


2010/1/12 Don O'Neil <[email protected]>:
> Ok.. just for grins I installed a new instance of 6.1, NO Patches, just
> straight off the ISO...
>
> I loaded the ports that came WITH the distro, and was able to make php 5.1.2
> ok...
>
> When I did a portsnap fetch, portsnap extract, then went into the
> /usr/ports/lang/php5 and just typed make I get the same error...
>
> SO as it seems, the port is broken, at least for working with FreeBSD 6.1.
>
> Can anyone give me some hints on how to build this sucker by hand? Seems as
> though there are a bunch of patches that are referenced in the distinfo
> file.
>
> I REALLY need to get this taken care of asap, any help is appreciated.
>
> Thanks!
>
>> > > I tried adding WITHOUT_X11=yes to /etc/make.conf as well as
>> X11BASE=
>> > and
>> > > X11BASE="", but I still get the same error.
>> >
>> > Remove them. This makes sure they are not defined, not even
>> > empty (as in "#define BLA -> symbol 'BLA' is defined").
>> >
>> > > Where to go from here? Do I have and old version of something that
>> is
>> > > causing this? I get this error _right away_ before anything is even
>> > built.
>> >
>> > It seems to be a check by the Makefile at port's top level.
>>
>> Ok... I have no definition for X11BASE anywhere, not in my env, not in
>> my
>> /etc/make.conf, nowhwere...
>>
>> However, it's still complaining about X11BASE being deprecated. I tried
>> just
>> adding WITHOUT_X11=yes in /etc/make, and without it. I even searched
>> all the
>> Makefiles in /usr/ports, and in the /usr/ports/lang/php5 dir to find
>> any
>> reference to X11, or X, or X11BASE, but nada... I don't even know where
>> this
>> error message is being generated from.
>>
>> I can't even do a basic make without it immediately spitting out the
>> error:
>>
>> # make
>> X11BASE is now deprecated.  Unset X11BASE in make.conf and try again.
>> *** Error code 1
>>
>> Stop.
>>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
This is _exactly_ what I did, and as soon as I try a 'make all-depend-list'
the error shows up. I don't even have the X11 system installed (it's a
headless server, with no GUI).

This is on a CLEAN 6.1 install, without any upgrades/patches, just straight
off the ISO install and after a portsnap install/extract.

I tried building it _before_ I updated the ports and it would build a 5.1.2
php ok, but I need 5.2.12. Something has changed in the port between 5.1.2
and 5.2.12

> 1.add
> WITHOUT_X11=yes
> in /etc/make.conf
> 2.remove
> X11BASE=""
> from that file and
> 
> 4.make all-depend-list
> 5.make clean all depend soft
> 6.make menuconfig set X11 disable
> 7.make &&make install
> 
> 
> 2010/1/12 Don O'Neil <[email protected]>:
> > Ok.. just for grins I installed a new instance of 6.1, NO Patches,
> just
> > straight off the ISO...
> >
> > I loaded the ports that came WITH the distro, and was able to make
> php 5.1.2
> > ok...
> >
> > When I did a portsnap fetch, portsnap extract, then went into the
> > /usr/ports/lang/php5 and just typed make I get the same error...
> >
> > SO as it seems, the port is broken, at least for working with FreeBSD
> 6.1.
> >
> > Can anyone give me some hints on how to build this sucker by hand?
> Seems as
> > though there are a bunch of patches that are referenced in the
> distinfo
> > file.
> >
> > I REALLY need to get this taken care of asap, any help is
> appreciated.
> >
> > Thanks!
> >
> >> > > I tried adding WITHOUT_X11=yes to /etc/make.conf as well as
> >> X11BASE=
> >> > and
> >> > > X11BASE="", but I still get the same error.
> >> >
> >> > Remove them. This makes sure they are not defined, not even
> >> > empty (as in "#define BLA -> symbol 'BLA' is defined").
> >> >
> >> > > Where to go from here? Do I have and old version of something
> that
> >> is
> >> > > causing this? I get this error _right away_ before anything is
> even
> >> > built.
> >> >
> >> > It seems to be a check by the Makefile at port's top level.
> >>
> >> Ok... I have no definition for X11BASE anywhere, not in my env, not
> in
> >> my
> >> /etc/make.conf, nowhwere...
> >>
> >> However, it's still complaining about X11BASE being deprecated. I
> tried
> >> just
> >> adding WITHOUT_X11=yes in /etc/make, and without it. I even searched
> >> all the
> >> Makefiles in /usr/ports, and in the /usr/ports/lang/php5 dir to find
> >> any
> >> reference to X11, or X, or X11BASE, but nada... I don't even know
> where
> >> this
> >> error message is being generated from.
> >>
> >> I can't even do a basic make without it immediately spitting out the
> >> error:
> >>
> >> # make
> >> X11BASE is now deprecated.  Unset X11BASE in make.conf and try
> again.
> >> *** Error code 1
> >>
> >> Stop.
> >>
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> No virus found in this incoming message.
> Checked by AVG - www.avg.com
> Version: 9.0.725 / Virus Database: 270.14.136/2616 - Release Date:
> 01/11/10 23:35:00


--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Michael A. Peters [mailto:[email protected]] 
> Sent: Tuesday, January 12, 2010 2:46 AM
> To: Angus Mann
> Cc: [email protected]
> Subject: Re: [PHP] corect way to use mail() function
> 
> Angus Mann wrote:
> > There are only 11 types of people in this world. Those that 
> > think binary jokes are funny, those that don't, 
> > and those that don't know binary.
> > 
> > Er....Ummm.....shouldn't that read "...only 10 types of people..." ?
> > 
> > 
> > 
> 
> 1 - those that think they are funny
> 10 - those that don't
> 11 - those that don't know binary

LOL. 

Thanks Angus Mann for literally being the butt of my joke. :)

Thanks Michael for validating my point. :)

-D-


--- End Message ---
--- Begin Message ---


Daevid Vincent wrote:
-----Original Message-----
From: Michael A. Peters [mailto:[email protected]] Sent: Tuesday, January 12, 2010 2:46 AM
To: Angus Mann
Cc: [email protected]
Subject: Re: [PHP] corect way to use mail() function

Angus Mann wrote:
There are only 11 types of people in this world. Those that think binary jokes are funny, those that don't, and those that don't know binary.

Er....Ummm.....shouldn't that read "...only 10 types of people..." ?



1 - those that think they are funny
10 - those that don't
11 - those that don't know binary

LOL.
Thanks Angus Mann for literally being the butt of my joke. :)

Thanks Michael for validating my point. :)

Shouldn't the enumeration start at 0 with a default value for said ID? Perhaps the following:

 0 - those that suck the life out of humour
 1 - those that think they are funny
10 - those that don't
11 - those that don't know binary

;)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
I did a query... then I display records like:

<table>
  <?php do { ?>
    <tr>
      <td><?php echo $row_cur['tid']; ?></td>
      <td>&nbsp;</td>
    </tr>
    <?php } while ($row_cur = mysql_fetch_assoc($cur)); ?>
</table>


Q: but how I i just display a particular record with out the do / while loop?

like just the 2nd record only:

i tried
<?php echo $row_cur['tid',2]; ?>
but this makes an error....

or $row_cur('tid',2) --- hmmm what's the syntax?



Thanks,
[email protected]
[db-10]


--- End Message ---
--- Begin Message ---
though you can fetch twice to get the 2nd row
$row_cur = mysql_fetch_assoc($cur); //skip 1st row
$row_cur = mysql_fetch_assoc($cur);
echo $row_cur['tid'];

you should really modify your sql statement, like 'select xxx from xx order
by xx limit 1, 1'  (limit 1,1 retrieve your 2nd row if you are using mysql)

On Tue, Jan 12, 2010 at 4:52 PM, [email protected] <[email protected]>wrote:

> I did a query... then I display records like:
>
> <table>
>  <?php do { ?>
>    <tr>
>      <td><?php echo $row_cur['tid']; ?></td>
>      <td>&nbsp;</td>
>    </tr>
>    <?php } while ($row_cur = mysql_fetch_assoc($cur)); ?>
> </table>
>
>
> Q: but how I i just display a particular record with out the do / while
> loop?
>
> like just the 2nd record only:
>
> i tried
> <?php echo $row_cur['tid',2]; ?>
> but this makes an error....
>
> or $row_cur('tid',2) --- hmmm what's the syntax?
>
>
>
> Thanks,
> [email protected]
> [db-10]
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

--- End Message ---
--- Begin Message ---
On Tue, 2010-01-12 at 13:52 -0800, [email protected] wrote:

> I did a query... then I display records like:
> 
> <table>
>    <?php do { ?>
>      <tr>
>        <td><?php echo $row_cur['tid']; ?></td>
>        <td>&nbsp;</td>
>      </tr>
>      <?php } while ($row_cur = mysql_fetch_assoc($cur)); ?>
> </table>
> 
> 
> Q: but how I i just display a particular record with out the do /  
> while loop?
> 
> like just the 2nd record only:
> 
> i tried
> <?php echo $row_cur['tid',2]; ?>
> but this makes an error....
> 
> or $row_cur('tid',2) --- hmmm what's the syntax?
> 
> 
> 
> Thanks,
> [email protected]
> [db-10]
> 
> 


Depends on how you're creating running the query. You could do something
like:

echo mysql_result($result, 1, 'fieldname');

Where $result is your result object and 1 is a 0 indexed array, so would
be the second result.

Thanks,
Ash
http://www.ashleysheridan.co.uk



--- End Message ---
--- Begin Message ---
[email protected] wrote on 12/01/2010 22:52:
I did a query... then I display records like:

<table>
  <?php do { ?>
    <tr>
      <td><?php echo $row_cur['tid']; ?></td>
      <td>&nbsp;</td>
    </tr>
    <?php } while ($row_cur = mysql_fetch_assoc($cur)); ?>
</table>


Q: but how I i just display a particular record with out the do / while loop?

Just use extract($row_cur); before the table starts. That would give you first row only

Another approach could be to add " LIMIT 1" to the end of your SQL statement

like just the 2nd record only:

i tried
<?php echo $row_cur['tid',2]; ?>
but this makes an error....

or $row_cur('tid',2) --- hmmm what's the syntax?

Getting only second row, but not the first? That would be using a count var and show only data if count == 2


<table>
<?php
$count=0;
do {
$count++;
if($count == 2) {
  echo '
    <tr>
      <td>'. $row_cur['tid'] .'</td>
      <td>&nbsp;</td>
    </tr>';
  }
} while ($row_cur = mysql_fetch_assoc($cur));
?>
</table>


Another thing: drop the do and use this syntax instead, it's more readable:

<table>
<?php
$count=0;
while ($row_cur = mysql_fetch_assoc($cur)) {
  $count++;
  if($count == 2) {
    echo '
    <tr>
      <td>'. $row_cur['tid'] .'</td>
      <td>&nbsp;</td>
    </tr>';
  }
}
?>
</table>


--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Kim Madsen [mailto:[email protected]] 
> Sent: Tuesday, January 12, 2010 2:17 PM
> To: [email protected]
> Cc: [email protected]
> Subject: Re: [PHP] Display just 1 record in a query
> 
> [email protected] wrote on 12/01/2010 22:52:
> > I did a query... then I display records like:
> > 
> > <table>
> >   <?php do { ?>
> >     <tr>
> >       <td><?php echo $row_cur['tid']; ?></td>
> >       <td>&nbsp;</td>
> >     </tr>
> >     <?php } while ($row_cur = mysql_fetch_assoc($cur)); ?>
> > </table>
> > 
> > 
> > Q: but how I i just display a particular record with out 
> the do / while 
> > loop?
> 
> Just use extract($row_cur); before the table starts. That 
> would give you 
> first row only
> 
> Another approach could be to add " LIMIT 1" to the end of 
> your SQL statement
> 
> > like just the 2nd record only:
> > 
> > i tried
> > <?php echo $row_cur['tid',2]; ?>
> > but this makes an error....
> > 
> > or $row_cur('tid',2) --- hmmm what's the syntax?
> 
> Getting only second row, but not the first? That would be 
> using a count 
> var and show only data if count == 2
> 
> 
> <table>
> <?php
> $count=0;
> do {
> $count++;
> if($count == 2) {
>    echo '
>      <tr>
>        <td>'. $row_cur['tid'] .'</td>
>        <td>&nbsp;</td>
>      </tr>';
>    }
> } while ($row_cur = mysql_fetch_assoc($cur));
> ?>
> </table>
> 
> 
> Another thing: drop the do and use this syntax instead, it's 
> more readable:
> 
> <table>
> <?php
> $count=0;
> while ($row_cur = mysql_fetch_assoc($cur)) {
>    $count++;
>    if($count == 2) {
>      echo '
>      <tr>
>        <td>'. $row_cur['tid'] .'</td>
>        <td>&nbsp;</td>
>      </tr>';
>    }
> }
> ?>
> </table>

Holy, Jesus, Marry and Joseph! You can't be serious with that?!
So you're going to loop over potentially hundreds or thousands of records
and only display one?
Wow. Speechless.

http://www.php.net/manual/en/function.mysql-data-seek.php

$result = mysql_query($query);
mysql_data_seek($result, 1); //rows start at 0, so second row is 1
$row = mysql_fetch_assoc($result);
echo $row['tid'];

But the real way I suggest is using the LIMIT portion of your SELECT
http://dev.mysql.com/doc/refman/5.0/en/select.html
Then you don't need to data_seek() as you would have pulled the exact row
you wanted.
If you wanted the second row, you would "LIMIT 1,1" 

Also, if you just did a basic loop and stored all your results in a
multi-dimensional array, then you would just pull that element.

$mydata = array();

while ($row = mysql_fetch_assoc($result)) $mydata[] = $row;
Then you would just echo $mydata[1]['tid'];

Or what I like to do:

while ($row = mysql_fetch_assoc($result)) $mydata[$row['id']] = $row;
Assuming you were trying to pull a specific record $tid = ID:
echo $mydata[$tid];


ÐÆ5ÏÐ 
Light travels faster than sound. This is why some people appear bright
until you hear them speak.


--- End Message ---
--- Begin Message ---
Daevid Vincent wrote on 13/01/2010 00:00:

Holy, Jesus, Marry and Joseph! You can't be serious with that?!
So you're going to loop over potentially hundreds or thousands of records
and only display one?
Wow. Speechless.

Either you're talking to dealtek or you didn't read my post very well:

"Another approach could be to add " LIMIT 1" to the end of your SQL statement"

I just pointed out different approaches and answered his questions. Of course I would use last or break on the count == 2 approach, not running through _any_ records after getting what I wanted. I don't really get the "like just the 2nd record only", but again, from the material we've seen it's hard to give the right advice

--
Kind regards
Kim Emax - masterminds.dk

--- End Message ---
--- Begin Message ---

On Jan 12, 2010, at 1:57 PM, Ashley Sheridan wrote:

Depends on how you're creating running the query. You could do something like:

echo mysql_result($result, 1, 'fieldname');

Where $result is your result object and 1 is a 0 indexed array, so would be the second result.

Thanks Ryan, Ashley & Kim for the good techniques...

- in my case I was trying to pull a random record from a query of Table1 - then do a 2nd query from 1st so

mysql_result worked fine for my needs like:


... do query 1... 'cur' - SELECT id FROM myTable1

$ran = rand(0, $totalRows_cur - 1); // pick random rec row within total count

$pick1 = mysql_result($cur, $ran); // get the ID from the choice - (like id=252)

... do query 2 // where relatedID = $pick1 of myTable2



cool - THANKS ALL!



Thanks,
[email protected]
[db-10]


--- End Message ---
--- Begin Message ---

[email protected] wrote:
On Jan 12, 2010, at 1:57 PM, Ashley Sheridan wrote:

Depends on how you're creating running the query. You could do something like:

echo mysql_result($result, 1, 'fieldname');

Where $result is your result object and 1 is a 0 indexed array, so would be the second result.

Thanks Ryan, Ashley & Kim for the good techniques...

- in my case I was trying to pull a random record from a query of Table1 - then do a 2nd query from 1st so

mysql_result worked fine for my needs like:


... do query 1... 'cur' - SELECT id FROM myTable1

$ran = rand(0, $totalRows_cur - 1); // pick random rec row within total count

$pick1 = mysql_result($cur, $ran); // get the ID from the choice - (like id=252)

... do query 2 // where relatedID = $pick1 of myTable2

Put your random logic into the query:

    SELECT
        something
    FROM
        somewhere
    WHERE
        condition
    ORDER BY
        RAND()
    LIMIT
        1

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Op 1/13/10 12:43 AM, Robert Cummings schreef:
> 
> [email protected] wrote:
>> On Jan 12, 2010, at 1:57 PM, Ashley Sheridan wrote:
>>
>>> Depends on how you're creating running the query. You could do 
>>> something like:
>>>
>>> echo mysql_result($result, 1, 'fieldname');
>>>
>>> Where $result is your result object and 1 is a 0 indexed array, so 
>>> would be the second result.
>>
>> Thanks Ryan, Ashley & Kim for the good techniques...
>>
>> - in my case I was trying to pull a random record from a query of 
>> Table1 - then do a 2nd query from 1st so
>>
>> mysql_result worked fine for my needs like:
>>
>>
>> ... do query 1... 'cur' - SELECT id FROM myTable1
>>
>> $ran = rand(0, $totalRows_cur - 1); // pick random rec row within 
>> total count
>>
>> $pick1 = mysql_result($cur, $ran); // get the ID from the choice - 
>> (like id=252)
>>
>> ... do query 2 // where relatedID = $pick1 of myTable2
> 
> Put your random logic into the query:
> 
>     SELECT
>         something
>     FROM
>         somewhere
>     WHERE
>         condition
>     ORDER BY
>         RAND()
>     LIMIT
>         1

please read the following to understand the consequences and
possible performance problems with this approach:

http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/

personally I go with the 2 query approach

 ... or even to use a specific field to store a generated random value
(with suitable index) for each record, the stored values can be regenerated
in an out-of-band process (e.g. cron job) ... such a setup would suffice in
situations where frontend response speed is of primary concern and it's
acceptable to return the same 'random' record over a given period (i.e.
the time between random value regeneration)

> Cheers,
> Rob.


--- End Message ---
--- Begin Message ---
Jochem Maas wrote:
Op 1/13/10 12:43 AM, Robert Cummings schreef:
[email protected] wrote:
On Jan 12, 2010, at 1:57 PM, Ashley Sheridan wrote:

Depends on how you're creating running the query. You could do something like:

echo mysql_result($result, 1, 'fieldname');

Where $result is your result object and 1 is a 0 indexed array, so would be the second result.
Thanks Ryan, Ashley & Kim for the good techniques...

- in my case I was trying to pull a random record from a query of Table1 - then do a 2nd query from 1st so

mysql_result worked fine for my needs like:


... do query 1... 'cur' - SELECT id FROM myTable1

$ran = rand(0, $totalRows_cur - 1); // pick random rec row within total count

$pick1 = mysql_result($cur, $ran); // get the ID from the choice - (like id=252)

... do query 2 // where relatedID = $pick1 of myTable2
Put your random logic into the query:

    SELECT
        something
    FROM
        somewhere
    WHERE
        condition
    ORDER BY
        RAND()
    LIMIT
        1

please read the following to understand the consequences and
possible performance problems with this approach:

http://www.titov.net/2005/09/21/do-not-use-order-by-rand-or-how-to-get-random-rows-from-table/

I was already aware of the issues with RAND(). However, at the very top it says:

  "if your table have just 50-100 rows, use whatever you want."

Without more information about the person's particular use case I would use the RAND() version for its simplicity :)

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP

--- End Message ---
--- Begin Message ---
Hello,

my idea is to make a backup of some paths of my laptop via PHP.

I like to use a MySQL Datebase to trace which file was uploaded from which
path and so on.

Also it should be uses to look up it is nessasery to backup this file
because it was changed since last time or not.

All this files should be uploaded to the SERVER in a special folder where
this files run to a tape backup machine.

I hope some one can give me some ideas for this.

Kind Regards
Jens Geier




--- End Message ---

Reply via email to