Re: [PHP] one click - two actions?

2007-01-21 Thread pub

On Nov 13, 2006, at 9:44 PM, Paul Novitski wrote:

Paul,

Thank you again for your amazingly generous email.

I am working on my query as you suggested. I have a joint query that  
seems to work except that I get the name of the company repeated for  
each job. Could you please help me figure out how to make it echo the  
company once and list all the jobs next to it on the same line and  
start a new line with the next company like you suggested bellow?


 Here is the code I have now:

$query = SELECT client.companyName, job.jobType, job.pix, job.info,  
job.url

FROM client, job
WHERE client.companyId=job.companyId
AND client.view='yes'
order by client.companyName;


$result = mysql_query($query)
or die (Couldn't execute query);

while   ($aaa = mysql_fetch_array($result,MYSQL_ASSOC))
{   
  		echo span class='navCompany'{$aaa['companyName']}/spanspan  
class='navArrow'   /spanspan class='navText'a  
href='single_page_t10.php?art=.$aaa['pix'].'{$aaa['jobType']}/a/ 
spanbr\n;

}   





I think what you're looking for is JOIN syntax for your queries:
http://dev.mysql.com/doc/refman/4.1/en/join.html

For example:

SELECT * FROM client, job
WHERE client.companyId=job.companyId
AND (client.status='active' or client.status='old')
order by client.companyName;

(Note that when you extract fields from more than one table like  
this, you identify the table that each field belongs to, e.g.  
client.companyId.)


Then you can extract the desired fields from both tables in the  
same loop because they've been captured together.  Your current  
logic executes a job query for every row of client, which is  
extremely inefficient.


The dataset produced by the join query is going to look something  
like this:


client. job.
companyId   companyId
1   2
1   3
1   9
2   4
2   5
...

In other words, there will be one row for each job record, with the  
(parent) client fields duplicated each row.



You can further improve the efficiency of your query by naming only  
the fields you need, instead of using * to extract all fields:


SELECT client.companyName, job.pix, job.jobType, job.url,  
job.web

FROM client, job
WHERE client.companyId=job.companyId
AND (client.status='active' or client.status='old')
order by client.companyName;

Once you execute the join query, your PHP loop can cycle in a  
similar way, echoing a company name and then listing all the job  
types until a new company name occurs, etc.



You've got other problems, however.  If you look at your HTML  
source, you'll see markup like this:


span class='navCompany'Builtworks/spanspan class='navArrow'   
 /span
span class='navText'a href='single_page.php? 
art=btw_logo.jpg'logo/a/span

span class='navText'a href='single_page.php?art='/a/span
span class='navText'a href='single_page.php?art='/a/span
span class='navText'a href='single_page.php?art='/a/span
span class='navText'a href='single_page.php?art='/a/span
brspan class='navCompany'Citizens Bank / eProperty/spanspan  
class='navArrow'   /span
span class='navText'a href='single_page.php? 
art=ctz_web1.jpg'website/a/span


All those empty hyperlinks aren't doing anything but making your  
download heavier than it has to be.  I think you need to test your  
'jobType' fields and output only those that aren't blank.





Good luck,
Paul



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2007-01-21 Thread Paul Novitski

At 1/21/2007 01:54 AM, pub wrote:

I am working on my query as you suggested. I have a joint query that
seems to work except that I get the name of the company repeated for
each job. Could you please help me figure out how to make it echo the
company once and list all the jobs next to it on the same line and
start a new line with the next company like you suggested bellow?



You want to output the company name only when it changes.  I usually 
do this by keeping a variable equal to the previous value in the loop 
and compare it each time with the current value:


PreviousCompany = '';

while (fetching data records)
{
if (PreviousCompany != CurrentCompany)
{
output CurrentCompany;
PreviousCompany = CurrentCompany;
}

output Job;
}


One markup structure you might consider for this application is the 
definition list:


dl
dtCompany/dt
ddjob 1/dd
ddjob 2/dd
ddjob 3/dd
ddjob 4/dd

dtCompany/dt
ddjob 1/dd
ddjob 2/dd
ddjob 3/dd
ddjob 4/dd
...
/dl

Regards,

Paul
__

Juniper Webcraft Ltd.
http://juniperwebcraft.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-14 Thread tedd

At 12:31 PM -0800 11/13/06, Mel wrote:

I really don't know?

My site is all php and ready to go live except for this little problem.

I would really appreciate some help.

On Nov 13, 2006, at 4:12 AM, John Meyer wrote:


Not to be rude or anything, but if you want to do two things with one
click, wouldn't the javascript list be the place you would want to go?



Mel:

I think I know what you want, which is when someone clicks 
Bullworks  Logo (for example) that not only does the Logo appear 
on the left, but you want text describing the logo to appear on the 
right, correct?


This can be done via an ajax and php combination. You may want to 
consider that. Plus, there would be no activity in the url portion of 
the user browser -- IMO, it looks cooler.


tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-14 Thread Mel

YES YES! that is exactly what I want.
But I don't know how to do what you are suggesting!

On Nov 14, 2006, at 8:59 AM, tedd wrote:


At 12:31 PM -0800 11/13/06, Mel wrote:

I really don't know?

My site is all php and ready to go live except for this little  
problem.


I would really appreciate some help.

On Nov 13, 2006, at 4:12 AM, John Meyer wrote:

Not to be rude or anything, but if you want to do two things with  
one
click, wouldn't the javascript list be the place you would want  
to go?



Mel:

I think I know what you want, which is when someone clicks  
Bullworks  Logo (for example) that not only does the Logo appear  
on the left, but you want text describing the logo to appear on the  
right, correct?


This can be done via an ajax and php combination. You may want to  
consider that. Plus, there would be no activity in the url portion  
of the user browser -- IMO, it looks cooler.


tedd
--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-14 Thread Jon Anderson

Mel wrote:

YES YES! that is exactly what I want.
But I don't know how to do what you are suggesting! 
You'll have to read some documentation about AJAX if that's what you 
want, but thankfully there are some easy AJAX toolkits out there. Of the 
ones I've tried, I find xajax (xajax.sf.net) to be the simplest. For 
example, the following is a rough (completely untested) example that 
illustrates my point:


In your HTML, you could have: div id=logoDiv/div and div 
id=textDiv/div somewhere...


Then the xajax PHP code:
function twoActions() {
   $xR = new xajaxResponse();
   $xR-addAssign('logoDiv','innerHTML','img src=images/logo.jpg /');
   $xR-addAssign('textDiv','innerHTML','Here is an explanation of the 
logo!');

   return($xR-getXML());
}
$xajaxInstance-registerFunction('twoActions');

Then the link:

a href=# onclick=xajax_twoActions();return(false);Logo/a

jon

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-14 Thread tedd

At 12:30 PM -0800 11/14/06, Mel wrote:

YES YES! that is exactly what I want.


I'll send it to you off-list.

But, to see it work, try this:

http://xn--ovg.com/ajax_w_picts1

tedd

--
---
http://sperling.com  http://ancientstones.com  http://earthstones.com

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-13 Thread John Meyer
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Not to be rude or anything, but if you want to do two things with one
click, wouldn't the javascript list be the place you would want to go?
Mel wrote:
 Could someone please help me figure out how to show some description
 (where applicable) at the same time as I show an image, when I click on
 a link, without repeating the entire query?
 The image and the description are both in the same table in my database.
 
 I now show the image when I click on the link which is good, but the
 description stays on at all times instead of appearing only when active.
 
 http://www.squareinch.net/single_page.php
 
 This is the code I have for the image area:
 /* query 1 from client */
   $query = SELECT * FROM client
 where status='active' or status='old'
 order by companyName;

   $result = mysql_query($query)
 or die (Couldn't execute query);

   while ($aaa = mysql_fetch_array($result,MYSQL_ASSOC))
   { 
   echo span class='navCompany'{$aaa['companyName']}/spanspan
 class='navArrow'   /span\n;
 
 /* query 2 from job */
 $query = SELECT * FROM job
 WHERE companyId='{$aaa['companyId']}';
   $result2 = mysql_query($query)
 or die (Couldn't execute query2);
 
 foreach($aaa as $jobType)
 {
 $bbb = mysql_fetch_array($result2,MYSQL_ASSOC);
 echo span class='navText'a
 href='single_page.php?art=.$bbb['pix'].'{$bbb['jobType']}/a/span\n;
 }   
 echo br;
 }   
 ?
 
 /div   
 
 
 div class=navbox3?php $image = $_GET['art']; ?
 img src=images/?php print ($image) ?  alt=Portfolio
 Item border=0 width=285 height=285/div
 
 
 This is the code I have for the description area:
 
 /* query 1 from client */
 $query = SELECT * FROM client
 where status='active' or status='old'
 order by companyName;

   $result = mysql_query($query)
 or die (Couldn't execute query);
 
 while ($row = mysql_fetch_array($result,MYSQL_ASSOC))
 { 

 /* query 2 from job */
 $query = SELECT * FROM job
 WHERE companyId='{$row['companyId']}';
   $result2 = mysql_query($query)
 or die (Couldn't execute query2);
 $url = mysql_query($result2);

 foreach($row as $url)
 {
 $row = mysql_fetch_array($result2,MYSQL_ASSOC);
 if (url={$row['url']})   
 echo span class='navText'a
 href='{$row['url']}'{$row['web']}/a/span;   
 }
 
 echo br;   
 }
 ?
 
 
 

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.2 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org

iD8DBQFFWGE2bHd4gglFmoARAnNWAJ0fs+NHm5MbNwDpm3E7Flu3giU+LQCgkF7O
uCu6zhUFfviNC+aaxpNy+Vg=
=NQVC
-END PGP SIGNATURE-

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-13 Thread Mel

I really don't know?

My site is all php and ready to go live except for this little problem.

I would really appreciate some help.

On Nov 13, 2006, at 4:12 AM, John Meyer wrote:


Not to be rude or anything, but if you want to do two things with one
click, wouldn't the javascript list be the place you would want to go?




RE: [PHP] one click - two actions?

2006-11-13 Thread Warren Vail

Mel, that may have been a disguised hint.  Your answer lies in
javascript.  The first php page needs to contain javascript to open a
second page with the URL to the second php script when the first page
loads.

Keep a couple of things in mind, popup blockers will reek havoc if you
can't get visitors to your site to stop blocking popups and if you
expect both URLs to receive form contents, you will have to make
arrangements for that in the javascript in your first page, since it
will need to pass the data again.

Check out http://www.hotscripts.com for some links to sites with the
necessary javascript.

Hope this helps,

Warren Vail

-Original Message-
From: Mel [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 13, 2006 12:32 PM
To: John Meyer
Cc: PHP General List
Subject: Re: [PHP] one click - two actions?

I really don't know?

My site is all php and ready to go live except for this little problem.

I would really appreciate some help.

On Nov 13, 2006, at 4:12 AM, John Meyer wrote:

 Not to be rude or anything, but if you want to do two things with one
 click, wouldn't the javascript list be the place you would want to go?

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-13 Thread Mel
Thank you for your reply. I think my question is really much more  
simple than what you are suggesting.

If you have a quick look at
http://www.squareinch.net/single_page.php?art=crp_logo.jpg
you will see what I mean.
I have a single page and both results load in the same page.

When I click on a link the picture loads on the left side and the  
info should load on the right side.
Right now the info is visible at all times regardless of what I click  
on!

I need to know how to join my echo statements and/or my query!

On Nov 13, 2006, at 12:57 PM, Warren Vail wrote:



Mel, that may have been a disguised hint.  Your answer lies in
javascript.  The first php page needs to contain javascript to open a
second page with the URL to the second php script when the first page
loads.

Keep a couple of things in mind, popup blockers will reek havoc if you
can't get visitors to your site to stop blocking popups and if you
expect both URLs to receive form contents, you will have to make
arrangements for that in the javascript in your first page, since it
will need to pass the data again.

Check out http://www.hotscripts.com for some links to sites with the
necessary javascript.

Hope this helps,

Warren Vail

-Original Message-
From: Mel [mailto:[EMAIL PROTECTED]
Sent: Monday, November 13, 2006 12:32 PM
To: John Meyer
Cc: PHP General List
Subject: Re: [PHP] one click - two actions?

I really don't know?

My site is all php and ready to go live except for this little  
problem.


I would really appreciate some help.

On Nov 13, 2006, at 4:12 AM, John Meyer wrote:


Not to be rude or anything, but if you want to do two things with one
click, wouldn't the javascript list be the place you would want to  
go?





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] one click - two actions?

2006-11-13 Thread Warren Vail
Mel,

Not sure if I understand your question now or not, but here goes.  In
order to prepare your page you want to be able to click a link on the
left and have the page on the right replaced with something in response.

Technically when php prepares the page, it prepares both sides (unless
you are using frames).  If preparing each side requires different
queries against your database, you can certainly do two database queries
in the same execution.  When you first posed your question you talked
about starting two pages at once.  What I see is one page.  Perhaps if
you used frames you could cause the left frame to be a separate PHP
script and the one on the right another, this would allow your server to
process both requests simultaneously, perhaps this is what you meant?
Technically they are still part of the one page, but each would be a
separate frame within the page.

Caution about using technical terms, in your first message you referred
to separate pages when (I believe) you may have been referring to one
page (yes, page is a technical term) and in your second message you used
a term Join which has a meaning when running queries on your database,
causing me to think for a moment that your question had been about
retrieving information from your database, which you seemed to mention.

If you opt to use frames and are new to PHP programming, or programming
with frames, expect difficulties (use of Target consistently is the
key).  I avoid frames unless I simply can't do what I want to do without
the use of them.  I think at one time some browsers didn't support
frames, not sure any more.

Warren Vail

-Original Message-
From: Mel [mailto:[EMAIL PROTECTED] 
Sent: Monday, November 13, 2006 1:32 PM
To: Warren Vail
Cc: 'John Meyer'; 'PHP General List'
Subject: Re: [PHP] one click - two actions?

Thank you for your reply. I think my question is really much more  
simple than what you are suggesting.
If you have a quick look at
http://www.squareinch.net/single_page.php?art=crp_logo.jpg
you will see what I mean.
I have a single page and both results load in the same page.

When I click on a link the picture loads on the left side and the  
info should load on the right side.
Right now the info is visible at all times regardless of what I click  
on!
I need to know how to join my echo statements and/or my query!

On Nov 13, 2006, at 12:57 PM, Warren Vail wrote:


 Mel, that may have been a disguised hint.  Your answer lies in
 javascript.  The first php page needs to contain javascript to open a
 second page with the URL to the second php script when the first page
 loads.

 Keep a couple of things in mind, popup blockers will reek havoc if you
 can't get visitors to your site to stop blocking popups and if you
 expect both URLs to receive form contents, you will have to make
 arrangements for that in the javascript in your first page, since it
 will need to pass the data again.

 Check out http://www.hotscripts.com for some links to sites with the
 necessary javascript.

 Hope this helps,

 Warren Vail

 -Original Message-
 From: Mel [mailto:[EMAIL PROTECTED]
 Sent: Monday, November 13, 2006 12:32 PM
 To: John Meyer
 Cc: PHP General List
 Subject: Re: [PHP] one click - two actions?

 I really don't know?

 My site is all php and ready to go live except for this little  
 problem.

 I would really appreciate some help.

 On Nov 13, 2006, at 4:12 AM, John Meyer wrote:

 Not to be rude or anything, but if you want to do two things with one
 click, wouldn't the javascript list be the place you would want to  
 go?



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] one click - two actions?

2006-11-13 Thread Paul Novitski

At 11/13/2006 01:28 AM, Mel wrote:

Could someone please help me figure out how to show some description
(where applicable) at the same time as I show an image, when I click
on a link, without repeating the entire query?
The image and the description are both in the same table in my database.

I now show the image when I click on the link which is good, but the
description stays on at all times instead of appearing only when active.

http://www.squareinch.net/single_page.php



Mel,

I think what you're looking for is JOIN syntax for your queries:
http://dev.mysql.com/doc/refman/4.1/en/join.html

For example:

SELECT * FROM client, job
WHERE client.companyId=job.companyId
AND (client.status='active' or client.status='old')
order by client.companyName;

(Note that when you extract fields from more than one table like 
this, you identify the table that each field belongs to, e.g. 
client.companyId.)


Then you can extract the desired fields from both tables in the same 
loop because they've been captured together.  Your current logic 
executes a job query for every row of client, which is extremely inefficient.


The dataset produced by the join query is going to look something like this:

client. job.
companyId   companyId
1   2
1   3
1   9
2   4
2   5
...

In other words, there will be one row for each job record, with the 
(parent) client fields duplicated each row.



You can further improve the efficiency of your query by naming only 
the fields you need, instead of using * to extract all fields:


SELECT client.companyName, job.pix, job.jobType, job.url, job.web
FROM client, job
WHERE client.companyId=job.companyId
AND (client.status='active' or client.status='old')
order by client.companyName;

Once you execute the join query, your PHP loop can cycle in a similar 
way, echoing a company name and then listing all the job types until 
a new company name occurs, etc.



You've got other problems, however.  If you look at your HTML source, 
you'll see markup like this:


span class='navCompany'Builtworks/spanspan class='navArrow'   /span
span class='navText'a 
href='single_page.php?art=btw_logo.jpg'logo/a/span

span class='navText'a href='single_page.php?art='/a/span
span class='navText'a href='single_page.php?art='/a/span
span class='navText'a href='single_page.php?art='/a/span
span class='navText'a href='single_page.php?art='/a/span
brspan class='navCompany'Citizens Bank / eProperty/spanspan 
class='navArrow'   /span
span class='navText'a 
href='single_page.php?art=ctz_web1.jpg'website/a/span


All those empty hyperlinks aren't doing anything but making your 
download heavier than it has to be.  I think you need to test your 
'jobType' fields and output only those that aren't blank.



Finally, to answer one of your questions, your logic to display the 
description area has a snarl of syntax flaws:



/* query 2 from job */

...

foreach($row as $url)
{
$row = mysql_fetch_array($result2,MYSQL_ASSOC);
if (url={$row['url']})
echo span class='navText'a 
href='{$row['url']}'{$row['web']}/ a/span;

}


You're testing if (url={$row['url']})

1) Because you've put that expression in quotes, you're testing the 
true/false value of a string expression which will always test true 
unless it's blank, which this one will never be.


Expressing it as a string might be correct if you were using eval(), 
but you're not and you're safer not to.  Eval() can get you into big 
trouble if there are PHP code fragments in your database fields; 
until you get better control of your logic I urge you not to use it.


2) You omitted the $ in front of $url.

3) You used a single equal sign instead of two.  This:
if ($url = $row['url'])
tests whether $row['url'] is blank, and also sets $url equal to that value.

I think you meant this:
if ($url == $row['url'])
which tests whether the variable $url is equal to the database field 
$row['url'].



Good luck,
Paul




This is the code I have for the image area:
/* query 1 from client */
  $query = SELECT * FROM client
where status='active' or status='old'
order by companyName;

  $result = mysql_query($query)
or die (Couldn't execute query);

  while ($aaa = mysql_fetch_array($result,MYSQL_ASSOC))
  {
  echo span class='navCompany'{$aaa['companyName']}/spanspan
class='navArrow'   /span\n;

/* query 2 from job */
$query = SELECT * FROM job
WHERE companyId='{$aaa['companyId']}';
$result2 = mysql_query($query)
or die (Couldn't execute query2);

foreach($aaa as $jobType)
{
$bbb =