473,387 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

MySQL link, PLEASE help!?!?

After googling and reading my eyeballs out I am no closer to a solution, I
hope someone will be kind enough to help.

I have a simple MySQL inventory db where the relevant fields are ID (pri,
auto-inc), image (med-blob), description and price. All I want to be able
to do is to store a link to the image in the image field, and have that
image be shown on the returning page. I just can't seem to get it to work
right. It is a 2000 row db, and each item has an image.

Relevant code on the inventory page (I'm sorry if it wraps funny):

$result = @mysql_query("SELECT ID, image, description, price FROM table");

echo ("<table border='0' width='90%' align=center>");

while ( $row = mysql_fetch_array($result, MYSQL_ASSOC) ) {

echo("<tr><td width='10%'><a
href=\"showPhoto.php?ID={$row[ID]}\">Photo</a> </td>" .

"<td width='70%'>" . $row[description] . "</td>" .
"<td width='20%'align=right>" . $row[price] . "</td></tr> ");
}
echo "</table>"; }

---Everything displays correctly and when you hover over the photo link
you see the URL "showPhoto.php?ID=1"

In the returning (showPhoto) page, I have the following:

//connect stuff
$result = @mysql_query("SELECT image FROM table"); while ( $row =
mysql_fetch_array($result, MYSQL_ASSOC) ) {

echo $row["image"]; }

But on the return (showPhoto) page I get all 2000 photos loading! I don't
know how to tell the array that I only want to return the photo pertaining
to that row's ID. I have tried MANY other alternatives but I either get no
data on the return page or all 2000 photos.

The entry in the image field of the db is <img src="/path/image_name.jpg">

Will some kind soul PLEASE look at this code and tell me how to do this? I
will do your dishes for life!

Thank you,

Will
Jul 17 '05 #1
9 1844
Will Clifton wrote:
In the returning (showPhoto) page, I have the following:

//connect stuff
$result = @mysql_query("SELECT image FROM table"); while ( $row =
mysql_fetch_array($result, MYSQL_ASSOC) ) {
echo $row["image"]; }

But on the return (showPhoto) page I get all 2000 photos loading! I don't
know how to tell the array that I only want to return the photo pertaining
to that row's ID. I have tried MANY other alternatives but I either get no
data on the return page or all 2000 photos.


Gorsh, Will... isn't that what your code is _asking_ PHP to do? It looks to
me like the code quoted above is specifically querying the entire table and
generating every single image!

It seems to me that your code should:

$result = mysql_query("SELECT image FROM table WHERE id=$id")
....

Jul 17 '05 #2
On Tue, 23 Nov 2004 09:40:17 -0500, Sundial Services wrote:
It seems to me that your code should:

$result = mysql_query("SELECT image FROM table WHERE id=$id")
...


THANK YOU for reading, however that's precisely what I've been trying to
do. I even had that exact same code at one point and it returns a MySQL
syntax error where I put the variable in the query. Sigh. Still lost, any
other ideas?

Will

Jul 17 '05 #3
Will Clifton wrote (in part):
[snip]
href=\"showPhoto.php?ID={$row[ID]}\">Photo</a> </td>" . [snip]
//connect stuff
$result = @mysql_query("SELECT image FROM table"); while ( $row =
mysql_fetch_array($result, MYSQL_ASSOC) ) {

echo $row["image"]; }


You are passing the ID field, but not using it, so you are getting all
of your pictures returned. Use:

$result = @mysql_query("select image from table where id='" .
$_GET['id'] . "'");

Of course you really should do some sanity checking on what's in
$_GET['id'] before using it in your query.

Ken Robinson

Jul 17 '05 #4

showphoto.php is doing exactly what you asked it to do: write out one
<img> tag for every row in your database table.

The first of many solutions... Your query should only fetch the one row
that corresponds to the ID that your user selects on the inventory
page, thus:

// get the ID passed from inventory page...
$lngID = $_GET[ "ID" ];

// fetch one row: the <img> text for that ID only...
$result = @mysql_query( "SELECT image FROM table WHERE ID=$lngID" );

// get the result into an array...
$row = mysql_fetch_array( $result, MYSQL_ASSOC );

echo $row[ "image" ];

I'll courier my dirty dishes over shortly. Please can I have them back
in time for tea?

---
Steve

Jul 17 '05 #5

Will Clifton wrote:
On Tue, 23 Nov 2004 09:40:17 -0500, Sundial Services wrote:
It seems to me that your code should:

$result = mysql_query("SELECT image FROM table WHERE id=$id")
...
THANK YOU for reading, however that's precisely what I've been trying

to do. I even had that exact same code at one point and it returns a MySQL syntax error where I put the variable in the query. Sigh. Still lost, any other ideas?

Please post the code that gives the error and the error messsage.

Ken

Jul 17 '05 #6
On Tue, 23 Nov 2004 07:30:17 -0800, Ken Robinson wrote:
THANK YOU for reading, however that's precisely what I've been trying

to
do. I even had that exact same code at one point and it returns a

MySQL
syntax error where I put the variable in the query. Sigh. Still lost,

any
other ideas?

Please post the code that gives the error and the error messsage.


Ken,

Your other post did the trick, it was exactly what I couldn't figure out
how to do. You were very kind to an obvious newbie.

Will

Jul 17 '05 #7
On Tue, 23 Nov 2004 07:04:15 -0800, Steve wrote:

showphoto.php is doing exactly what you asked it to do: write out one
<img> tag for every row in your database table.

The first of many solutions... I'll courier my dirty dishes over shortly. Please can I have them back
in time for tea?


Steve,

Thank you very much, I used your solution and Ken's solution and they both
worked wonderfully. However, as I live in the central part of the US we
might have to overnight your dishes!

Will

Jul 17 '05 #8
Will Clifton wrote:
In the returning (showPhoto) page, I have the following:

//connect stuff
$result = @mysql_query("SELECT image FROM table"); while ( $row =
mysql_fetch_array($result, MYSQL_ASSOC) ) {

echo $row["image"]; }


You don't want a loop here; you want to display a single image.

/* validate $_GET['id'] */
$id = (int)$_GET['id'];

/* fetch *one* image from the database */
$sql = "select image from table where id=" . $id;
$result = mysql_query($sql) or die('Error querying the database.');

$row = mysql_fetch_array($result, MYSQL_ASSOC);
echo $row['image'];

--
Mail sent to my "From:" address is publicly readable at http://www.dodgeit.com/
== ** ## !! !! ## ** ==
TEXT-ONLY mail to the complete "Reply-To:" address ("My Name" <my@address>) may
bypass the spam filter. I will answer all pertinent mails from a valid address.
Jul 17 '05 #9
I noticed that Message-ID: <pa****************************@cox.net> from
Will Clifton contained the following:
I have a simple MySQL inventory db where the relevant fields are ID (pri,
auto-inc), image (med-blob), description and price.


A couple of asides here since you main q has been answered.

Why is the image field set to med-blob if it is just a short text
string?

Are you really storing <img src="/path/image_name.jpg"> in this field?
(assuming this is a relative path)

Personally I'd simply store the image name, allowing whatever script
calls the data to prepend the path and add the html. More flexibility
this way.

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sinasalek | last post by:
i have a problem with MySQL 4.1.x and UTF8. in version 4.0, i'm using html forms with utf8 charset for inserting unicode strings. but in version 4.1.x it is not working! if i change the charset of...
1
by: ADale | last post by:
Hi all, I hope someone here may be able to help me out! I have already serached the net for info to sort my problem but I could not find anything that solved it. Now, go easy on me, I am a...
2
by: shoa | last post by:
Hello I have an Access database that is used for a station computer. Now I want to update this database for a small network for about 4 computers (to share this database). I know that I can link...
2
by: shoa | last post by:
Hello I can link MS Access (front) with MySQL (back end). However, when I add a new record, the previous added record is signed as Deleted record (view in Access) even I can view this record in...
0
by: Chris Ochs | last post by:
Not to change the topic too much, but as a new postgresql user I have to say that it takes quite a bit of time to find even the basic postgresql tools/interfaces/etc that are available. The main...
0
by: edward_sanders | last post by:
Hi, This is a newbie question. I am using a text for learning php/mysql. I am using PHP 5.2.x and mysql 5. The example is that of a mysql database of jokes. Before we get to joins there is a...
8
by: deko | last post by:
I've just loaded phpMyAdmin on a Debian Linux server with Apache2, MySql5 and PHP5. myserver # dpkg -l | grep php ii libapache-mod-php5 5.2.0-8+etch4 ii libapache2-mod-php4 4.4.4-8+etch2 ii...
39
by: alex | last post by:
I've converted a latin1 database I have to utf8. The process has been: # mysqldump -u root -p --default-character-set=latin1 -c --insert-ignore --skip-set-charset mydb mydb.sql # iconv -f...
0
by: Alan Silver | last post by:
Hello, I'm a newbie at PHP and MySql, although I have wads of experience of ASP, ASP.NET, SQL Server, etc. I have just installed PHP 5.2.3 on a server (Windows Server 2003), as well as MySql...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.