Jump to content

Query and Function Help!


nirvana

Recommended Posts

Hi All,

Here is the script I wrote and having problem with it. I am new in this area and would be appreciated for any help.
I use the same query in displaying 3 results: minimum, maximum and list all the contents of the query array.
Although I think it should work, it didn't. It displays minimum and maximum but it doesn't display all the contents.

I tried debugging with var_dump($result) as shown or echo number of rows and columns - it returned resource 17 mysql result and 50 rows and 4 columns. However, it didn't display any content data.
Is there something wrong?
I tried changing the variable name $row which is the same in both cases as I thought it would be the reason but still didn't work.

function table_create()
{
// Getting information from the form
//Assigning Variables - Device# and test
$device = $_POST ['device'];
if ($device == "0"){
    die ("Please Select Device Number!!");
}
$test = $_POST['test'];
  if ($test == ""){
    die ("Please Select Test Parameter!!");
}
  $port = $_POST['port'];
  $attn = $_POST['attn'];
  $date = $_POST['dates'];
  if ($date == ""){die ("Please Select Test Group# !!!");}
  $ebw = $_POST ['ebw'];
  $temp = $_POST['temp'];
 
$temperature = @mysql_query("SELECT temp FROM tested_device join dwp_data where
device_ID = '$device' AND Temperature BETWEEN $temp");
$t = mysql_fetch_row($temperature);

switch ($test) {
case "Min BW":

if ($attn == "All"){
$result = @mysql_query("SELECT measured_paras_1 AS Channel, attn AS Attenuation_dB,
measured_paras_2 AS Min_Bandwidth_GHz FROM dwp_data join dwp_data_summary join tested_device
where dwp_data.device_num = tested_device.device_num AND dwp_data.test_number = dwp_data_summary.test_number
AND parameter = 'PFL($ebw)' AND port = '$port' AND TestGroup = '$date' AND device_ID = '$device' AND temp BETWEEN $temp
ORDER BY measured_paras_1 ASC, attn ASC");
while ($row = mysql_fetch_array($result))
{ $bw[] = $row[2];}
$min = min($bw);
$max = max($bw);

}
else {
$result = @mysql_query("SELECT measured_paras_1 AS Channel, attn AS Attenuation_dB,
measured_paras_2 AS Min_Bandwidth_GHz FROM dwp_data join dwp_data_summary join tested_device
where dwp_data.device_num = tested_device.device_num AND dwp_data.test_number = dwp_data_summary.test_number
AND parameter = 'PFL($ebw)' AND port = '$port' AND attn = '$attn' AND TestGroup = '$date'
AND device_ID = '$device' AND temp BETWEEN $temp");
while ($row = mysql_fetch_array($result))
{ $bw[] = $row[2];}
$min = min($bw);
$max = max($bw);
}
echo "<b><center> Minimum Bandwidth at Port $port = $min GHz<b><br>\n";
echo "<b><center> Maximum Bandwidth at Port $port = $max GHz<b><br>\n";
echo " Port $port - Minimum BandWidth by Channel @ $ebw, $t[0] °C<b><br>\n";
break;
}
if (!$result) {
die('<p>Error performing query:' . mysql_error() . '</p>');
}
//echo " PORT $port <br>";
//echo "$attn dB <br>";
//echo "$temp Degree <br>";
//echo "Channel- $ch<br>";
//var_dump($result);
//Display # of rows, columns & Create Table
  $numrows = mysql_num_rows($result);
  $fnum = mysql_num_fields($result);
//  echo "$numrows Rows <br>\n";
//  echo "$fnum Columns <br><br>\n";
 
  echo "<table border width='75%' align= 'center' border='0' cellpadding= '0'>";
  // echo "<tr>";
  for ($x = 0; $x < $fnum; $x++) {
        echo "<td><b><center>";
          echo  (mysql_field_name($result, $x));
              echo "</center></b></td>";
}
     
//  echo "</tr>";
  for ($i = 0; $i < $numrows; $i++) {
    $row = mysql_fetch_object($result);
      echo "<tr align='center'>";
        for ($x = 0; $x < $fnum; $x++) {
    $fieldname = mysql_field_name($result, $x);
        echo "<td>";
        echo $row->$fieldname;
        echo "</td>";
}
        echo"</tr>";
}
    echo "</table>";

return 0;
}

table_create ($result);


thanks in advance,
nirvana
Link to comment
Share on other sites

Glancing over your queries i noticed the BETWEEN keyword. Normally it's BETWEEN value1 AND value2. You don't specify the 2nd value.

Also while debugging it's useful to remove the silencing operator @ from the mysql_query call to get the error message.

If it still doens't work post the error message here.
Link to comment
Share on other sites

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.