473,239 Members | 1,814 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,239 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 1838
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...

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.