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
https://forums.phpfreaks.com/topic/18242-primary-key/
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
https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78362
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
https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78378
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.