db insert row before the first one

Started by Azoula, February 01, 2015, 09:55:48 AM

Previous topic - Next topic

Azoula

Hi guys as the title how can i insert the new row before the first one 0.

$sql = 'INSERT INTO updates VALUES("'.$....... .'")';
mysql_query($sql);

margarett

It's not really relevant in which position a row is entered. What are you trying to do?
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Azoula

just i want to change the postion example:

before:

row 1 -- last
row 2 -- new

after

row 2 -- new
row 1 -- last

all what i need is new row will be on the top.

margarett

Yeah but that's not really how it works... Each table has usually an id and that's what defines the order. But you can't just go and swap ids because it can mess other things...

Are you trying to change the order of replies, topics, or...
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Arantor

In addition, you can have other fields in a table that define the order but trying to physically force the order actually in the table is an extremely bad idea - if it's even possible. It will not be possible in InnoDB tables, which is why you add other columns and use ORDER BY.

Hard to know how to help without knowing what you're trying to do (because we just told you that the 'how' you're trying to do it isn't going to work)

Azoula

np guys i already fixed it please one more question , i add a new custom action using integration hooks and i want to put all db data inside it (Body).

i tried this and it's working fine but the poblem i can't see the text inside the body.

$base = mysql_connect ('localhost', 'user.', 'pass');
        mysql_select_db ('db', $base);
        $sql = 'SELECT * FROM updates';
        $req = mysql_query($sql);
        while($data = mysql_fetch_array($req)){
        $up = $data['update'];
        echo "$up<br />";


how can i put it inside $context because i'm using SMF template.

$context['updateLog_Body'] =' here'

i'm sorry about my english.

Kindred

Ummm....   that code looks like it is just RIPE for an injection attack....
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

margarett

You should, first and foremost, use $smcFunc functions correctly (so that you are protected against these injections)

Then you just need to use $context['updateLog_Body'] where $up is ;)

And you need to globalize $context in your function.
Se forem conduzir, não bebam. Se forem beber... CHAMEM-ME!!!! :D

QuoteOver 90% of all computer problems can be traced back to the interface between the keyboard and the chair

Azoula

bro please can u explane how to do it please i'm Newbie.

Advertisement: