4images Forum & Community

General / Allgemeines => Programming => Topic started by: MrAndrew on September 04, 2010, 04:15:41 PM

Title: Extract info from DB
Post by: MrAndrew on September 04, 2010, 04:15:41 PM
Hi to all.

I need some help. I want to extract all info of photo by one field of database. For this i need to extract some fields from DB. I`ve written a code for extract this but cannot complete this, becouse i`m not programmist. Please help me anyone. My exemple:

It must work next: when i changed image registration from dropdown menu, other information need to be extract from database, and show in the inputs. This code extract information randomly, and dropdown not extract values of image_reg. What need to be changed and what is wrong?

Code: [Select]
$sql = "SELECT * FROM 5images_images WHERE image_reg=\"".$image_reg."\"";
$result = mysql_query($sql);

  $image_autofill .= "<select name=\"image_reg\">";
  $image_autofill .= "<option value=\"0\">-- Chose Reg --</option>";
    $image_autofill .= "<option value=\"$row[image_reg]\" name=\"image_registrations\">$row[image_reg]</option>";
      $image_autofill .= "</select>";
   
while ($row = mysql_fetch_assoc($result)) {
      echo "<input type=\"text\" name=\"image_airline\" value=\"$row[image_airline]\" class=\"input\" size=\"30\" class=\"input\">";     

}
   

$site_template->register_vars("image_autofill", $image_autofill);
unset($image_autofill);

Many thanks!
Title: Re: Extract info from DB
Post by: V@no on September 04, 2010, 04:45:38 PM
I know it won't be as you expected (because your code is not correct and I don't understand what exactly it supposed to do), but this should get you started:
$sql = "SELECT *
        FROM " . IMAGES_TABLE . "
        WHERE image_reg='".$image_reg."'";
$result = $site_db->query($sql);

$image_autofill .= "<select name=\"image_reg\">";
$image_autofill .= "<option value=\"0\">-- Chose Reg --</option>";
$image_autofill .= "<option value=\"$image_reg\" name=\"image_registrations\">$image_reg</option>";
$image_autofill .= "</select>";
   
while ($row = $site_db->fetch_array($result))
{
 $image_autofill .= "<input type=\"text\" name=\"image_airline\" value=\"" . $row['image_airline'] . "\" class=\"input\" size=\"30\" class=\"input\">";     

}
$site_template->register_vars("image_autofill", $image_autofill);
unset($image_autofill);


you cannot use echo in 4images unless it's in ACP, but if it's in ACP, then you cannot use $site_templates because ACP doesn't support templates...
Title: Re: Extract info from DB
Post by: MrAndrew on September 04, 2010, 04:59:49 PM
Can i use image_reg from table, for show other values??? I.e. When will change value of "image_reg" from dropdown, it will show me value from image_airline?

V@no, i`ve extract info from image_reg with this code:

//-----------------------------------------------------
// --- Choose autofill - Start --------------------------
//-----------------------------------------------------

$sql = "SELECT image_reg, image_airline
        FROM ". IMAGES_TABLE ."";
$result = mysql_query($sql);

  $image_autofill .= "<select name=\"image_reg\">";
  $image_autofill .= "<option value=\"0\">-- Choose Reg --</option>";
while($row = mysql_fetch_array($result)){
  $image_autofill .= "<option value=\"$row[image_reg]\" name=\"image_autofill\">$row[image_reg]</option>";
}
  $image_autofill .= "</select>";

$site_template->register_vars("image_autofill", $image_autofill);
unset($image_autofill);
//-----------------------------------------------------
// --- Choose autofill - End ----------------------------
//-----------------------------------------------------

Can i show image_airline value, if will change one of image_reg?