Author Topic: Extract info from DB  (Read 3835 times)

0 Members and 1 Guest are viewing this topic.

Offline MrAndrew

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
    • Aviation PhotoBase
Extract info from DB
« 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!

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Extract info from DB
« Reply #1 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...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline MrAndrew

  • Sr. Member
  • ****
  • Posts: 302
    • View Profile
    • Aviation PhotoBase
Re: Extract info from DB
« Reply #2 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?
« Last Edit: September 04, 2010, 10:37:25 PM by MrAndrew »

 

Post your comments here