PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 27th, 2007, 02:48 PM
ABM2007 ABM2007 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 3 ABM2007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 7 sec
Reputation Power: 0
Exclamation PHP&SQL merge tables?

The problem is real simple,

I have a database with products which i search through. Some products however look the same, but have different dimensions... I want the products that look the same to be output into 1 table. For example:

Scissor
-------4inch
-------5inch
-------6inch

Instead of what i have now all products seperately output:
Scissor
-------4inch

Scissor
-------5inch

Here is a bit of code i have... the url-small is the link to the image of the product ( match to this ) and article are the products.
So my database has numerous articles that share the same image. and i want those acticles to be displayed WITH just 1 image.

Here is what i have so far:

PHP Code:
 $data mysql_query("SELECT * FROM temp_26_01_2007_22_00_25 WHERE $field LIKE'%$find%'");

$find strtoupper($find); 
$find strip_tags($find); 
$find trim ($find);

while(
$result = @mysql_fetch_array$data )) 
{

echo 
"<a href=".$result['url-big']."><img src=".$result['url-small']."></a>";  
echo 
$result['Article:']; 
echo 
" "
echo 
"<br>"
echo 
$result['zoek1']; 
echo 
"<br>"
echo 
$result['zoek3'];
echo 
"<br>"



I hope i'm making myself clear enough, english is not my first language. And i'd be very thankfull if anyone could help me with the problem.

Reply With Quote
  #2  
Old January 28th, 2007, 12:40 PM
ABM2007 ABM2007 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 3 ABM2007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 7 sec
Reputation Power: 0
Anyone?

I brushed my teeth right? hehe nobody knows?

All i want is to have multiple products shown next to 1 picture...
Can anyone help me please because my knowledge of this ends here...

Anne.

Reply With Quote
  #3  
Old January 28th, 2007, 04:52 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 14
displaying results from table

Don't forget to floss.
You should be able to do this with a nested if loop or two. I tend to come up with PHP-centric solutions even when there are nuch more efficient and elegant database methods available to achieve the same result, but if you provide more detail pertaining to the database schema (ie. field names) I may be able to give some help.

Reply With Quote
  #4  
Old January 29th, 2007, 11:28 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,886 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 19 m 35 sec
Reputation Power: 18
Is it necessary to have dimensions in the same record?
You might want to consider breaking them out into their own table.

Just a brainstorming thought, I haven't considered the pros/cons.
I wouldn't mind seeing your database schema
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
  #5  
Old January 30th, 2007, 03:32 PM
ABM2007 ABM2007 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2007
Posts: 3 ABM2007 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 58 m 7 sec
Reputation Power: 0
i came up with the following code, it now contains a if statement when it finds duplicates.

PHP Code:
 $data mysql_query("SELECT * FROM temp_26_01_2007_22_00_25 WHERE $field LIKE'%$find%'");  

$find strtoupper($find);  
$find strip_tags($find);  
$find trim ($find);  

$oldarticle "";  

while(
$result = @mysql_fetch_array$data ))  
{  

echo 
"<a href=".$result['url-big']."><img src=".$result['url-small']."></a>";    
if (
$oldarticle == $result['Article']) // If it is the same article  
{  
    echo 
$result['Article:'];  
    
// Do nothing  
}  
else 
// If it is a new article  
{  
    echo 
"<a href=".$result['url-groot']."><img src=".$result['url-klein']."></a>";  
    echo 
$result['Article:'];  
    
$oldarticle $result['Article'];  
}  
echo 
" ";  
echo 
"<br>";  
echo 
$result['zoek1'];  
echo 
"<br>";  
echo 
$result['zoek3'];  
echo 
"<br>";  



The problem now however is the end result, i want to put this into a nice table... Picture left, and the articles found right.

I have added two attachments, the one called current.jpg is how the data will be shown now... It will output each result in a different table. Even though the articles have the same picture... This is a working script already:

www. b o t t e r m e d i a.nl/current.JPG
( I had to put in space because for some reason it blocked the url )

With the code i posted it will put articles with the same url-klein next to one picture without outputting duplicated. Very neat

But currently, i cannot get the result i want to... the second attachment shows you the result i need ( modified with paint
And that's the problem, i can't get it to be like the result.jpg picture:

www. b o t t e r m e d i a.nl/result.JPG

The table code looks like this for example:

Code:
<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table1">
	<tr>
		<td>
		<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table2">
			<tr>
				<td width="26" height="21"></td>
				<td width="155" height="21"></td>
				<td height="21"></td>
				<td width="18" height="21" valign="bottom"></td>
			</tr>
			<tr>
				<td width="26"></td>
				<td width="155" valign="top">
				<p align="center">Main picture</td>
				<td valign="top">
				<table border="0" width="100%" cellspacing="0" cellpadding="0" id="table3">
					<tr>
						<td><font face="Verdana" size="1">Article 1</font></td>
						<td width="83">info button</td>
					</tr>
					<tr>
						<td><font face="Verdana" size="1">Article 2</font></td>
						<td width="83">info button</td>
					</tr>
				</table>
				</td>
				<td width="18"></td>
			</tr>
			<tr>
				<td width="26"></td>
				<td width="155">
				<p align="center"><b><font face="Verdana" size="1">category</font></b></td>
				<td></td>
				<td width="18"></td>
			</tr>
		</table>
		</td>
	</tr>
</table>


So how can i make an extra loop or whatever i need to make in order to finish the table neatly even when several products have been found. And believe me, i have tried this over and over.. I can't figure it out

Thanks for your help.
xAnne

Reply With Quote
  #6  
Old January 30th, 2007, 06:33 PM
Mittineague's Avatar
Mittineague Mittineague is offline
Contributing User
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jul 2005
Location: West Springfield, Massachusetts
Posts: 552 Mittineague User rank is Private First Class (20 - 50 Reputation Level)Mittineague User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 9 h 1 m 33 sec
Reputation Power: 14
echo inside loop

Maybe if instead of using echo inside the loop you try assigning the value to a variable and then echo that variable outside of the loop? eg.
PHP Code:
 $result_display '';
..... 
/* loop */
$result_display .= $result['Article:'];
..... 
/* end of loop */
echo $result_display

You may need to have $result_display be an array if re-setting it to empty somewhere won't work. Then maybe use a for loop, eg.
PHP Code:
.....
echo 
$result_display[$i]; 

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > PHP&SQL merge tables?


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap