...

View Full Version : A simple select statement, but I have an error...



briintex1
09-27-2004, 03:14 AM
I have a select statement that gets an ID from the URL, with this ID I want it to select an image from a database, or the code for the image so it will be displayed can someone tell me what is wrong with my code.

<?
//-----------------------------------
//this is the connection string to connect to the database
//-----------------------------------
$db = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());


//----------------------------------------------
// Get the ID from the URL, or supply a default.
//----------------------------------------------
$id = (isset($_GET["id"])) ? $_GET["id"] : "1";
//-----------------------------------
// This is display the image...
//-----------------------------------
$query2 = "SELECT images FROM Image WHERE id='$id'";
$result2 = mysql_query($query2) or die(mysql_error());
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<? echo($query2);?>
Put the image here get it from the url
<input type="button" onClick="window.close()" value="Close Window">
</body>
</html>

If I put query2 in the echo statement then it displays the actual select statement

If I put result2 in the echo statement then it displays resource ID#3, but I think my problem is my select statement, can someone help please?

As5a5sIn5
09-27-2004, 03:21 AM
First off... are your echoing the query not the result :p

Secondly, you need to run a while statement to pull the stuff u need out the DB


*Edit Well you see ur first problem, try running a while statement and make sure you put the html stuff to turn the links from the DB into actual pics, thats what ur doing rite?

dniwebdesign
09-27-2004, 03:22 AM
Please place your code in [ php ] and [ /php ] tags... (without the spaces)... Then we can read the code better and easier and might be able to help you.

Nightfire
09-27-2004, 11:23 AM
<?php
//-----------------------------------
//this is the connection string to connect to the database
//-----------------------------------
$db = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());


//----------------------------------------------
// Get the ID from the URL, or supply a default.
//----------------------------------------------
$id = (isset($_GET["id"])) ? $_GET["id"] : "1";
//-----------------------------------
// This is display the image...
//-----------------------------------
$query2 = "SELECT images FROM Image WHERE id='$id'";
$result2 = mysql_query($query2) or die(mysql_error());

$image = mysql_fetch_assoc($result2);
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $image['images'];?>
Put the image here get it from the url
<input type="button" onClick="window.close()" value="Close Window">
</body>
</html>

Should work

paulsiew
09-27-2004, 06:48 PM
<?php
//-----------------------------------
//this is the connection string to connect to the database
//-----------------------------------
$db = mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("table") or die(mysql_error());


//----------------------------------------------
// Get the ID from the URL, or supply a default.
//----------------------------------------------
$id = (isset($_GET["id"])) ? $_GET["id"] : "1";
//-----------------------------------
// This is display the image...
//-----------------------------------
$query2 = "SELECT images FROM Image WHERE id='$id'";
$result2 = mysql_query($query2) or die(mysql_error());

$image = mysql_fetch_assoc($result2);
?>

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php echo $image['images'];?>
Put the image here get it from the url
<input type="button" onClick="window.close()" value="Close Window">
</body>
</html>

Should work

Yup! This should works.


Paul

We Make IT Simple! (http://www.niveux.net)
Email: paul@niveux.net



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum