Get the ID generated in the last query

  • Vladimir707
  • Vladimir707's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 32
  • Thank you received: 0

Vladimir707 created the topic: Get the ID generated in the last query

Dear Colleagues,


I have a form "Create new product":
- textfield "product_name";
- textarea "description";
- textarea "price".
I have an insert integrator which link this form with "Product" table:
- PK product_id INT AUTO-INCREMENT;
- product_name VARCHAR;
- description TEXT;
- price INT.

I want the notification (echo/alert - whatever) "Product <name of product> is saved with id <product id>" to appear, when user submits the form.

How can I get this product id? Where should I use the mysql_insert_id() function?


Best regards,
Vladimir
#187464
  • Vladimir707
  • Vladimir707's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 32
  • Thank you received: 0

Vladimir707 replied the topic: Get the ID generated in the last query

Small clarification:
The column product_name is not unique. So the way through SQL query
SELECT product_id FROM Product WHERE product_name='some name'
is not a variant.
#187465
  • Posts: 1880
  • Karma: 57
  • Thank you received: 247

lovre replied the topic: Get the ID generated in the last query

Hello there Vladimir,

You could use this code in your "Before Form" piece and alter it a little to get it working for you:
$db = JFactory::getDbo();
$db->setQuery("Select Max(id) From #__mytable");
$id = $db->loadResult();
if( JRequest::getInt( 'ff_status', -1 ) == 0 ){
echo "<script type='text/javascript'>alert('$id');</script>";
}

If needed change the id value, #__mytable value in the code and in the end customize the string to your needs.

This should be a good working solution for your request. Please let us know if you need more help with this.

===============================================
Need to renew Pro Support?
Buy Here!
===============================================
Satisfied?
Consider a membership!
===============================================
Like us on Facebook
===============================================
Follow us on Twitter
===============================================
#188198
Moderators: ForumSupporttomeperica
Time to create page: 0.039 seconds

News and Updates

Get informed about new downloads, updates and more in our News and Updates newsletter.

New extension AnalyticsAnywhere released!

Track website visitors no matter if ad blockers are enabled! Check it out!

Lifetime Subscription

Special Offer! Get lifetime access to all of our current and future products and 2 years of professional support -- 149 for only 90!

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, WordPress® plugins, Joomla!® templates   this means, by purchasing a Lifetime Subscription you'll have it all covered!

Get it from here

3rd Party Discount - 25% Off

We help you to keep your costs under control. If you are a new member and purchased a form building tool from a different form vendor, then you'll get a 25% discount on our 1-Year or Lifetime Subscription plans.

How to receive the discount:

Send us a quick email to sales@crosstec.org with a proof of purchase (for example a paypal receipt), await payment instructions and enjoy your membership!

Pro Support Renewal Plans

If you just need professional support and no further access to downloads or simply want or need to renew professional support, you may choose between various support plans from here.