Jump to content

how to insert the post id along?


lovephp

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?

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);
}
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.