Jump to content

[SOLVED] How to select a certain amount of fields?


Recommended Posts

Hello, Is there a way to echo 30 fields without telling the php app each field name?

 

my code looks like this:

 

$category=TEM;

$query="SELECT * FROM `Hitachi Consumables` WHERE Instrument='$instrument'";
$result=mysql_query($query,$sql);
$num=mysql_numrows($result);

mysql_close();

echo "$instrument <br><br>";

$i=0;
while ($i < $num) {

$filament=mysql_result($result,$i,"Filament");
$filCart=mysql_result($result,$i,"Filament Cartridge");
$l6=mysql_result($result,$i,"LAB-6 or Consumable Emitter");
$updatedBy=mysql_result($result,$i,"Updated by");
$fixedCondenserAperture=mysql_result($result,$i,"Fixed Condenser Aperture");
$movableAperture=mysql_result($result,$i,"EDX Objective Movable Aperture");
$conMovableAperature=mysql_result($result,$i,"Condenser Movable Aperture");
$objMovableAperature=mysql_result($result,$i,"Objective Movable Aperture");
$beamMA=mysql_result($result,$i,"Beam Monitor Aperture");
$DBAOBJ=mysql_result($result,$i,"DPA or OBJ Fixed Aperture");
$SEMA=mysql_result($result,$i,"Selected Area Movable Aperture");
$viewScreen=mysql_result($result,$i,"Viewing Screen");
$sViewScreen=mysql_result($result,$i,"Spot Viewing Screen");
$PMT=mysql_result($result,$i,"PMT");
$STEMs=mysql_result($result,$i,"STEM Scintillator");
$BSEDetector=mysql_result($result,$i,"BSE Detector");
$trackBall=mysql_result($result,$i,"Track Ball");
$OVS=mysql_result($result,$i,"Outer Viewing Screen");
$wehneltAssembly=mysql_result($result,$i,"Wehnelt Assembly");
$wehneltCS=mysql_result($result,$i,"Whenelt Contact Spring");
$wehneltfC=mysql_result($result,$i,"Wehnelt for Cartridge");

echo "<b>Filament:</b> $filament<br>
<b>Filament Cartridge:</b> $filCart<br>
<b>LAB-6 or Consumable Emitter:</b> $l6<br>
<b>Fixed Condenser Aperture:</b> $fixedCondenserAperture<br>
<b>EDX Objective Movable Aperture:</b> $movableAperture<br>
<b>Condenser Movable Aperture:</b> $conMovableAperature<br>
<b>Objective Movable Aperture:</b> $objMovableAperature<br>
<b>Beam Monitor Aperture:</b> $beamMA<br>
<b>DPA or OBJ Fixed Aperture:</b> $DBAOBJ<br>
<b>Selected Area Movable Aperture:</b> $SEMA<br>
<b>Viewing Screen:</b> $viewScreen<br>
<b>Spot Viewing Screen:</b> $sViewScreen<br>
<b>PMT:</b> $PMT<br>
<b>STEM Scintillator:</b> $STEMs<br>
<b>BSE Detector:</b> $BSEDetector<br>
<b>Track Ball:</b> $trackBall<br>
<b>Outer Viewing Screen:</b> $OVS<br>
<b>Wehnelt Assembly:</b> $wehneltAssembly<br>
<b>Whenelt Contact Spring:</b> $wehneltCS<br>
<b>Wehnelt for Cartridge:</b> $wehneltfC<br>";


$i++;
}

 

I would like to somehow shrink all the code down after "while ($i < $num) {".

Use mysql_fetch_assoc in stead of mysql_result eg:

$category = TEM;

$query = "SELECT * FROM `Hitachi Consumables` WHERE Instrument='$instrument'";
$result = mysql_query($query,$sql);

mysql_close();

echo "<p>$instrument</p>\n";

while($row = mysql_fetch_assoc($result))
{
    foreach($row as $field => $value)
    {
        echo '<b>' . $field . ':</b> ' . $value . "<br />\n";
    }
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.