We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

This EE db Query Question

Development and Programming

@nnette's avatar
@nnette
109 posts
14 years ago
@nnette's avatar @nnette

$query = $this->EE->db->query(“SELECT field_id_1 FROM exp_channel_data”);

if ($query->num_rows() > 0) { foreach($query->result_array() as $row) { echo $row[‘field_id_1’].” \n”; } }


I am trying to get the value from “Field_ID_1” for the particular entry that is being viewed. However, the above code returns all the values in the table/all entries, not just the value for that specific entry.

Perhaps I am going about this in the wrong way? Basically, I need to use a php script to accomplish what I want, but I don’t know what variable to use in SELECT/FROM/WHERE that will give me the information related to that specific page. (Yes, I am using this code on the actual entry url page and not on the general ‘index’ page.)

Help!

Thanks in advance!

       
@nnette's avatar
@nnette
109 posts
14 years ago
@nnette's avatar @nnette

Ok, I’ve tried doing a simple query just to get the entry_id number of that particular entry page, and can’t even get that.

I’ve used GET, and REQUEST… I just get an ‘undefined variable’ error message.

How can I get the entry_id number using a query in a php script outside of the EE {variables}? Because the ee query function does not allow me to update, insert, or delete I have to do this in a php script… (No, SafeCracker will not help me, I’ve already looked at that option).

I simply need to do a php script and be able to return the entry_id…

I’ve tried:

<?php echo $_GET [“entry_id”]; ?> <?php echo $_REQUEST [“entry_id”]; ?>

Both return an error message. I’ve tried using “$entry_id” as well.

Why won’t this work?

pulls out hair

Any help would be appreciated.

       
Dave @ Exp:resso's avatar
Dave @ Exp:resso
465 posts
14 years ago
Dave @ Exp:resso's avatar Dave @ Exp:resso

Maybe I’m missing something obvious but can’t you just use your select query, and add a WHERE statement - such as WHERE entry_id == {segment_3} (may need quotes), and set the php parsing stage accordingly?

It’d help to know what you’re trying to accomplish, since everything you’ve mentioned could be done easily with a standard exp:channel:entries tag?

       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

Hi there @nnete,

Is this related to your other thread here?

I’m going to migrate this thread over into Development and Programming so the discussion can continue.

Feel free to start a new thread if you need further assistance.

Cheers,

       
@nnette's avatar
@nnette
109 posts
14 years ago
@nnette's avatar @nnette

Dave - Unfortunately you can’t use EE tags within php scripts.

Dan - They are sort of related, but not entirely.

       
Dan Decker's avatar
Dan Decker
7,338 posts
14 years ago
Dan Decker's avatar Dan Decker

@nnette,

You can use ExpressionEngine tags in PHP in your templates, but there are some rules at play. Have a look at this resource by Low. It details the ExpressionEngine parsing order fairly well.

Cheers!

       
@nnette's avatar
@nnette
109 posts
14 years ago
@nnette's avatar @nnette

Thanks, Dan. That might help me.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.