OLM3CA Posted August 21, 2006 Share Posted August 21, 2006 Hi!İ have a question about the "no" section of my tablefor 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 ? Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/ Share on other sites More sharing options...
fenway Posted August 21, 2006 Share Posted August 21, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78343 Share on other sites More sharing options...
OLM3CA Posted August 22, 2006 Author Share Posted August 22, 2006 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 changeWhen i click on it no news is going to appear because newsID=4=no (primary key) is deleted Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78362 Share on other sites More sharing options...
fenway Posted August 22, 2006 Share Posted August 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78368 Share on other sites More sharing options...
OLM3CA Posted August 22, 2006 Author Share Posted August 22, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78378 Share on other sites More sharing options...
fenway Posted August 22, 2006 Share Posted August 22, 2006 So get back uid & title, instead of using just title. Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78418 Share on other sites More sharing options...
OLM3CA Posted August 22, 2006 Author Share Posted August 22, 2006 Thank you fenway I'have done it (: Quote Link to comment https://forums.phpfreaks.com/topic/18242-primary-key/#findComment-78512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.