Jump to content

Issues with if statement and MySQL data


BCAV_WEB

Recommended Posts

untitled.jpg

 

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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>
											  ";	
  										}

Link to comment
Share on other sites

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  :D

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.