Jump to content

Primary key


OLM3CA

Recommended Posts

Hi!
İ have a question about the "no" section of my table
for example i have a table that includes no,title,message,date i make
"no" =  int primary key auto_incremente etc...
mysql automaticly number the titles with "no" (1,2,3 )
but when i delete a title (ex: the 3rd one) and then add another title,the "no" is 4 for the new title.i want it to be get the number 3 ? how can i make it ?
Link to comment
Share on other sites

becouse I am using it in links:

[code]<?php
echo "<a href='?newsID=$i'>".$row['title']."</a>";
$i = $i + 1;
?>[/code]

and in sql :

[code]$sorgu2="SELECT * FROM news WHERE no=$newsID ";[/code]

and "no" is my primary key,for example if i delete 4rd news my link will be : [color=red]newsID=4[/color] the counter "i" does not change
When i click on it no news is going to appear because newsID=4=no (primary key) is deleted
Link to comment
Share on other sites

but my query is diffrent i am so confused can you help me with this.
I want to show 10 news on homepage and when i click one of them i have to see details of that news.

[code]$query1 = "SELECT title FROM news LIMIT 0, 10";
$query2="SELECT * FROM news WHERE no=$newsID ";
$result1 = mysql_query($query1);
$result2 = mysql_query($query2);[/code]

// I AM USING THIS TO SHOW THE NEWS TITLES LINKS
[code]$i=1; while ($row = mysql_fetch_array($result1)) {

                                    echo "<a href='?newsID=$i'>".$row['title']."</a>";
$i = $i + 1;
}[/code]


// I AM USING THİS TO SHOW THE DETAILS OF NEWS

[code]while ($row2 = mysql_fetch_array($result2)) {


      echo $row2['title];
   
      echo $row2['fullpart'];


[/code]
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.