Jump to content

Archived

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

OLM3CA

Primary key

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 ?

Share this post


Link to post
Share on other sites
Don't even bother -- leave the UID alone.  And please rename the column to id, uid, something_id, anything but "no".  Why do you want the number to change?  You're not supposed to use it as a counter.

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
You should NEVER rely on the PK being any value at all.  You should be doing the following, which will work in the general case:

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

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
So get back uid & title, instead of using just title.

Share this post


Link to post
Share on other sites

×

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.