Re: Newbie - help with a foreach

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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,$password)
>         			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_ASSOC))
>    {  			
>    echo "<span class='navCompany'>{$aaa['companyName']}</span><span  
> class='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_ASSOC);
> 			echo "<span class='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 class="navbox2"><img src="images/sq_logo_137.gif" alt="Square  
> Inch logo" width="137" height="137"></div>
> 
> <div class="navbox3"><?php $image = $_GET['art']; ?>
> 			<img src="images/<?php print ($image) ?>"  alt="Portfolio Item"  
> border="0" width="285" height="285"></div>
> 
> 
> 
> <div class="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_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>";	
> 	}
> 	?>
> 
> 
> <!-- 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_page_t2.php?art=btw_logo.jpg
> >>>
> >>> -- 
> >>> 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux