954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

loading images from MySQL database

I am having problems loading images from my database. I think it's something with the variable...i am new to PHP and have a project i need to finish by Tuesday. Your help is appreciated.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SMRTCV</title>
    <meta name="description" content="Demo page for FlowGallery jQuery plugin - image gallery based on cover flow effect." />
    <meta name="author" content="Boris Searles">

    <link rel="stylesheet" href="css/skin.css" type="text/css" media="screen" charset="utf-8" />

    <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="js/jquery.easing.1.3.js" type="text/javascript"></script>
    <script src="js/jquery.flowgallery.min.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
      $(function() {
        $('#gallery').flowGallery({
          easing: 'easeOutCubic',
          imagePadding: 6,
          thumbWidth: 120
        });
      });
    </script>
  </head>
  <body>

    <body>
		<div id = "wrapper">
			<div id = "header"><a href-"http://www.mysphinx.net"><img src = "http://www.obinnaizeogu.com/mysphinx/images/SMRTCV_LOGOTYPE.gif" alt = "SMRTCV" width="107" height="18" border="0"/></a>
			</div>
				<div id = "menu">
					<ul>
						<li>Refine</li>
						<li>Create a Spec</li>
						<li>Mail</li>
						<li>Casting Board</li>
					</ul
				</div>
					<div>
						<p class="name">Sign In</p>
						<p class="name">Forgot Password?</p>
					</div>
 						<div class="search">
							<form id="searchform" action="http://www.mysphinx.net/" method="get">
								<fieldset>
									<div class="form">
										<input id="s" class="field" type="text" name="s" value="">
											<input id="searchsubmit" class="submit" type="submit" value="">
									</div>
								</fieldset>
							</form>	
 						</div>
 				
 				
 				
 				
 				
 <?php

 
		
		$sql = "SELECT models_ID, profile_image, photo1, photo2, photo3\n"
    		. "FROM photos_models\n"
    		. "WHERE profile_image LIKE \'SigridAgren.jpg\' LIMIT 0, 30 ";    
    	
    	$img_src = $row['1'];

    	
    	
    	
    	
?>

            				
        				

      <div id="content">
        
        <ul class="gal" id="gallery">
          <li><img src="http://www.obinnaizeogu.com/mysphinx/models/women/smart_gallery/lightbox/updated-images-04-26-11/<?=$img_src?>" alt="Sigrid Agren" title="Sigrid Agren" /></li>

        </ul>
       
      </div><!-- #content -->
    </div><!-- #wrapper -->

  </body>
</html>


[/CODE]

DeIntegro
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

im not sure what you are tryin to do with the code...but your sql query is not getting executed any where....

$sql = "select * from something";
$res = mysql_query($sql);
$row = mysql_fetch_row($res);
$img_src = $row[1];

you code should be something like this ...

dos_killer
Junior Poster in Training
50 posts since Dec 2010
Reputation Points: 15
Solved Threads: 4
 

I get this error when I load the page:


Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in

DeIntegro
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

that means either you are passing the wrong parameter to the function or your query is wrong or query is not returning any rows...

i suggest you read up an online tutorial on this first and then proceed with your project ...

dos_killer
Junior Poster in Training
50 posts since Dec 2010
Reputation Points: 15
Solved Threads: 4
 

When you get following error:
"Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in "
You should echo/print your query and try execute it on your database using your favorite mysql client tool be it phpmyadmin or heidisql and see if it brings the result?
Mostly if connection is proper it will be query problem. so just make sure that.

Following posts may be helpful to you:
http://blogs.digitss.com/php/reading-mssql-blog-column-data-with-php/
http://blogs.digitss.com/database/mysql/heidisql-5-1-good-has-got-better/

dharmavir
Newbie Poster
1 post since May 2011
Reputation Points: 10
Solved Threads: 0
 

that means either you are passing the wrong parameter to the function or your query is wrong or query is not returning any rows...

i suggest you read up an online tutorial on this first and then proceed with your project ...


I got to figure it out, but it's only loading 1 field from database and not the entire row

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SMRTCV</title>
    <meta name="description" content="Demo page for FlowGallery jQuery plugin - image gallery based on cover flow effect." />
    <meta name="author" content="Boris Searles">

    <link rel="stylesheet" href="css/skin.css" type="text/css" media="screen" charset="utf-8" />

    <script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
    <script src="js/jquery.easing.1.3.js" type="text/javascript"></script>
    <script src="js/jquery.flowgallery.min.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
      $(function() {
        $('#gallery').flowGallery({
          easing: 'easeOutCubic',
          imagePadding: 6,
          thumbWidth: 120
        });
      });
    </script>
  </head>
  <body>

    <body>
		<div id = "wrapper">
			<div id = "header"><a href-"http://www.mysphinx.net"><img src = "http://www.obinnaizeogu.com/mysphinx/images/SMRTCV_LOGOTYPE.gif" alt = "SMRTCV" width="107" height="18" border="0"/></a>
			</div>
				<div id = "menu">
					<ul>
						<li>Refine</li>
						<li>Create a Spec</li>
						<li>Mail</li>
						<li>Casting Board</li>
					</ul
				</div>
					<div>
						<p class="name">Sign In</p>
						<p class="name">Forgot Password?</p>
					</div>
 						<div class="search">
							<form id="searchform" action="http://www.mysphinx.net/" method="get">
								<fieldset>
									<div class="form">
										<input id="s" class="field" type="text" name="s" value="">
											<input id="searchsubmit" class="submit" type="submit" value="">
									</div>
								</fieldset>
							</form>	
 						</div>
 				
 				
 				
 				
 				
 <?php

 
		
		$result = mysql_query($sql = "SELECT models_ID, profile_image, photo1, photo2, photo3\n"
    		. "FROM photos_models\n"
    		. "WHERE models_ID = '15' ");
    		
		if (!$result) {
   		 echo 'Could not run query: ' . mysql_error();
    	exit;
		}
		
		$row = mysql_fetch_row($result);


   

    	
    	
    	
    	
?>

            				
        				

      <div id="content">
        
        <ul class="gal" id="gallery">
          <li><img src="http://www.obinnaizeogu.com/mysphinx/models/women/smart_gallery/lightbox/updated-images-04-26-11/<?=$row[1]?>" alt="Sigrid Agren" title="Sigrid Agren" /></li>

        </ul>
       
      </div><!-- #content -->
    </div><!-- #wrapper -->

  </body>
</html>
DeIntegro
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

Can I ask, why are you using the 'new line' in your sql query?

Nimerion
Newbie Poster
8 posts since Feb 2011
Reputation Points: 10
Solved Threads: 0
 
Can I ask, why are you using the 'new line' in your sql query?


I copy pasted from phpMyAdmin create php code

DeIntegro
Newbie Poster
15 posts since Aug 2010
Reputation Points: 10
Solved Threads: 0
 

DeIntegro,

The reason you're only getting one row is because you're querying for one row. You need to query an array of rows.

$row = mysql_fetch_<strong>row</strong>($result);


should be

$row = mysql_fetch_<strong>array</strong>($result);
floatingDivs
Junior Poster
198 posts since Aug 2010
Reputation Points: 32
Solved Threads: 34
 

DeIntegro,

The reason you're only getting one row is because you're querying for one row. You need to query an array of rows.

$row = mysql_fetch_<strong>row</strong>($result);

should be

$row = mysql_fetch_<strong>array</strong>($result);

This is not true.
Both functions fetch one row from the query and store it in an array.
The only difference between them is how the array in which the row is stored is constructed:
mysql_fetch_row returns an enumerated array (eg. {[0] => a, [1] => b})
mysql_fetch_assoc returns an associative array (eg. {[x] => a, [y] => b})
mysql_fetch_array returns an array containing both of these (eg. {[0] => a, [x] => a, [1] => b, [y] => b}).

To get multiple rows from your query simply call mysql_fetch_array/assoc/row again and again until it returns false:

while($row = mysql_fetch_array($sql)){
    // Do something with the row
}
Insensus
Junior Poster
112 posts since Mar 2011
Reputation Points: 70
Solved Threads: 46
 
while($row=mysql_fetch_row($result))
{

}
dos_killer
Junior Poster in Training
50 posts since Dec 2010
Reputation Points: 15
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: