Page 1 of 1

SQL query

Posted: Fri Oct 15, 2004 6:55 am
by ratamaster
Hi you there, I tring to develop a system wich prints pics from a databa base, with a description of the pics too.And you can input in a series of input text fields values that they are submited to change the order of the pics display in a php file (file.php). I print a table with these pics, text description and an input text area, with the intention to input integer values. These values are handle by a script, to update the order of the pics in the database.

Next the html code wich output the table:

Code: Select all

$i=1;
While($row=mysql_fetch_object($result)) {
      $des1=mysql_fetch_object($result2);
      $orden= mysql_fetch_object($result3);
      print "<td>
                 <IMG SRC="header.php?PicNum=$row->PicNum" border="0" high="200" width ="100">
            </td>
            <td>
                 <p align='center'>$des1->des1</p>
            </td>
                 <td><p align='center'>$orden->orden</p>
            </td>
            <td>
                <p align= 'center'><input type='text' name='newO".$i++."'size='1' value=0 maxlength='15'></p>
            </td>";
            $counter += 1;
                print"</tr></table><input type='submit' name='orden' value='gogo'></form>";
}
Plase, look at line 14, while this script finds objects (pics) in the db, it prints a serie of html tags to bild a table, and more important, prints input areas with the names "newO1, newO2,newO3", and so on, in these fields I'll put diferent integer values
Now see line 17, when I press the submit button I reload this file (file.php)

Code: Select all

while($row=mysql_fetch_object($result)){
    mysql_query("UPDATE imagen SET orden = $newO1  WHERE PicNum = PicNum LIMIT 1") or die ("wrong ".mysql_error());//here is the problem
       }
I use a $_POST['orden'] to execute the code above, my problem resides in line 20, I can“t find a way to take all the values I put in newO$i++, as you can see, in this query I wrote "$newO1", and it works with the first field but not with others, and I wish to update all the values.

this is the table "imagen":

Code: Select all

PicNum int(11) auto_increment Primary
imagen blob BINARY
des1 varchar(25)
des2 varchar(255)
seccion varchar(10)
precio int(11)
orden int(11) //orden=order
I hope you can help me.

Alvaro


ps: sorry about my english :)

Posted: Fri Oct 15, 2004 1:28 pm
by kettle_drum
If you want to increment the value after the $new - $new01, $new02 - then you need some kind of loop to track what the number should be, and then prints that. So first thing is to replace the number with a variable which will hold the number value, and then increment this value on each loop. You then want to check out how to format numbers so that they begin with a 0 if its less than 10.

Give it ago, and if your still stuck ask for more help.

Posted: Mon Oct 18, 2004 3:36 pm
by ratamaster
feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


I still stuck, I did the next script but it dosen't work, havve youy any idea how can I rebild it?

Code: Select all

$k=1;
$result=mysql_query("SELECT * FROM imagen") or die("wrong");

while($row=mysql_fetch_object($result)){
      $n = $newO.$k;
       mysql_query("UPDATE imagen SET orden = $n WHERE PicNum = PicNum LIMIT 1") or die ("wrong".mysql_error());
       $k++;
       }
}else{
      print "xxx";

        }
this link http://lafiestarefinal.net/imageWeb/file.php show you I what did until now, and maybe it explains better what I want.

I hope this can help.

Alvaro


feyd | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]