Go Back   Forum Care Forums > Development Reference Area > Php Development

Reply
 
LinkBack Thread Tools Display Modes
Newbie - help with a foreach
Old
  (#1)
pub
Guest
 
Posts: n/a
Default Newbie - help with a foreach - 05-14-2007, 03:35 AM

Could someone please help me figure out how to hide the info in the
right bottom part of my page unless the corresponding link is
selected in the top left.

The company names and job types at the top left need to show at all
time. But the corresponding picture at the bottom left and the web
address/info at the bottom right should appear only when selected.

I have the same query repeating twice once for the top left part and
once for the bottom right part because I can't figure out how else to
do it!

Thank you.

http://www.squareinch.net/single_pag...t=btw_logo.jpg
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Re: [PHP] Newbie - help with a foreach
Old
  (#2)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM

I can't really understand what your problem is, because it seems to me
that the site is working like you want it to work. Or not?

And if there is a problem with the code then please show us the code
somehow, not the resulting webpage

greets
Zoltán Németh

On cs, 2007-01-18 at 01:31 -0800, pub wrote:
> Could someone please help me figure out how to hide the info in the
> right bottom part of my page unless the corresponding link is
> selected in the top left.
>
> The company names and job types at the top left need to show at all
> time. But the corresponding picture at the bottom left and the web
> address/info at the bottom right should appear only when selected.
>
> I have the same query repeating twice once for the top left part and
> once for the bottom right part because I can't figure out how else to
> do it!
>
> Thank you.
>
> http://www.squareinch.net/single_pag...t=btw_logo.jpg

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#3)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM

ok, but how could anyone help without seeing your code?

greets
Zoltán Németh

On cs, 2007-01-18 at 01:54 -0800, pub wrote:
> Thank you for your reply.
>
> My problem is that the web addresses on the bottom right show at all
> times as is instead of appearing only when active or selected on the
> left top navigation!
>
> Does that make sense?
>
> On Jan 18, 2007, at 1:43 AM, Németh Zoltán wrote:
>
> > I can't really understand what your problem is, because it seems to me
> > that the site is working like you want it to work. Or not?
> >
> > And if there is a problem with the code then please show us the code
> > somehow, not the resulting webpage
> >
> > greets
> > Zoltán Németh
> >
> > On cs, 2007-01-18 at 01:31 -0800, pub wrote:
> >> Could someone please help me figure out how to hide the info in the
> >> right bottom part of my page unless the corresponding link is
> >> selected in the top left.
> >>
> >> The company names and job types at the top left need to show at all
> >> time. But the corresponding picture at the bottom left and the web
> >> address/info at the bottom right should appear only when selected.
> >>
> >> I have the same query repeating twice once for the top left part and
> >> once for the bottom right part because I can't figure out how else to
> >> do it!
> >>
> >> Thank you.
> >>
> >> http://www.squareinch.net/single_pag...t=btw_logo.jpg

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

>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#4)
pub
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM

Thank you for your reply.

My problem is that the web addresses on the bottom right show at all
times as is instead of appearing only when active or selected on the
left top navigation!

Does that make sense?

On Jan 18, 2007, at 1:43 AM, Németh Zoltán wrote:

> I can't really understand what your problem is, because it seems to me
> that the site is working like you want it to work. Or not?
>
> And if there is a problem with the code then please show us the code
> somehow, not the resulting webpage
>
> greets
> Zoltán Németh
>
> On cs, 2007-01-18 at 01:31 -0800, pub wrote:
>> Could someone please help me figure out how to hide the info in the
>> right bottom part of my page unless the corresponding link is
>> selected in the top left.
>>
>> The company names and job types at the top left need to show at all
>> time. But the corresponding picture at the bottom left and the web
>> address/info at the bottom right should appear only when selected.
>>
>> I have the same query repeating twice once for the top left part and
>> once for the bottom right part because I can't figure out how else to
>> do it!
>>
>> Thank you.
>>
>> http://www.squareinch.net/single_pag...t=btw_logo.jpg

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

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#5)
pub
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM


On Jan 18, 2007, at 2:00 AM, Németh Zoltán wrote:

> ok, but how could anyone help without seeing your code?
>
> greets
> Zoltán Németh
>

Here is the code:

Here is the entire page:

<!-- nav/box 1 starts here -->



<?php
include("../include/etc_inc.php");

$connection = mysql_connect($host,$user,$p***word)
or die ("couldn't connect to server");

// connect to database
$db = mysql_select_db($database,$connection)
or die ("Couldn't select database");

// query a 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_***OC))
{
echo "<span cl***='navCompany'>{$aaa['companyName']}</span><span
cl***='navArrow'> > </span>\n";

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

foreach($aaa as $jobType)
{
$bbb = mysql_fetch_array($result2,MYSQL_***OC);
echo "<span cl***='navText'><a href='single_page_t2.php?art=".$bbb
['pix']."'>{$bbb['jobType']}</a></span>\n";

}

echo "<br>";
}
?>



<!-- nav/box 1 ends here -->



</div>
<div cl***="navbox2"><img src="images/sq_logo_137.gif" alt="Square
Inch logo" width="137" height="137"></div>

<div cl***="navbox3"><?php $image = $_GET['art']; ?>
<img src="images/<?php print ($image) ?>" alt="Portfolio Item"
border="0" width="285" height="285"></div>



<div cl***="navbox4">




<!-- info/box 4 starts here -->
<?php
/* 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_***OC))
{

/* 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_***OC);
if ("url={$row['url']}")
echo "<span cl***='navText'><a href='{$row['url']}'>{$row['web']}</
a></span>";
}

echo "<br>";
}
?>


<!-- info/box 4 ends here -->





> On cs, 2007-01-18 at 01:54 -0800, pub wrote:
>> Thank you for your reply.
>>
>> My problem is that the web addresses on the bottom right show at all
>> times as is instead of appearing only when active or selected on the
>> left top navigation!
>>
>> Does that make sense?
>>
>> On Jan 18, 2007, at 1:43 AM, Németh Zoltán wrote:
>>
>>> I can't really understand what your problem is, because it seems
>>> to me
>>> that the site is working like you want it to work. Or not?
>>>
>>> And if there is a problem with the code then please show us the code
>>> somehow, not the resulting webpage
>>>
>>> greets
>>> Zoltán Németh
>>>
>>> On cs, 2007-01-18 at 01:31 -0800, pub wrote:
>>>> Could someone please help me figure out how to hide the info in the
>>>> right bottom part of my page unless the corresponding link is
>>>> selected in the top left.
>>>>
>>>> The company names and job types at the top left need to show at all
>>>> time. But the corresponding picture at the bottom left and the web
>>>> address/info at the bottom right should appear only when selected.
>>>>
>>>> I have the same query repeating twice once for the top left part
>>>> and
>>>> once for the bottom right part because I can't figure out how
>>>> else to
>>>> do it!
>>>>
>>>> Thank you.
>>>>
>>>> http://www.squareinch.net/single_pag...t=btw_logo.jpg
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>

>>

>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#6)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM

On cs, 2007-01-18 at 02:04 -0800, pub wrote:
> On Jan 18, 2007, at 2:00 AM, Németh Zoltán wrote:
>
> > ok, but how could anyone help without seeing your code?
> >
> > greets
> > Zoltán Németh
> >

> Here is the code:
>
> Here is the entire page:
>
> <!-- nav/box 1 starts here -->
>
>
>
> <?php
> include("../include/etc_inc.php");
>
> $connection = mysql_connect($host,$user,$p***word)
> or die ("couldn't connect to server");
>
> // connect to database
> $db = mysql_select_db($database,$connection)
> or die ("Couldn't select database");
>
> // query a 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_***OC))
> {
> echo "<span cl***='navCompany'>{$aaa['companyName']}</span><span
> cl***='navArrow'> > </span>\n";
>
> // query b from job
> $query = "SELECT * FROM job
> WHERE companyId='{$aaa['companyId']}'";
> $result2 = mysql_query($query)
> or die ("Couldn't execute query b");
>
> foreach($aaa as $jobType)
> {
> $bbb = mysql_fetch_array($result2,MYSQL_***OC);
> echo "<span cl***='navText'><a href='single_page_t2.php?art=".$bbb
> ['pix']."'>{$bbb['jobType']}</a></span>\n";
>
> }


first, do you want to allow several jobs for the same company to be
stored in the DB and appear on the page, right? (if not, then why are
you storing them in separate tables?)

second, you should do it with one query I think

something like "SELECT t1.*, t2.* FROM client t1, job t2 WHERE
t1.companyId=t2.companyId ORDER BY t1.companyId"

and then you can do all stuff in one loop

while ($aaa = mysql_fetch_array($result))

and you don't need that foreach stuff at all (which also seems to be
screwed up...)


>
>
> echo "<br>";
> }
> ?>
>
>
>
> <!-- nav/box 1 ends here -->
>
>
>
> </div>
> <div cl***="navbox2"><img src="images/sq_logo_137.gif" alt="Square
> Inch logo" width="137" height="137"></div>
>
> <div cl***="navbox3"><?php $image = $_GET['art']; ?>
> <img src="images/<?php print ($image) ?>" alt="Portfolio Item"
> border="0" width="285" height="285"></div>
>
>
>
> <div cl***="navbox4">
>
>
>
>
> <!-- info/box 4 starts here -->
> <?php
> /* query 1 from client */


and here you should not run the whole query again

you should specifically query the one which should appear

maybe you should use a parameter for it, place it into the link in the
first query loop, get it here and query based on it

like "SELECT * FROM job WHERE id={$_GET['job_id']}" or whatever

and just echo the data from that record

hope that helps
Zoltán Németh

>


> $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_***OC))
> {
>
> /* 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_***OC);
> if ("url={$row['url']}")
>
> echo "<span cl***='navText'><a href='{$row['url']}'>{$row['web']}</
> a></span>";
> }
>
> echo "<br>";
> }
> ?>
>
>
> <!-- info/box 4 ends here -->
>
>
>
>
>
> > On cs, 2007-01-18 at 01:54 -0800, pub wrote:
> >> Thank you for your reply.
> >>
> >> My problem is that the web addresses on the bottom right show at all
> >> times as is instead of appearing only when active or selected on the
> >> left top navigation!
> >>
> >> Does that make sense?
> >>
> >> On Jan 18, 2007, at 1:43 AM, Németh Zoltán wrote:
> >>
> >>> I can't really understand what your problem is, because it seems
> >>> to me
> >>> that the site is working like you want it to work. Or not?
> >>>
> >>> And if there is a problem with the code then please show us the code
> >>> somehow, not the resulting webpage
> >>>
> >>> greets
> >>> Zoltán Németh
> >>>
> >>> On cs, 2007-01-18 at 01:31 -0800, pub wrote:
> >>>> Could someone please help me figure out how to hide the info in the
> >>>> right bottom part of my page unless the corresponding link is
> >>>> selected in the top left.
> >>>>
> >>>> The company names and job types at the top left need to show at all
> >>>> time. But the corresponding picture at the bottom left and the web
> >>>> address/info at the bottom right should appear only when selected.
> >>>>
> >>>> I have the same query repeating twice once for the top left part
> >>>> and
> >>>> once for the bottom right part because I can't figure out how
> >>>> else to
> >>>> do it!
> >>>>
> >>>> Thank you.
> >>>>
> >>>> http://www.squareinch.net/single_pag...t=btw_logo.jpg
> >>>
> >>> --
> >>> PHP General Mailing List (http://www.php.net/)
> >>> To unsubscribe, visit: http://www.php.net/unsub.php
> >>>
> >>

> >

>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#7)
Jochem Maas
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM

Németh Zoltán wrote:
> On cs, 2007-01-18 at 02:04 -0800, pub wrote:
>> On Jan 18, 2007, at 2:00 AM, Németh Zoltán wrote:
>>



....

> maybe you should use a parameter for it, place it into the link in the
> first query loop, get it here and query based on it
>
> like "SELECT * FROM job WHERE id={$_GET['job_id']}" or whatever


SQL INJECTION WAITING TO HAPPEN.


....

>> foreach($row as $url)
>> {
>> $row = mysql_fetch_array($result2,MYSQL_***OC);
>> if ("url={$row['url']}")


what is this IF statement supposed to be doing???
because it will always evaluate to true
   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#8)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:35 AM

On cs, 2007-01-18 at 20:46 +0100, Jochem Maas wrote:
> Németh Zoltán wrote:
> > On cs, 2007-01-18 at 02:04 -0800, pub wrote:
> >> On Jan 18, 2007, at 2:00 AM, Németh Zoltán wrote:
> >>

>
>
> ...
>
> > maybe you should use a parameter for it, place it into the link in the
> > first query loop, get it here and query based on it
> >
> > like "SELECT * FROM job WHERE id={$_GET['job_id']}" or whatever

>
> SQL INJECTION WAITING TO HAPPEN.


true, sorry
so check the value first

greets
Zoltán Németh

>
>
> ...
>
> >> foreach($row as $url)
> >> {
> >> $row = mysql_fetch_array($result2,MYSQL_***OC);
> >> if ("url={$row['url']}")

>
> what is this IF statement supposed to be doing???
> because it will always evaluate to true

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Re: [PHP] Newbie - help with a foreach
Old
  (#9)
Guest
Guest
 
Posts: n/a
Default Re: [PHP] Newbie - help with a foreach - 05-14-2007, 03:36 AM

On v, 2007-01-21 at 01:28 -0800, pub wrote:
> On Jan 18, 2007, at 2:43 AM, Németh Zoltán wrote:
>
> > first, do you want to allow several jobs for the same company to be
> >
> > stored in the DB and appear on the page, right? (if not, then why
> > are
> >
> > you storing them in separate tables?)
> >
> >

> Yes, I have the name of the company with address etc in the "client"
> table
> and all the jobs in the "job" table, so that I can display several
> jobs per client
> > second, you should do it with one query I think
> >
> >
> > something like "SELECT t1.*, t2.* FROM client t1, job t2 WHERE
> >
> > t1.companyId=t2.companyId ORDER BY t1.companyId"
> >
> >
> > and then you can do all stuff in one loop
> >
> >
> > while ($aaa = mysql_fetch_array($result))
> >
> >
> > and you don't need that foreach stuff at all (which also seems to be
> >
> > screwed up...)
> >

>
> 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 twice. 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?
>
>


ehh, I thought you want the jobs on separate lines, sorry.

this can be achieved for example like this:

$prev_cname = "";
while ($aaa = mysql_fetch_array($result,MYSQL_***OC))
{
if ($aaa['companyName'] != $prev_cname) {
echo "<span cl***='navCompany'>{$aaa['companyName']}</span>";
}
echo "<span cl***='navArrow'> > </span><span cl***='navText'><a
href='single_page_t10.php?art=".$aaa['pix']."'>{$aaa['jobType']}</a></span>";
if ($aaa['companyName'] != $prev_cname) {
echo "<br/>\n";
$prev_cname = $aaa['companyName'];
}
}

hope that helps
Zoltán Németh


> 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_***OC))
> {
> echo "<span cl***='navCompany'>{$aaa['companyName']}</span><span
> cl***='navArrow'> > </span><span cl***='navText'><a
> href='single_page_t10.php?art=".$aaa['pix']."'>{$aaa['jobType']}</a></span><br>\n";
> }
>

   
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Contact Us - Forum Care Forums - Archive - Top