This topic is locked

Submitted field used in WHERE clause?

12/11/2006 2:51:06 PM
PHPRunner General questions
L
larsonsc author

Is there a vay to edit the *_variables.php page to be able to use a submitted field value in the SQL string as a comparison value?
For example (and this doesn't work...I tried it)

WHERE "$values['Intake_ID']" = `inventory`.`Intake_ID`";


I figure I have to tweak something to pass the $values array into the string, but I'm not sure what. Thanks for the help.

G
GeddyLee 12/11/2006

Where is the WHERE clause? i.e. in a lookup Wizard, the SQL edit page, an event?

L
larsonsc author 12/11/2006

Where is the WHERE clause? i.e. in a lookup Wizard, the SQL edit page, an event?


It is in the MySQL query which is stored in the *_variables.php file for the view I created.

J
Jane 12/12/2006

Shawn,
I'm not sure that I understand you correctly.
Please give me more detailed description of what you need to achieve and I'll try to help you.

L
larsonsc author 12/12/2006

I have a "report" that I need to run. I created a View that take a user to a search page where the user inserts a single value. The view is based on an SQL query that goes to each table that has information I need and gets the information, however, I am getting a bit of a Cartesian join effect the way the query is coded currently. I should get a single copy of the information assembled on the screen, but I actually get 15 complete copies of the record. What I want to do is take the value that is submitted by the user, and use it as part of my query so that I can eliminate the cartesian results and get a single record report.
So, to summarize the process flow, the user clicks the link to the report and is brought to the search page. They choose "equals" as the comaprison operator and then enter an ID#. I want to use the $values['Intake_ID'] value that is submitted by the user in my query as shown in my original post since that would be a unique value to use as a comparison rather than a value from another column which is what I was doing before and it cause the bad join results. Below is the entire query since maybe that will help more than just the single line I included previously.

select `inventory`.`Intake_ID`,

`Cat_Name` AS "Cat's Name",

concat((YEAR(curdate())-YEAR(Date_Of_Birth)), ' Year(s),', (MONTH(curdate())-MONTH(Date_Of_Birth)), ' Month(s)') AS "Estimated Current Age",

concat(`Breed`, ' ', `Color`, ' ', `Markings`) AS "Breed/Color/Markings",

`Intake_Source` AS "Source of Intake",

`Date_Of_Intake` AS "Date of Intake",

`Altered` AS "Spayed or Neutered",

concat(`Adopter_First_Name`, ' ', `Adopter_Last_Name`) AS "Adopted To",

concat(`Adopter_Address`, ' ', `Adopter_Address_2`) AS "Address",

`Adopter_City` AS "City",

`Adopter_State` AS "State",

`Adopter_Zip_Code` AS "Zip Code",

`Adopter_Home_Phone` AS "Home Phone",

`Adopter_Alt_Phone` AS "Alternate Phone",

`Adopter_Email` AS "Email Address",

`Adoption_Date` AS "Date of Adoption",

`Adoption_Location` AS "Adoption Location",

`Adoption_Fee` AS "Adoption Fee",

`Adoption_Payment_Method` AS "Paid By",

`inventory`.`Foster_Name` AS "Fostered By",

`foster_homes`.`Contact_Info` AS "You Can Contact The Foster At"

From `adoption_records`JOIN `inventory` ON `adoption_records`.`Intake_ID` = `inventory`.`Intake_ID`

JOIN `foster_homes` ON `inventory`.`Foster_Name` = `foster_homes`.`Foster_Name`

WHERE "$values['Intake_ID']" = `inventory`.`Intake_ID`
Alexey admin 12/12/2006

Shawn,
just use the Advanced search page.
Enter your query without WHERE clause on the Edit SQL query tab.

Build the pages and let the user enter the desired ID in Intake_ID field on Advanced search page.

L
larsonsc author 12/12/2006

Alexey,
That worked GREAT! I have one other question related to this report that I would like to ask. I would like to be able to add in anoter set of data to this but have it all still come up in a single record. The issue is that the other data usually has more than one result and therefore causes the other data to repeat.
What I need to do is get the medical records for the cat that are stored (usually several entries) and have them list at the bottom of this report, but not repeat any of the adoption, adopter, or cat details.
I.E. The result would look like this:
Cat details

Adopter details

Adoption details

All medical records
Is there any way to get that to format properly or is it the nature of the DB extraction to pair up all the data into individual results?

J
Jane 12/13/2006

Shawn,
you can do it editing generated ..._print.php file manually.

  1. find this line:
    while($data && $recno<=$PageSize)

and add

$newvalue1="";



just before it.

2. then find following code:

// FieldName -

$value="";

$value = ProcessLargeText(GetData($data,"FieldName", ""),"field=FieldName".$keylink,MODE_PRINT);

$row[$col."FieldName_value"]=$value;



and replace it with this one:

// FieldName -

$value="";

$value = ProcessLargeText(GetData($data,"FieldName", ""),"field=FieldName".$keylink,MODE_PRINT);

if ($value!=$newvalue)

$row[$col."FieldName_value"]=$value;

$newvalue=$value;



FieldName is your actual field name.

Make the same for the all repeated fields.

L
larsonsc author 12/13/2006

Jane,
Thanks for the reply. I'll be trying this solution very soon and see if I can make it work. I think i figured out what I need to edit when I compared my *_print.php page to your post. I'll let you know how it turns out! Thanks so much for the help!
--Shawn

L
larsonsc author 12/13/2006

Jane I tried the method you suggested and received the following error on my server:
Fatal error: Maximum execution time of 30 seconds exceeded in /home/jpurnell/htdocs/kcsiameserescue/admin/Post_Adoption_Paperwork_list.php on line 652
I have a couple of questions though:
You state that I should add $newvalue1=""; to the end of the line you asked me to find. Now my line of code looks like this:

while($data && $recno<=$PageSize) $newvalue1="";


Will the ; at the end of that line cause the while statement to fail to execute?
Also, in the other lines you have me add, you state to add in $newvalue=$value. Should that be $newvalue1 as was created up above?
Thanks.

L
larsonsc author 12/13/2006

Well, I figured out where to add the newvalue1=""; statement and added in the code you suggested for the multiple records, but it does the same thing it did before. It still returns each individual medical with all the other data that I do not want to repeat. Is there any way I could send you the _list.php and _print.php files and have you examine them to see if I have misapplied your suggested configuration? Or perhaps I could create a login for you on my server so that you could see what is happening and maybe get a better idea of my desired results? Please let me know. Thank you.

L
larsonsc author 12/13/2006

Everyone, the more I think about this "problem", the less I think it is as much of a neccessity as I originally thought. Therefore, I would like to take this opportunity to thank everyone for their effort on this, but I am going to let this requirement slide and just inform the users that they will have to run two searches/reports to get the data rather than just the one I had hoped to be able to code for them.
After updating both the list.php and print.php pages for the respective report, I ended up completely chinking the app and generated a nice big smarty error. So, since no one who uses this database except me cared if the report was one report or two, I'm going to back off on trying to make this happen and move on with more report development activites.
Again, thanks to everyone who assisted me in trying to make this work.
--Shawn

J
Jane 12/14/2006

Shawn,
please send your ..._print.php file to [email=support@xlinesoft.com]support@xlinesoft.com[/email] for investigation.