Forum Moderators: coopster
Im doing a little update page where theres a text box on the screen called id_top and a hidden field called command which are submitted via a form to the same page, now when you type the id number for the product you want to retrieve info on to perform an update, the code is jumping to the row not the id in the products table?
its like
<?php
$id_top = $_GET["id_top"];
$command = $_GET["command"];
$sql2 = " SELECT * FROM products where id = '$id_top' ";
$result2 = mysql_query($sql2);
?>
the result bring like row 69 from the table instead of id 69?
this causes probs when the row number doesnt match the id number of the table due to editing adding and removing all the time,
im wondering if its the code further down the page thats buggedring it up for me, here have a nosey
<?php if ($command = 1) {
$prod_name = mysql_result($result,$id_top,'prod_name');
$price = mysql_result($result,$id_top,'price');
$colour = mysql_result($result,$id_top,'colour');
$brand = mysql_result($result,$id_top,'brand');
$person = mysql_result($result,$id_top,'person');
$related = mysql_result($result,$id_top,'related_code');
$related2 = mysql_result($result,$id_top,'related_code2');
$stock= mysql_result($result,$id_top,'stock');
$prod_desc = mysql_result($result,$i,'prod_desc');
$s1 = mysql_result($result,$id_top,'s1');
$s2 = mysql_result($result,$id_top,'s2');
$s3 = mysql_result($result,$id_top,'s3');
$s4 = mysql_result($result,$id_top,'s4');
$s5 = mysql_result($result,$id_top,'s5');
$s6 = mysql_result($result,$id_top,'s6');
$s7 = mysql_result($result,$id_top,'s7');
$s8 = mysql_result($result,$id_top,'s8');
$s9 = mysql_result($result,$id_top,'s9');
$s10 = mysql_result($result,$id_top,'s10');
$s11 = mysql_result($result,$id_top,'s11');
$s12 = mysql_result($result,$id_top,'s12');
$s13 = mysql_result($result,$id_top,'s13');
$s14 = mysql_result($result,$id_top,'s14');
$s15 = mysql_result($result,$id_top,'s15');
$s16 = mysql_result($result,$id_top,'s16');
$s17 = mysql_result($result,$id_top,'s17');
$s18 = mysql_result($result,$id_top,'s18');
$s19 = mysql_result($result,$id_top,'s19');
$s20 = mysql_result($result,$id_top,'s20');
//This is closed further down the page after some html form stuff
?>
why does it bring the row number in the tablr and no the info for the correct id from the table?
i got more code on the page but dont think that is effecting it in anyway?
can you guys see any problems?
help plz
thanx
Diegomh7
I never use mysql_result so I would do the same thing this way
$sql2 = " SELECT * FROM products where id = '$id_top' ";
$result2 = mysql_query($sql2);
$row = mysql_fetch_array($result2); // this way because it is only returning a single row
$prod_name = $row['prod_name'];
$price = $row['price'];
$colour = $row['colour'];
$brand = $row['brand'];
$person = $row['person'];
$related = $row['related_code'];
$related2 = $row['related_code2'];
$stock= $row['stock'];
$prod_desc = $row['prod_desc'];
$s1 = $row['s1'];
$s2 = $row['s2'];
$s3 = $row['s3'];
$s4 = $row['s4'];
$s5 = $row['s5'];
$s6 = $row['s6'];
$s7 = $row['s7'];
$s8 = $row['s8'];
$s9 = $row['s9'];
$s10 = $row['s10'];
$s11 = $row['s11'];
$s12 = $row['s12'];
$s13 = $row['s13'];
$s14 = $row['s14'];
$s15 = $row['s15'];
$s16 = $row['s16'];
$s17 = $row['s17'];
$s18 = $row['s18'];
$s19 = $row['s19'];
$s20 = $row['s20'];