Jump to content


This topic is now archived and is closed to further replies.


Selecting from Database mySQL

Recommended Posts

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";[/code]

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";[/code]

Unknown column 'UCF' in 'where clause'

Share this post

Link to post
Share on other sites

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

<title>View Bars</title>
<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>
<? echo "$display_block"; ?></font>


This is how I would get all the bars before

$sql = "SELECT * FROM $table_name ORDER BY UCF_id";[/code]

Share this post

Link to post
Share on other sites
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.

[code]$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[/code]

Share this post

Link to post
Share on other sites
ok, i changed
[code]$sql = "SELECT * FROM $table_name WHERE barName=$barAreaM";


$sql = "SELECT * FROM $table_name WHERE barName='$barAreaM'";[/code]

but now I get no bars at all...

Share this post

Link to post
Share on other sites
sorry, typo

[code]$sql = "SELECT * FROM $table_name WHERE barName='$barAreaM'";[/code]

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

Fixed it

Share this post

Link to post
Share on other sites


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.