Closed Thread Icon

Topic awaiting preservation: mysql: insert into (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=27353" title="Pages that link to Topic awaiting preservation: mysql: insert into (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: mysql: insert into <span class="small">(Page 1 of 1)</span>\

 
redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 01-20-2006 02:53

Ok, I'm not sure how to ask this so it will make sense... but here we go. How does php/mysql decide where a data entry is going to go within the table?

For example... I'm wanting to display data that has been inserted into the table from most recent to least.

code:
connectDB();
	
$query = "SELECT * FROM newsTable";
$result = mysql_query($query);
$num = mysql_numrows($result);

for ($i = ($num - 1); $i >= 0; $i--)
{
	$id = mysql_result($result, $i, "id");
	$title = mysql_result($result, $i, "title");
	$title = unFormatDataForm($title);
		
	echo '<li><a href="index.php?cat=news&func=updateForm&id=' . $id . '">' . $title . '</a></li>';
}



The above code works just fine for displaying the data but for some reason when I'm inserting data it almost seems randomly placed...??

code:
$query = "INSERT INTO newsTable VALUES ('', '$title', '$content')"; 
mysql_query($query);



So, after adding I can look at the table via phpmyadmin and sometimes it sticks the data at the end of the table, sometimes it sticks it in the middle, and sometimes it sticks it at top... I was thinking that it would, by default, always stick it at the end but that is not the case. I looked for patterns in the content/title's I was adding but I can't seem to see any reason why...

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-20-2006 03:29

"where" it goes depends on how your table is set up.

How it gets displayed when you call it out depends on how your table is set up, and how you sort it.

If your 'id' field is set to auto increment, then using ORDER BY in your SELECT statement to sort by the id will sort it in order of entry.

You can also add a field that records the date and time the entry was added, and sort by that.

redroy
Paranoid (IV) Inmate

From: 1393
Insane since: Dec 2003

posted posted 01-20-2006 04:28

ORDER BY !! I see the light! Thank you DL!

DL-44
Lunatic (VI) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 01-20-2006 05:11



« BackwardsOnwards »

Show Forum Drop Down Menu