This topic is locked

Problem in where clause

7/12/2006 3:12:47 AM
PHPRunner General questions
F
frank author

Hello,

I have a stupid question as my syntax in the where clause is wrong and I could find the fault.
This script should show me the number of records in this list view.
function ListOnLoad($strSQL)

{
//** Custom code ****

// put your custom code here
global $conn;

global $masterkey;
$SQL = "select count(anfragen.anfragenummer) from anfragen where anfragen.seriennummer=$masterkey";

$FH = mysql_query($SQL,$conn);

$data=mysql_result($FH,0);

// $_SESSION["number"]=$data["ID"]+1;

echo $data;

echo $masterkey;
}
Any help will be fine.
Thanks, Frank

J
Jane 7/12/2006

Hrank,
see my changes in Bold:

function ListOnLoad($strSQL)

{
//** Custom code ****

// put your custom code here
global $conn;

global $masterkey;
$SQL = "select count(anfragen.anfragenummer) from anfragen where anfragen.seriennummer=".$masterkey;

$FH = mysql_query($SQL,$conn);

$data=mysql_result($FH,0);

// $_SESSION["number"]=$data["ID"]+1;

echo $data;

echo $masterkey;
}

F
frank author 7/12/2006

Thank you for the fast reply.
But this did not work. I explain the situation better. I have a table called machines with serialnumber field. This ist the master detail field for the table "anfragen".

So on load of the table "anfragen" I can see all records related to this machine serialnumber.
The $masterkey contains already the correct value of the serial number. The echo $masterkey command show the correct value.
Without the where clause the SQL query works and show in $data the value of all counted records in the table "anfragen".
I thought that I then must just add the where clause to the SQL statement and it will calculate only the related records but something is wrong in this statement the error shown is
Error type 2

Error description mysql_result(): supplied argument is not a valid MySQL result resource

URL localhost/PHPRunner/anfragen_pro_maschine_list.php?masterkey=43+038

Error file C:\Programme\PHPRunner\Output\include\anfragen_pro_maschine_events.php

Error line 14

SQL query select `Bearbeiter1`, `Aufgenommen_am`, `Aufgenommen_um`, `Stichwort2`, `Stichwort3`, `Beschreibung`, `Techniker`, `Fertig`, `NUMMER`, `Priority`, `AnfrageNummer`, `Seriennummer`, `Kontaktperson`, `ID` From `anfragen` where `anfragen`.`Seriennummer`='43 038'
Best regards
Frank

J
Jane 7/12/2006

Frank,
try to use following code:

function ListOnLoad($strSQL)

{
global $conn;

global $strTableName;
$SQL = "select count(anfragen.anfragenummer) from anfragen where anfragen.seriennummer='".$_SESSION[$strTableName."_masterkey"]."'";

$FH = mysql_query($SQL,$conn);

$data=mysql_result($FH,0);

// $_SESSION["number"]=$data["ID"]+1;

echo $data;

echo $masterkey;
}