Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | PHP - Trying to retrieve a value from Mysql db

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

PHP - Trying to retrieve a value from Mysql db
Reply
 
Thread Tools
Old 26-03-2009, 09:06   #1
funkyCable
Inactive
 
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05 TV XL services 2MB BROADBRAND UNLIMITED TALK PACKAGE V+ Service (Since 18
Posts: 1,195
funkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nice
PHP - Trying to retrieve a value from Mysql db

Hi

I have a table in mysql called tbl_picture_link which stores a url string to some pictures not I would like to retieve the string and place <img> around it.

This is the function I have
PHP Code:
function get_image($image_id){
    
//finds and displays the selected image 
        
global $connection
        
$query "SELECT     * 
                  FROM tbl_picture_link
                  where picture_link_id = 
{$image_id}  
                  LIMIT 1"

        
$picture_set mysql_query($query$connection); 
        
confirm_query($picture_set); 
        echo 
"<img scr=\"" $picture_set['picture_link_href'] . "\">" $query."<br />"
    } 
I'm not getting an errors with connection to my db all that its echoed is an img place holder the $query value which is a value sql statement because I copied the output and ran it in phpmyadmin and it returned some the result I was expecting.

Any ideas what could be wrong.
funkyCable is offline   Reply With Quote
Advertisement
Old 26-03-2009, 09:25   #2
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: PHP - Trying to retrieve a value from Mysql db

You're missing out a step. Even though you have one row, you still need to fetch the result, not just link to the query. So something like this:

PHP Code:
function get_image($image_id){
    
//finds and displays the selected image 
        
global $connection
        
$query "SELECT     * 
                  FROM tbl_picture_link
                  where picture_link_id = 
{$image_id}  
                  LIMIT 1"
;

        
//get query result 
        
$query_result mysql_query($query$connection);
        
//fetch result as an array
        
$picture_set mysql_fetch_array($query_result);
 
        
confirm_query($picture_set); 
        echo 
"<img scr=\"" $picture_set['picture_link_href'] . "\">" $query."<br />"
    } 
Note as you only have one row returned, you only call the mysql_fetch_array once. If you wanted to do more than one row, you need to do a while loop or something to keep calling mysql_fetch_array and get the new rows.
punky is offline   Reply With Quote
Old 26-03-2009, 09:26   #3
bmxbandit
Inactive
 
bmxbandit's Avatar
 
Join Date: Oct 2004
Location: Nottingham
Posts: 1,405
bmxbandit has reached the bronze age
bmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze agebmxbandit has reached the bronze age
Re: PHP - Trying to retrieve a value from Mysql db

This won't help...
Quote:
<img scr
I'm a little confused as to the problem...does $picture_set contain what you expect it to?

edit: heh, ok. what he said ^^^
bmxbandit is offline   Reply With Quote
Old 26-03-2009, 10:10   #4
funkyCable
Inactive
 
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05 TV XL services 2MB BROADBRAND UNLIMITED TALK PACKAGE V+ Service (Since 18
Posts: 1,195
funkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nice
Re: PHP - Trying to retrieve a value from Mysql db

oh yes now I see. Thanks its working just one more question how can I use a relative url in a img tag?

This is my web folders are constructed my root is htdocs i then have a websites folder which has another our_website folder which has all my php files under it. I then have /images/pix folder under our_website my images are displaying if I use <img src"/websites/our_website/images/familypix/image.jpeg"/> Is there a way I could shorten this to something like /images/familypix/image.jpeg

So if I ever move/rename the our_website folder it will not affect it.
funkyCable is offline   Reply With Quote
Old 26-03-2009, 10:18   #5
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: PHP - Trying to retrieve a value from Mysql db

You can, just drop the first /

like:

images/familypix/image.jpeg
punky is offline   Reply With Quote
Old 26-03-2009, 10:24   #6
funkyCable
Inactive
 
Join Date: Aug 2005
Location: Canvey Island, Essex
Services: SERVICES FROM 26/08/05 TV XL services 2MB BROADBRAND UNLIMITED TALK PACKAGE V+ Service (Since 18
Posts: 1,195
funkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nicefunkyCable is just really nice
Re: PHP - Trying to retrieve a value from Mysql db

thanks working 100%, a shiney is on its way.
funkyCable is offline   Reply With Quote
Reply

Thread Tools

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


All times are GMT. The time now is 02:10.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum