Jasper Bryant-Greene | 1 Sep 01:22 2005

Re: ID based on position?

Gustav Wiberg wrote:
> Hi there!
> 
> Is there any function in PHP that gives an ID from a MySQL-db based on 
> which position the record has in the table?
> 
> Let's say, there's a table like this:
> 
> 1. Record1 ID 33
> 2. Record2 ID 76
> 3. Record3 ID 100
> 
> If I know position 2, I want to get ID 76. Is the only way to loop 
> through the recordset?

Why don't you use MySQL's LIMIT clause? Example:

SELECT * FROM myTable LIMIT 1,1

will retrieve the second row from myTable. You could combine that with 
WHERE clauses or whatever. Note that the LIMIT syntax is LIMIT 
[rowcount] or LIMIT [offset],[rowcount] and the offset starts at 0.

--

-- 
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

If you find my advice useful, please consider donating to a poor
student! You can choose whatever amount you think my advice was
(Continue reading)

Jason Davidson | 1 Sep 01:25 2005
Picon

Re: ID based on position?

You could LIMIT your query to the record number you are looking for, and 
grab the last element in the array from your result set. But this is a 
serious hack, and I am really wondering why you need to do what your asking, 
it seems (without knowing more) that you are tackling the problem in the 
wrong direction,

Jason

On 8/31/05, Gustav Wiberg <gustav <at> varupiraten.se> wrote:
> 
> Hi there!
> 
> Is there any function in PHP that gives an ID from a MySQL-db based on 
> which
> position the record has in the table?
> 
> 
> Let's say, there's a table like this:
> 
> 1. Record1 ID 33
> 2. Record2 ID 76
> 3. Record3 ID 100
> 
> 
> If I know position 2, I want to get ID 76. Is the only way to loop through
> the recordset?
> 
> /G
>  <at> varupiraten.se <http://varupiraten.se>
> 
(Continue reading)

hitek | 1 Sep 02:02 2005
Picon
Picon

Re: ZCE Reccommendations

Chris Shiflett wrote:

> hitek wrote:
>
>> I'm taking my ZCE exam soon and would like general advice on
>> what to study up on.
>
>
> This is a good resource:
>
> http://zend.com/store/education/certification/zend-php-certification-objectives.php 
>
>
> You picked a good month to take the exam, since it's $125 this month 
> (normally $200).
>
> Chris
>
Thanks for the tip. For the record, I passed :)

--

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

Miles Thompson | 1 Sep 02:38 2005

Re: ID based on position?


Auugh!!  Why would you want to do this? You're flying in the face of 
relational database theory and practice. Position of a record in the table 
is, or should be irrelevant.

What if you have twenty thousand records, or two hundred, and the 45th 
record in the table is deleted? Fetching an ID from anything beyond that 
record, based on the order of insertion (position), is instantly broken.

Please rethink what you want to do, and if you are not familiar with 
relational databases read some of the excellent tutorials available on the 
'Net about them and their design. It's pretty straightforward, common sense 
stuff -- but you can back yourself into an awkward corner.

Regards - Miles

At 07:54 PM 8/31/2005, Gustav Wiberg wrote:
>Hi there!
>
>Is there any function in PHP that gives an ID from a MySQL-db based on 
>which position the record has in the table?
>
>
>Let's say, there's a table like this:
>
>1. Record1 ID 33
>2. Record2 ID 76
>3. Record3 ID 100
>
>
(Continue reading)

Greg Donald | 1 Sep 06:36 2005
Picon

Re: ZCE Reccommendations

On 8/31/05, hitek <hitek <at> cox.net> wrote:
> For the record, I passed :)

Congrats.

-- 
Greg Donald
Zend Certified Engineer
MySQL Core Certification
http://destiney.com/

--

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

Mark Rees | 1 Sep 10:32 2005

Re: String format problem

> In fact, this is a poor example since the difference gets larger with
longer
> string and more arguments.  When you use dots, the interpreter has to
> actually concatenate the string, looking for memory to do so and freeing
it
> up afterwards.  This takes time.  With commas, each argument is sent to
the
> output stream as soon as it is found, no further processing is needed in
> between.
>

I have been wondering about this topic for a few months now, so thanks for
this fascinating explanation. Is this the only difference between using .
and , as concatenation operators>

> Then the single vs. double quotes:
>
> echo 'uno ' , ' dos ' , ' tres ': 0.94
> echo "uno " , " dos " , " tres ": 6.76
>
> Notice that when variables are involved, the difference in between echoing
> with arguments separated with commas and separated with dots is more than
9
> times faster for the commas.    Using double quotes with variable
expansion
> is almost 4 times slower than the commas, but is still faster than
> concatenating them externaly with dots.   Using heredoc-style strings is
not
> so bad compared to double quotes.

(Continue reading)

Ahmed Abdel-Aliem | 1 Sep 10:43 2005
Picon

array merge problem

i have the array with the following structure :

Array
(
    [19] => 20.00
    [25] => 20.00
    [7] => 30.00
    [17] => 30.00
)

when i merge a field to it using array_merge
it returns that :

Array
(
    [0] => 20.00
    [1] => 20.00
    [2] => 30.00
    [3] => 30.00
    [4] => 200.00
)

how can i merge the field without losing the original keys ?
can anyone help me with that plz
thanks in advance

--

-- 
Ahmed Abdel-Aliem
Web Developer
www.SafariStudio.net
(Continue reading)

Mark Rees | 1 Sep 10:47 2005

Re: ID based on position?

> Auugh!!  Why would you want to do this? You're flying in the face of
> relational database theory and practice. Position of a record in the table
> is, or should be irrelevant.

Agreed - "position" is a notional concept. The data is stored physically in
some sort of order, but what order that is is the database's business, not
yours. It could be subject to change when upgrading, and it is very likely
to differ on different platforms or RDBMSs.

You should also be aware that unless you use an order by clause in your
select statement, you don't have a guarantee that all RDBMSs will return the
records in the same row.

I don't know exactly what you want to do, perhaps you can provide more
details?

>
> What if you have twenty thousand records, or two hundred, and the 45th
> record in the table is deleted? Fetching an ID from anything beyond that
> record, based on the order of insertion (position), is instantly broken.
>
> Please rethink what you want to do, and if you are not familiar with
> relational databases read some of the excellent tutorials available on the
> 'Net about them and their design. It's pretty straightforward, common
sense
> stuff -- but you can back yourself into an awkward corner.
>
> Regards - Miles
>
>
(Continue reading)

The Gimper | 1 Sep 11:09 2005
Picon

fread and fgets (network streams)

On the php.net you can read the following about fread:

"fread() reads up to length bytes from the file pointer referenced by handle. 
Reading stops when length bytes have been read, EOF (end of file) is reached, 
or (for network streams) when a packet becomes available, whichever comes 
first."

Is this true with fgets also? The "when a packet becomes available" part that 
is. I´m guessing "for network streams" means when the handler is not a local 
file but a remote file, right?

Why i´m i asking this? Well because i have a script wich now uses fread to get 
a remote file and would like to change this to fgets but i´m afraid i will bump 
into truble if i do since the part about waiting for a packed to become 
available sounds pretty important when dealing with remote files, right?

Thanks!

-------------------------------------------------
FREE E-MAIL IN 1 MINUTE!
 - your.name <at> pc.nu - http://www.pc.nu

--

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

Shaw, Chris - Accenture | 1 Sep 11:11 2005
Picon

RE: array merge problem


<manual snippets>
If you want to completely preserve the arrays and just want to append them to
each other, use the + operator.

<?php
$array1 = array();
$array2 = array(1 => "data");
$result = $array1 + $array2;
?>

The numeric key will be preserved and thus the association remains.

Array
(
    [1] => data
)
</manual snippets>

Its actually on the same page as array_merge in array functions.

-----Original Message-----
From: Ahmed Abdel-Aliem [mailto:me2resh <at> gmail.com]
Sent: 01 September 2005 09:43
To: php-general <at> lists.php.net
Subject: [PHP] array merge problem

*************************************

This e-mail has been received by the Revenue Internet e-mail service.
(Continue reading)


Gmane