can someone check my code please

Soldato
Joined
1 Dec 2004
Posts
22,567
Location
S.Wales
right, firstly go here


www.caldicot-pc-helpdesk.co.uk/fcv/database/index4.php

what i am trying to achieve is in the search, you type in a string, if DVD or VIDEO table is selected from the dropdown box, i want it to execute some code which will display a certain number of fields.

else

if the PS2 OR xbox360 table is selected, i want it to execute another piece of code, reason being is because the video/dvd table have different fields from the XBOX & PS2 table..

i have achieved this with the following code

Code:
$input = strip_tags($_POST['userQuery']);
$searchTable = $_POST['select'];


if ($searchTable == DVD || VIDEO) {

	$sql = "SELECT * FROM $searchTable WHERE MATCH (catagory, title, certificate) AGAINST ('$userQuery')";

	$result = mysql_query($sql) or die (mysql_error());

//Shows number of rows (number of results)
///////////////////////////////////////
	$num_rows = mysql_num_rows($result);
	echo "Showing results\n: $num_rows of $num_rows ";
///////////////////////////////////////
//end of showing number of results code
	
		while ($field = mysql_fetch_array($result))
			{

			echo '<div align="left" class="result">';
				$searchResults = $field['catagory'];
				echo '<b>Catagory: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['title'];
				echo '<b>Title: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['certificate'];
				echo '<b>Certificate: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['price'];
				echo '<b>Price: </b>';
				echo $searchResults;
				echo '<br>';
		
				//IMAGE CODE//
				echo '<img src='.$field['image']. '>';
	
			echo "</div>";
			}

}

elseif ($searchTable == "xbox360" || "ps2") {

	$sql = "SELECT * FROM $searchTable WHERE MATCH (platform, developer, title, genre) AGAINST ('$userQuery)";
	$result = mysql_query($sql) or die (mysql_error());

//Shows number of rows (number of results)
///////////////////////////////////////
	$num_rows = mysql_num_rows($result);
	echo "Showing results\n: $num_rows of $num_rows ";
///////////////////////////////////////
//end of showing number of results code


		while ($field = mysql_fetch_array($result))
			{

			echo '<div align="left" class="result">';
				$searchResults = $field['platform'];
				echo '<b>Platform: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['developer'];
				echo '<b>Developer: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['title'];
				echo '<b>Title: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['genre'];
				echo '<b>Genre: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['synopsis'];
				echo '<b>Synopsis: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['price'];
				echo '<b>Price: </b>';
				echo $searchResults;
				echo '<br>';
	
				//IMAGE CODE//
				echo '<img src='.$field['image']. '>';
		
			echo "</div>";
			}

}

only problem is, when i choose xbox table or ps2 table, the only error it gives me is

Unknown column 'catagory' in 'where clause'

somewhere along the line the else if statement is picking up something from the 1st if statement, there is no field called "catagory" in my console games table.
 
Im no php expert, but in most languages if you do:

if (something == 'a' || 'b')

It gets borken down into two checks, one being a comparison between 'something' and 'a', and a boolean conversion of 'b'

You generally need to do:

if (something == 'a' || something == 'b')

....
 
Visage said:
Im no php expert, but in most languages if you do:

if (something == 'a' || 'b')

It gets borken down into two checks, one being a comparison between 'something' and 'a', and a boolean conversion of 'b'

You generally need to do:

if (something == 'a' || something == 'b')

....

i didnt think of it like that, will give that a try
 
Code:
if ($searchTable == 'DVD' || $searchTable == 'VIDEO') {

	$sql = "SELECT * FROM $searchTable WHERE MATCH (catagory, title, certificate) AGAINST ('$userQuery')";

	$result = mysql_query($sql) or die (mysql_error());

//Shows number of rows (number of results)
///////////////////////////////////////
	$num_rows = mysql_num_rows($result);
	echo "Showing results\n: $num_rows of $num_rows ";
///////////////////////////////////////
//end of showing number of results code
	
		while ($field = mysql_fetch_array($result))
			{

			echo '<div align="left" class="result">';
				$searchResults = $field['catagory'];
				echo '<b>Catagory: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['title'];
				echo '<b>Title: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['certificate'];
				echo '<b>Certificate: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['price'];
				echo '<b>Price: </b>';
				echo $searchResults;
				echo '<br>';
		
				//IMAGE CODE//
				echo '<img src='.$field['image']. '>';
	
			echo "</div>";
			}

}

elseif ($searchTable == 'xbox360' || $searchTable == 'ps22') {

	$sql = "SELECT * FROM $searchTable WHERE MATCH (platform, developer, title, genre) AGAINST ('$userQuery)";
	$result = mysql_query($sql) or die (mysql_error());

//Shows number of rows (number of results)
///////////////////////////////////////
	$num_rows = mysql_num_rows($result);
	echo "Showing results\n: $num_rows of $num_rows ";
///////////////////////////////////////
//end of showing number of results code


		while ($field = mysql_fetch_array($result))
			{

			echo '<div align="left" class="result">';
				$searchResults = $field['platform'];
				echo '<b>Platform: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['developer'];
				echo '<b>Developer: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['title'];
				echo '<b>Title: </b>';
				echo $searchResults;
				echo '<br>';
		
				$searchResults = $field['genre'];
				echo '<b>Genre: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['synopsis'];
				echo '<b>Synopsis: </b>';
				echo $searchResults;
				echo '<br>';
	
				$searchResults = $field['price'];
				echo '<b>Price: </b>';
				echo $searchResults;
				echo '<br>';
	
				//IMAGE CODE//
				echo '<img src='.$field['image']. '>';
		
			echo "</div>";
			}

}

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''ubisoft)' at line 1
 
Back
Top Bottom