Jump to content

how to insert the post id along?


lovephp
Go to solution Solved by Muddy_Funster,

Recommended Posts

ok im trying to make seo url im creating slug ok but how do i insert along the id of that post?

 

doing this following is definitely wrong im sure because i get 0 instead

 

 $id = $db->lastInsertId('id');            
        $stmt->execute(array(
                     ':poster' => $uid,
                     ':title' => $title,
                     ':mobile' => $mobile,
                     ':email' => $email,
                     ':seourl' => ''.$id.'/'.$seourl

 

how on earth i can acheive that?

Edited by lovephp
Link to comment
Share on other sites

 

ok, change the following and let us know what it gives you:

 $id = $db->lastInsertId('id');  

becomes

 $id = $db->lastInsertId();
var_dump('last-insert-id = '.$id);

i did this

 

 $id = $db->lastInsertId();
         var_dump('last-insert-id = '.$id);           

                $stmt->execute(array(
                     ':poster' => $uid,
                     ':title' => $title,
                     ':mobile' => $mobile,
                     ':email' => $email,
                     ':seourl' => ''.$id.'/'.$seourl

 

but still 0 gets added in db not the id an also in browser i get this printed string 'last-insert-id = 0' (length=18)

Link to comment
Share on other sites

yes bro in db the posted id is 8 here is how i exactly tried

$stmt = $db->prepare('INSERT INTO table (poster,title,mobile,email,seourl) VALUES (:(poster, :title, :mobile, :email, :seourl)');         

$id = $db->lastInsertId();
var_dump('last-insert-id = '.$id);           

$stmt->execute(array(
  ':poster' => $uid,
  ':title' => $title,
  ':mobile' => $mobile,
  ':email' => $email,
  ':seourl' => ''.$id.'/'.$seourl
));

Link to comment
Share on other sites

So you're trying to get the ID of the record you're just inserting? That's impossible. MySQL cannot predict the future.

 

What's the whole point of the seourl field, anyway? If it's just the ID and the slugified title, then you can create the URL dynamically. There's no need to physically store it in the database.

Link to comment
Share on other sites

I'm not your bro.

 

The URLs in this forum are probably generated dynamically. As I already said, it's just the ID concatenated with a URL-friendly version of the title:

function get_topic_url($topic_id)
{
    $title = get_topic_title($topic_id);

    return $topic_id.'-'.slugify($title);
}
  • Like 1
Link to comment
Share on other sites

 

I'm not your bro.

 

The URLs in this forum are probably generated dynamically. As I already said, it's just the ID concatenated with a URL-friendly version of the title:

function get_topic_url($topic_id)
{
    $title = get_topic_title($topic_id);

    return $topic_id.'-'.slugify($title);
}

i tried something like this and seems to be working

 

$stmt = $db->prepare('INSERT INTO table (poster,title,mobile,email,seourl) VALUES (:(poster, :title, :mobile, :email, :seourl)');        
$stmt->execute(array(
  ':poster' => $uid,
  ':title' => $title,
  ':mobile' => $mobile,
  ':email' => $email,
  ':seourl' => ''.$id.'/'.$seourl
));

 $id = $db->lastInsertId();        
  $seturl = ''.$id.'/'.$seourl.'';
  $qry = "UPDATE jobs SET seourl = :seourl WHERE id = :id";
  $stmt = $db->prepare($qry);                  
  $stmt->bindParam(':seourl', $seturl);      
  $stmt->bindParam(':id', $id);            
  $stmt->execute();
 

 

does it makes sense or should i remove it? do you think i should do it like this?

Link to comment
Share on other sites

 

I'm not your bro.

 

The URLs in this forum are probably generated dynamically. As I already said, it's just the ID concatenated with a URL-friendly version of the title:

function get_topic_url($topic_id)
{
    $title = get_topic_title($topic_id);

    return $topic_id.'-'.slugify($title);
}

and sorry bout the (Bro) apology if it offended you in any ways.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.