Runing a personalizated Query

J

Jorge

Guest
Can you tell me is there is any easy way to create custom querys to run from the menu for example?

I mean making dadabik display the results fo a query i have premade....

thanks
 
D

Debbie S

Guest
Jorge

If you are referring to creating a menu with pre-made searches to display a specific group of records, that is easy to do. Below is an example from one of my installations. This information is in a file I created called "nav.php" which I included in the header.php file.

<?

// get the number of XXX records in the database
$sql = "SELECT COUNT(Area) FROM contact where Area = 1";
// execute the select query
$AFC = execute_db($sql, $conn);
while ($count_row = fetch_row_db($AFC)){
$AFC_records = $count_row[0];
} // end while

$sql1 = "SELECT COUNT(Area) FROM contact where Area = 2";
$EmailDNS = execute_db($sql1, $conn);
while ($count_row = fetch_row_db($EmailDNS)){
$EmailDNS_records = $count_row[0];
}

$sql2 = "SELECT COUNT(Area) FROM contact where Area = 3";
$Netwatch = execute_db($sql2, $conn);
while ($count_row = fetch_row_db($Netwatch)){
$Netwatch_records = $count_row[0];
}

$sql3 = "SELECT COUNT(Area) FROM contact where Area = 4";
$PBX = execute_db($sql3, $conn);
while ($count_row = fetch_row_db($PBX)){
$PBX_records = $count_row[0];
}

$sql4 = "SELECT COUNT(Area) FROM contact where Area = 5";
$Tspt = execute_db($sql4, $conn);
while ($count_row = fetch_row_db($Tspt)){
$Tspt_records = $count_row[0];
}

$sql5 = "SELECT COUNT(Area) FROM contact where Area = 6";
$Switch = execute_db($sql5, $conn);
while ($count_row = fetch_row_db($Switch)){
$Switch_records = $count_row[0];
}

echo "<a href=\"".$dadabik_main_file."?function=search&table_name=".urlencode($table_name)."&where_clause=Area=1&page=0\" class=\"menu\">Acs Fac & CPE  <span class=\"small\">[".$AFC_records."]</span></a>";
echo "<a href=\"".$dadabik_main_file."?function=search&table_name=".urlencode($table_name)."&where_clause=Area=2&page=0\" class=\"menu\">Email/DNS/AAA  <span class=\"small\">[".$EmailDNS_records."]</span></a>";
echo "<a href=\"".$dadabik_main_file."?function=search&table_name=".urlencode($table_name)."&where_clause=Area=3&page=0\" class=\"menu\">Netwatch  <span class=\"small\">[".$Netwatch_records."]</span></a>";
echo "<a href=\"".$dadabik_main_file."?function=search&table_name=".urlencode($table_name)."&where_clause=Area=4&page=0\" class=\"menu\">PBX  <span class=\"small\">[".$PBX_records."]</span></a>";
echo "<a href=\"".$dadabik_main_file."?function=search&table_name=".urlencode($table_name)."&where_clause=Area=5&page=0\" class=\"menu\">Transport  <span class=\"small\">[".$Tspt_records."]</span></a>";
echo "<a href=\"".$dadabik_main_file."?function=search&table_name=".urlencode($table_name)."&where_clause=Area=6&page=0\" class=\"menu\">Switching  <span class=\"small\">[".$Switch_records."]</span></a>"; }
?>

This example also displays the number of records beside the menu link. The classes used are custom classes I created for the menu and do not appear in the default DaDaBIK stylesheets.

This is only part of the entire navigation I built for this particular installation. The whole thing works on the two main tables in the DB and the menu displayed depends on which table the user is viewing at the time -- accomplished with 'if' statements surrounding the php echo lines. If you use the counts on more than one table, you'll have to create additional count sections also.

Hope this makes sense.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
A

Annie

Guest
Debbie can you show me the code of how you added your nav.php into your header.php file...

Thanks,
Annie
 
D

Debbie S

Guest
Annie

You simply need to include it in header.php at the location where you want it to appear:

<? include ("./include/nav.php"); ?>

In my installation, I customized the header/footer with tables for layout -- for the nav.php part, that table opens in the header and then closes in the footer. I've posted a screenshot of what one of my installations looks like on the company intranet that I manage (http://members.shaw.ca/debsweb/dadabik/screenshot.gif). This should give you an idea of the level of complexity that DaDaBIK is capable of.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
J

John Rogers

Guest
Probably what I need is a link that searches all of the records in a particular field that start with the letter A.

table_name =crew & field name is Last_Name therefore if I do a search in the field Last_Name for all records starting with the letter A I get what I want.

Is there a url that will do this? Something like below:-

http://www.whatever/dadabik/index.php?function=search&table_name=crew&field=Last_Name&starts_with=A
 
D

Debbie S

Guest
John

I'll play around with that in my install and let you know if I find a solution.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
D

Debbie S

Guest
John

You could create a drop down search selection box something like this:

<form method="POST" action="<? echo $dadabik_main_file; ?>?table_name=<?php echo urlencode($table_name); ?>&page=0&function=search&execute_search=1" enctype="multipart/form-data">
Select:
<input name="Last_Name_select_type" type="hidden" value="starts_with">
<select name="Last_Name">
<option value=""></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
etc., etc., etc. ...
</select>
<input type="submit" class="submit" style="font-size:11px;" value="Find">
</form>

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
D

Debbie S

Guest
Glad to help!

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
G

Geckox

Guest
Hello Debbie:

In this case, could I change this line in the index page:

"XXX records found"

whit something like this?

"XXX records found on Acs Fac & CPE"
or
"XXX records found on Email/DNS/AAA"
etc
depending of the query
who?

Thankyou and perdon for my english. I´m spanish.
 
D

Debbie S

Guest
Geckox

You sure can ... in index.php, look for the following line (on or about line 457):

txt_out("<br>".$results_number." ".$normal_messages_ar["records_found"], "n_results_found");

Change that line to this:

if ($where_clause == "") {
txt_out($normal_messages_ar["records_found"].$results_number, "n_results_found");

... and then add as many of these lines as you have custom queries set (change the bold parts to match that of your database):

if ($where_clause == "Area=6") {
txt_out("XXX Records:".$results_number, "n_results_found");
}

That will produce 'XXX Records: 111'. To have it display a different way, just move the pieces around to suit:

if ($where_clause == "Area=6") {
txt_out($results_number."XXX Records", "n_results_found");
}

would produce '111 xxx Records' and so on.

Hope this helps!Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
G

Geckox

Guest
Hello Debbie, thanks for your help:

Its works well but only if I not add the line

if ($where_clause == "") {
txt_out($normal_messages_ar["records_found"].$results_number, "n_results_found");

and only add the lines as I have custom queries set:

if ($where_clause == "PA>0") {
txt_out("XXX Records:".$results_number, "n_results_found");
}

My $where_clause 's are
PA>0
PB>0
PG>0
differents fields

is that the error?

thanks very much

Geckox
 
G

Geckox

Guest
Pardon, I forgot this question:

And is possible if I click on Search button of one of this personalizated Querys, to do a Search in this querys?

Thankyou
 
D

Debbie S

Guest
Geckox

To answer the first question, I'd have to see your DaDaBIK installation in order to give you more help on this since I have no idea what output you are seeing. Do you have it placed in a location where I can view it? If you do not want to publicize it's location, just send me a private email with the link.

Second question -- If you are asking if you can use the search function of DaDaBIK to search within one of your custom query links, no. The DaDaBIK search function will search on the whole database.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
G

Geckox

Guest
Hello Debbie:

By the moment I have the installation in my localhost. When I publish the database and the installation I say you.

Thanks for your help.
 
C

Chikka

Guest
Hi Debbie,
I want to do something like this but I'm a newbie with PHP, I was wondering if you can give me the code for similar to below? My table is "events_db" the field name is "Event_PresaleStart". The field is a "DATETIME" field and the search options will be to display "Events today", "Events tomorrow" and "Events in 7 days".

Someone gave me this PHP code, but not sure how to implement it...

code:
<select name="whatrange">
<option value="0">Today</option>
<option value="1">Yesterday</option>
<option value="2">7 Days Ago</option>
<option value="3">1 Month Ago</option>
</select>



//time is field in db where you are adding time each entry was added using time() function.


if ($whatrange==0)
{
$from=time()%86400;
}
elseif ($whatrange==1)
{
$from=time()-(time()%86400)-86400; //current time minus time till midnight last night minus one day
}
elseif ($whatrange==2)
{
$from=time()-(time()%86400)-(86400*7);
}
elseif ($whatrange==3)
{
$from=time()-(time()%86400)-(86400*30)
}


SELECT * FROM tableName WHERE time>$from

output data

Thanks in advance, you have been very helpful.

Chikka


Debbie S Wrote:
Author: Debbie S (---.wp.shawcable.net)
Date: 12-06-04 05:37

John

You could create a drop down search selection box something like this:

<form method="POST" action="<? echo $dadabik_main_file; ?>?table_name=<?php echo urlencode($table_name); ?>&page=0&function=search&execute_search=1" enctype="multipart/form-data">
Select:
<input name="Last_Name_select_type" type="hidden" value="starts_with">
<select name="Last_Name">
<option value=""></option>
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
etc., etc., etc. ...
</select>
<input type="submit" class="submit" style="font-size:11px;" value="Find">
</form>

Debbie
(Latest version of DaDaBIK when this message was posted: 3.1 Beta)
 
D

Debbie S

Guest
Chikka

I'll need some time on this one... I'll get back to you in a few days.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2)
 
D

Debbie S

Guest
Chikka

I've not had any luck getting this to work. Perhaps someone on the board has more experience with date/time functions and a fresh set of eyes that may be able to get this working.

The other option would be to have your presale date field (or the one you wanted to base the custom query on) added as a quick date search at the top of your install. Users could select the date they wanted to view records for.

Sorry I can't be more help on this.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2)
 
C

chikka

Guest
Thanks for trying Debbie.. hopefully someone will get this one going.

Pardon my ignorance with scripting, but I'm not sure I understood the option you mentioned regarding adding the option of quick date search.

Thanks again. You have been really helpful to me.

ChikkaDebbie S wrote:

> Chikka
>
> I've not had any luck getting this to work. Perhaps someone
> on the board has more experience with date/time functions and a
> fresh set of eyes that may be able to get this working.
>
> The other option would be to have your presale date field (or
> the one you wanted to base the custom query on) added as a
> quick date search at the top of your install. Users could
> select the date they wanted to view records for.
>
> Sorry I can't be more help on this.
>
> Debbie
> (Latest version of DaDaBIK when this message was posted:
> 3.2)
 
D

Debbie S

Guest
Chikka

I'll look into making a quick date select form and get back to you.

Debbie
(Latest version of DaDaBIK when this message was posted: 3.2)
 
Top