Get the ID generated in the last query

  • Vladimir707
  • Vladimir707's Avatar Topic Author
  • Offline
  • Junior Boarder
  • Junior Boarder
  • Posts: 33
  • 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: 33
  • 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: 2667
  • Karma: 78
  • Thank you received: 326

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.

Support Crosstec and get ALL EXTENSIONS and professional support for just $5
Here!
===========================================
Need to renew Pro Support?
Buy Here!
===========================================
Satisfied?
Consider a membership!
===========================================
Like us on Facebook
===========================================
#188198
Moderators: ForumSupporttomeperica
Time to create page: 0.058 seconds

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here

News and Updates

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

All Extensions Subscription

Special Offer! Get 1 year access to all of our current and future products and 1 year of professional support -- 99 for only 55!

No support per domain or website installation limits! Includes all of our current and future Joomla!® extensions, WordPress® plugins, Joomla!® templates for the duration of your membership. This means, by purchasing an All Extensions 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 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!

Community Reward

Help us to create new extensions and plugins! With only $5 you help us a lot and get unlimited download access to all of our products, professional support and even more. Get your reward now!

Read More Here