php-general Digest 17 Jun 2013 15:01:00 -0000 Issue 8268
Topics (messages 321416 through 321420):
Re: LightBox click detection
321416 by: Micky Hulse
Re: newbie PDO query display question
321417 by: dealTek
321418 by: Ashley Sheridan
321419 by: dealTek
321420 by: jomali
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On Fri, Jun 14, 2013 at 8:52 AM, Tedd Sperling <t...@sperling.com> wrote:
> Here's the problem -- I need to count the number of times a user activates a
> LightBox -- how do you do that?
If you're using Google Analytics, you can use click tracking:
<https://developers.google.com/analytics/devguides/collection/gajs/eventTrackerGuide>
I recently setup click tracking on lightbox open, close and various
other modal window bits/pieces for a metered pay wall system.
For example, within the lightbox/modal window "open" method:
[code]
// Track this lightbox instance:
window._gaq.push([
'_trackEvent', // Method.
'Paymeter Lightbox', // Group.
'Lightbox OPEN group ' + count_txt, // Append count to "action" text.
count_txt + ' OPEN event' // Prepend count to "label" text.
]);
[/code]
The advantage to using a common tool like analytics is that it's got a
ton of powerful ways to analyze the data.
Not sure the goal of your project, but I thought I would mention.
Cheers,
M
--- End Message ---
--- Begin Message ---
On Jun 16, 2013, at 3:37 PM, Stephen <stephe...@rogers.com> wrote:
> Here is a sample from my code:
>
> $photo_category_list = "";
> $SQL = "SELECT category_id, category_name FROM gallery_category ORDER by
> category_order";
> try {
> $stmt = $dbh->prepare($SQL);
> $stmt->execute();
> while ( list( $id, $name) = $stmt->fetch(PDO::FETCH_NUM)) {
> $photo_category_list .= "<option value=$id>$name</option>\n";
> }
> }
> catch (PDOException $e){
> echo 'Error getting category name. ' . $e->getMessage();
> }
> return $photo_category_list;
>
> Try to avoid your code assuming that you will just get one record back
> (unless you use Limit 1)
>
Thanks Stephen,
Nice code!
you mentioned ... - to avoid your code assuming that you will just get one
record back
But what about the case where you are deliberately just showing one record as
in ---- FIND ONE PERSON like---- where ID = 101 ?
do you still need to loop through when you just selected/displayed 1 ITEM?
Q: How do I display the columns without a loop in this 1 record case...?
these fail - so what will work?
echo $results["First"];
echo $results["First"][0]; ???
echo $results["First"][1]; ???
> While works better than foreach for getting the result rows from PDO
--
Thanks,
Dave - DealTek
deal...@gmail.com
[db-3]
--- End Message ---
--- Begin Message ---
dealTek <deal...@gmail.com> wrote:
>
>On Jun 16, 2013, at 3:37 PM, Stephen <stephe...@rogers.com> wrote:
>
>> Here is a sample from my code:
>>
>> $photo_category_list = "";
>> $SQL = "SELECT category_id, category_name FROM gallery_category
>ORDER by category_order";
>> try {
>> $stmt = $dbh->prepare($SQL);
>> $stmt->execute();
>> while ( list( $id, $name) = $stmt->fetch(PDO::FETCH_NUM)) {
>> $photo_category_list .= "<option
>value=$id>$name</option>\n";
>> }
>> }
>> catch (PDOException $e){
>> echo 'Error getting category name. ' . $e->getMessage();
>> }
>> return $photo_category_list;
>>
>> Try to avoid your code assuming that you will just get one record
>back (unless you use Limit 1)
>>
>
>
>Thanks Stephen,
>
>Nice code!
>
>you mentioned ... - to avoid your code assuming that you will just get
>one record back
>
>But what about the case where you are deliberately just showing one
>record as in ---- FIND ONE PERSON like---- where ID = 101 ?
>
>do you still need to loop through when you just selected/displayed 1
>ITEM?
>
>Q: How do I display the columns without a loop in this 1 record
>case...?
>
>
>these fail - so what will work?
>
>echo $results["First"];
>echo $results["First"][0]; ???
>echo $results["First"][1]; ???
>
>
>
>> While works better than foreach for getting the result rows from PDO
>
>
>
>
>
>
>
>
>--
>Thanks,
>Dave - DealTek
>deal...@gmail.com
>[db-3]
Have you tried chaining the the fetch() method on as in:
$pdo_object->query()->fetch();
Thanks,
Ash
--- End Message ---
--- Begin Message ---
>>
>>
> When you know there is only one row to be returned you can do this:
>
> $photo_category_list = "";
> $SQL = "SELECT category_id, category_name FROM gallery_category ORDER by
> category_order";
> try {
> $stmt = $dbh->prepare($SQL);
> $stmt->execute();
> list( $id, $name) = $stmt->fetch(PDO::FETCH_NUM));
> }
> }
> catch (PDOException $e){
> echo 'Error getting category name. ' . $e->getMessage();
> }
>
> echo $id;
> echo $name;
>
> And you could also do
>
> list( $result["id"], $result["name"]) = $stmt->fetch(PDO::FETCH_NUM));
>
>
> --
> Stephen
>
Thanks very much for your help Stephen - I will try this asap!
--
Thanks,
Dave - DealTek
deal...@gmail.com
[db-3]
--- End Message ---
--- Begin Message ---
On Sun, Jun 16, 2013 at 6:29 PM, dealTek <deal...@gmail.com> wrote:
> Hi all,
>
> newbie PDO question...
>
> I think (hard to tell - buried in a wrapper class) I am doing a select
> query using - PDO::FETCH_ASSOC like...
>
> wrapper ------ return $pdostmt->fetchAll(PDO::FETCH_ASSOC);
>
> ---
>
> so my query is like...
>
> $results = $db->select("mytable", "id = 201"); //just 1 exact record)
>
> then I can loop like......
> foreach ($results as $result) {
> ....
> ?>
>
> <tr>
> <td><?php echo $result["First"]; ?></td>
> <td><?php echo $result["Last"]; ?></td>
> <td><?php echo $result["id"]; ?></td>
>
> </tr>
>
> This all works fine.....
>
> ---> But since I only have 1 exact record - I don't need to LOOP anything
> - so...
>
> Q: How do I display the columns without a loop
>
>
> these fail - so what will work
>
> echo $results["First"];
> echo $results["First"][0]; ???
> echo $results["First"][1]; ???
>
>
> PDO::fetchAll returns its data as an array, even if only one record is
returned. In this case,
echo $results[0]["First"];
echo $results[0]["Last];
echo $results[0]["id"];
will do what you want.
<snip>
--- End Message ---