Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 9th, 2005, 10:13 AM   #1
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
Would this work?

Just curious if this should work.
$mshirt = "select item_image from store_items where item_title = mshirt";

$display_table .= "
<td><a href=\"mshirt.php\"><img src=\"$mshirt\" /></a></td>

Just a piece of the code, but I think you get the idea. item_image is a path to where the pics are stored.
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old May 9th, 2005, 10:48 AM   #2
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
no it would not work it would just put the string in there.
Berto is offline   Reply With Quote
Old May 9th, 2005, 10:50 AM   #3
dmorales
Programmer
 
Join Date: Feb 2005
Posts: 74
Rep Power: 4 dmorales is on a distinguished road
so how would get the path to the file to work in the img tag?
__________________
Lorem ipsum dolor sit amet...
dmorales is offline   Reply With Quote
Old May 9th, 2005, 11:37 AM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Quote:
no it would not work it would just put the string in there.
it wouldn't put the string into it. it would put the result from the query into the img tag. which would look like "result index 0" or something like that.

if $item_image held the path you could do it.

this is how i would write it.

Note: This is code for a postgresql db, but you are probally using mysql.

[PHP]
//connect to the db
$pgConnection = pg_connect("dbname=users user=me password=foobar");
$sql = "select item_image from store_items where item_title = mshirt";

//then with your connection to the db, execute the query above:
$res = pg_query($pgConnection, $sql);

//now check to see if the query returned anything.
if (pg_num_rows($res) <> 0)
{
//now we can loop and creat output table.
for ($x=0; $x<pg_num_rows($res); $x++)
{
$data = pg_fetch_object($res, $x);
$display_table .= "
<td><a href=\"mshirt.php\"><img src=\"" . $data->item_image . "\" /></a></td>";
}
}
else
{
//error message:
?>
<center>
<b>There are no shirt images.</b>
</center>
<?PHP
}
[/PHP]

anyways, if you are using mysql, you'll have to do a little research on what functions you'd need to use.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!

Last edited by Pizentios; May 9th, 2005 at 11:39 AM.
Pizentios is offline   Reply With Quote
Old May 10th, 2005, 3:16 AM   #5
Berto
Programming Guru
 
Join Date: Aug 2004
Posts: 1,022
Rep Power: 6 Berto is on a distinguished road
Send a message via AIM to Berto Send a message via MSN to Berto
yes but he isnt using sql at the time Piz, so it would just print the string into where he had the thingy there :p.

there was no sql mentioned thank you

http://www.berto.org/test123.php

[php]

<?php

$mshirt = "select item_image from store_items where item_title = mshirt";

$display_table .= "<td><a href=\"mshirt.php\"><img src=\"" . $mshirt . " /></a></td>";

echo $display_table;

?>

[/php]

edited the code slightly.

Last edited by Berto; May 10th, 2005 at 3:25 AM.
Berto is offline   Reply With Quote
Old May 10th, 2005, 3:49 AM   #6
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
You probably want something along the lines of this. Assuming that what you're trying to do is a basic MySQL query, and yes Berto no SQL was mentioned but since he said "item_image is a path to where the pics are stored" and that sure looks like SQL to me i can only assume.

<?php
    mysql_connect("localhost", "root", "");
    mysql_select_db("database name");
    $mshirt = mysql_query("select item_image from store_items where item_title= mshirt");

    while($row = mysql_fetch_array($mshirt))
        echo "<td><a href=\"mshirt.php\"><img src=\"{$row["mshirt"]}\"/></a></td>";i

    mysql_close();
?>
__________________

tempest is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:03 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC