BCAV_WEB Posted December 16, 2010 Share Posted December 16, 2010 Hi, I'm having a slight issue with some coding (see below). It worked a few minutes ago before I add "Packages" & "Safety & Technology" titles to the MySQL database. Hopefully the attached image has worked, but if it hasn't go to www.bikescarsandvans.co.uk/test.php and select the first Audi A3 additional extras drop down menu and you'll see whats going wrong. $query_title = "SELECT * FROM extras JOIN car_to_extra ON (car_to_extra.extras_id = extras.id) WHERE car_to_extra.car_id = '{$car_row['id']}' ORDER BY extras.price ASC"; $title_results = mysql_query($query_title) or die ("Error in query: $query_title. ".mysql_error()); $current_heading = ''; print "<div class='addtional_extras'>";// ADDED TO TRY TO SORT OUT POSITIONING ISSUE while ($title_row = @ mysql_fetch_array($title_results )) { if ($current_heading != $title_row["title"]) { // The heading has changed from before, so print the new heading here. $current_heading = $title_row["title"]; print " <div class='title_tab2'>" . $title_row["title"] . "</div> "; } ?> <a class='data' href='#' onmouseout='hideTooltip()' onmouseover='showTooltip(event,"<?php print "" . $title_row["info"] . "<br/>(£" . $title_row["price"] . ")"; ?>");return false'> <?php print " <img class='extra_img' src=\"". $title_row["img"] ."\" alt='" . $title_row["img_alt"] . "' /></a> "; }// CLOSES WHILE LOOP ($title_row = @ mysql_fetch_array($title_results )) print "</div>";// CLOSES DIV IMAGE55 Quote Link to comment https://forums.phpfreaks.com/topic/221860-issues-with-if-statement-and-mysql-data/ Share on other sites More sharing options...
trq Posted December 16, 2010 Share Posted December 16, 2010 Hopefully the attached image has worked, but if it hasn't go to www.bikescarsandvans.co.uk/test.php and select the first Audi A3 additional extras drop down menu and you'll see whats going wrong. Better still. How about explaining your problem? Quote Link to comment https://forums.phpfreaks.com/topic/221860-issues-with-if-statement-and-mysql-data/#findComment-1148073 Share on other sites More sharing options...
BCAV_WEB Posted December 16, 2010 Author Share Posted December 16, 2010 Okay, well we are doing a query which is to return data on additional extras, so title (Interior), images (image/extras/interior_light.jpg) price etc... The first point is that each inserted bit of data will have a repeating title ie interior, leather seats and interior, cloth seats. So we don't want them to repeat so I'm doing the following if statement, just ignore the while and the print at the top. But the first thing I'm doing is defing the variable $current_heading as nothing then I'm saying within the while query, if variable $current_heading is not retrived data field title (interior) etc... then display, which worked about an hour ago when I had 6 bits of data 3 upholstery and 3 interior. Since adding extra data such as packages, safety & technology, it has stopped working. Duplicating titles, my inital thought was I might have accidently added a space meaning that it wouldn't be the same as the previous one, but on inspection of the data this isnt the issue. I hope that explains it a little better. Any ideas of whats going wrong? $current_heading = ''; print "<div class='addtional_extras'>";// ADDED TO TRY TO SORT OUT POSITIONING ISSUE while ($title_row = @ mysql_fetch_array($title_results )) { if ($current_heading != $title_row["title"]) { // The heading has changed from before, so print the new heading here. $current_heading = $title_row["title"]; print " <div class='title_tab2'>" . $title_row["title"] . "</div> "; } Quote Link to comment https://forums.phpfreaks.com/topic/221860-issues-with-if-statement-and-mysql-data/#findComment-1148075 Share on other sites More sharing options...
trq Posted December 16, 2010 Share Posted December 16, 2010 Sounds to me like you need a GROUP BY clause in your query. Quote Link to comment https://forums.phpfreaks.com/topic/221860-issues-with-if-statement-and-mysql-data/#findComment-1148089 Share on other sites More sharing options...
BCAV_WEB Posted December 16, 2010 Author Share Posted December 16, 2010 I've figured out, it seems on my orginial query I was ordering by price so all the £0.00 came first regardless of the title, so the first fix was to order by title but that then put upholstery at the bottom. So I created an new field called order, to arrange the section to my personal preference. So all sorted now Quote Link to comment https://forums.phpfreaks.com/topic/221860-issues-with-if-statement-and-mysql-data/#findComment-1148091 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.