Jump to content


Photo

Selecting from Database mySQL


  • Please log in to reply
4 replies to this topic

#1 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 24 August 2006 - 01:39 PM

Ok, I have a page where I can edit the entries I have and it works fine.  I think the problem is that there is multiple entries that will have UCF as their area...  I want the sql to go through and only display the bars in that area

$idm = $_GET[id];
$sql = "SELECT * FROM $table_name WHERE UCF_id=$idm";

but when I try to bring up only a certain area of bars I get an error

$barAreaM = "$_GET[barMenu]";
$sql = "SELECT * FROM $table_name WHERE barName=$barAreaM";

Unknown column 'UCF' in 'where clause'



#2 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 24 August 2006 - 01:54 PM

<?

//access the database
$barAreaM = "$_GET[barMenu]";

$db_name = "cfuf"; 
$table_name = "dso_bars";

$connection = @mysql_connect("+++", "+++", "+++")
	or die(mysql_error());

$db = @mysql_select_db($db_name, $connection) or die(mysql_error());

$sql = "SELECT * FROM $table_name WHERE barName=$barAreaM";

$result = @mysql_query($sql, $connection) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
	$barArea = $row['barArea'];
	$UCF_id = $row['UCF_id'];
	$barName = stripslashes($row['barName']);
	$barPhone = stripslashes($row['barPhone']);
	$barAddress = stripslashes($row['barAddress']);
	$barVIP = stripslashes($row['barVIP']);
	$barCity = stripslashes($row['barCity']);
	$barZip = stripslashes($row['barZip']);	
	$barComments = stripslashes($row['barComments']);
	$barKey = stripslashes($row['barKey']);
	$barKey = unserialize($row['barKey']);
		$view = '<a href="../bar/do_viewbar.php?id='. $UCF_id. '">
				<img src="../images/search.png" width="16" height="16" border="0"></a>';
		$edit = '<a href="../bar/edit_bar.php?id='. $UCF_id. '">
				<img src="../images/edit.png" width="16" height="16" border="0"></a>';
		$delete = '<a href="../bar/delete_confirm.php?id='. $UCF_id. '"><img src="../images/delete.png" width="16" height="16" border="0"></a>';
$display_block .= "<p><strong>$barName:</strong> $barAddress, $barCity $barZip<br>
				   Phone: $barPhone  VIP Line: $barVIP $view $edit $delete</p><br>
     <strong>Bar Key:</strong> $barKey[0] $barKey[1] $barKey[2] $barKey[3] $barKey[4] $barKey[5] $barKey[6] $barKey[7] $barKey[8]<br>
	 $barKey[9] $barKey[10] $barKey[11] $barKey[12]<hr />";
} ?>

<html>
<head>
<title>View Bars</title>
</head>
<body>
<p><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><img src="../images/admin_head.gif" width="380" height="51" /></font><a href="../admin_main.html"><img src="../images/Menu.png" width="94" height="32" border="0"></a></p>
<hr />
<span class="Heading"><strong class="Heading"><font color="#B5BFCC" size="6" face="Verdana, Arial, Helvetica, sans-serif">Orlando </font><font color="#B5BFCC" size="6" face="Verdana, Arial, Helvetica, sans-serif">Area<br>
</font></strong><font size="1" face="Verdana, Arial, Helvetica, sans-serif"><br>
<br>
<? echo "$display_block"; ?></font>
</body>
</html>


This is how I would get all the bars before

$sql = "SELECT * FROM $table_name ORDER BY UCF_id";


#3 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 August 2006 - 01:58 PM

I don't understand how you get an unknown column UCF from a query looking for the column barName.

Try restructuring your code - and remove the @ symbols so you see errors.

$barAreaM = $_GET['barMenu'];
$sql = "SELECT * FROM $table_name WHERE barName = '$barAreaM' ";
$result = mysql_query($sql) or die("Error: ". mysql_error(). " with query ". $sql); // helpful error message

Legend has it that reading the manual never killed anyone.
My site

#4 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 24 August 2006 - 07:49 PM

ok, i changed
$sql = "SELECT * FROM $table_name WHERE barName=$barAreaM";

to

$sql = "SELECT * FROM $table_name WHERE barName='$barAreaM'";

but now I get no bars at all...

#5 FloridaNutz

FloridaNutz
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 24 August 2006 - 07:51 PM

sorry, typo

$sql = "SELECT * FROM $table_name WHERE barName='$barAreaM'";

I have no idea why I put barName instead of barArea.... too much time infornt of the computer...

Fixed it




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users