[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

fetch_row to display images

Dear Friends:

I need display pictures in 2 or 3 column with .PHP and MySQL and I would like to know if you can help me in order to modify the script below to make it:

Script
============

$conn = mysql_connect("localhost","user", "password");
mysql_select_db("db_name",$conn);

$ssql = "select * table_images ";


$rs = mysql_query($ssql);

while($myrow = mysql_fetch_array($rs))
{
print
"<table width='180' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td><div align='center'>$myrow[name]</td>
  </tr>
    <tr>
    <td><img src='images/$myrow[photo]></td>
  </tr>
</table>";
}
mysql_free_result($rs);
mysql_close($conn);

==========

Best Regard,


Willy Gonzalez
0
willygonzalez
Asked:
willygonzalez
  • 5
  • 3
  • 3
1 Solution
 
Timothy GoldenCommented:
$conn = mysql_connect("localhost","user", "password");
mysql_select_db("db_name",$conn);
$ssql = "select * table_images ";
$rs = mysql_query($ssql);
echo"<table width='180' border='0' cellspacing='0' cellpadding='0'>";
while($myrow = mysql_fetch_object($rs)){
echo"
  <tr>
    <td><div align='center'>$myrow->name</td>
  </tr>
    <tr>
    <td><img src='images/$myrow->photo'></td>
  </tr>
";
}
echo "</table>";
mysql_free_result($rs);
mysql_close($conn);
0
 
Timothy GoldenCommented:
use the last one

it will loop through the table rows createing a row for rach record
0
 
willygonzalezAuthor Commented:
Sorry but don't work. Display the follow messages:

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/roymarvi/public_html/row.php on line 26
 
Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/roymarvi/public_html/row.php on line 37
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Timothy GoldenCommented:
did you change the database connection information?
 $conn = mysql_connect("localhost","user", "password");

it would seem that the DB is not connecting.
0
 
Timothy GoldenCommented:
thanks ldbkutty
0
 
ldbkuttyCommented:
"from" word is missing in the sql query, and an associative array should be enclosed within curly braces.

<?php
$conn = mysql_connect("localhost", "user", "password") or die("Could not connect to DB: " . mysql_error());
mysql_select_db("db_name", $conn) or die("Could not select DB: " . mysql_error());

$ssql = "select * from table_images";
$rs = mysql_query($ssql) or die("Sql error: " . mysql_error());

while($myrow = mysql_fetch_array($rs))
{
print
"<table width='180' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td><div align='center'>{$myrow['name']}</td>
  </tr>
    <tr>
    <td><img src='images/{$myrow['photo']}'></td>
  </tr>
</table>";
}
mysql_free_result($rs);
mysql_close($conn);
?>
0
 
Timothy GoldenCommented:
ldbkutty  oh yea.. missed that one too....oppps
0
 
willygonzalezAuthor Commented:
This script don't show the data in columns, list in rows
0
 
ldbkuttyCommented:
<?php
$conn = mysql_connect("localhost", "user", "password") or die("Could not connect to DB: " . mysql_error());
mysql_select_db("db_name", $conn) or die("Could not select DB: " . mysql_error());

$ssql = "select * from table_images";
$rs = mysql_query($ssql) or die("Sql error: " . mysql_error());

while($myrow = mysql_fetch_array($rs))
{
print
"<table width='180' border='0' cellspacing='0' cellpadding='0'>
  <tr>
    <td><div align='center'>{$myrow['name']}</td>
    <td><img src='images/{$myrow['photo']}'></td>
  </tr>
</table>";
}
mysql_free_result($rs);
mysql_close($conn);
?>
0
 
willygonzalezAuthor Commented:
Sorry but the script don't work property, I have the images in a directory and the reference [photo_name] in a data base, I need display the images in 3 columns how follow:

images1    | images2     | images3
name1      | name2       | name3

images4    | images5     | images6
name4      | name5       | name6
0
 
ldbkuttyCommented:
Try like this (its untested but the logic should work):

<?php
$conn = mysql_connect("localhost", "user", "password") or die("Could not connect to DB: " . mysql_error());
mysql_select_db("db_name", $conn) or die("Could not select DB: " . mysql_error());

$ssql = "select * from table_images";
$rs = mysql_query($ssql) or die("Sql error: " . mysql_error());

while($myrow = mysql_fetch_array($rs))
{
    $myPhoto[] = $myrow['photo'];
    $myName[]  = $myrow['name'];
}
echo "<table width='180' border='0' cellspacing='0' cellpadding='0'>";
$i = 0;
while($i < count($myPhoto))
{
      echo "<tr>";
      for($j = 0; $j < 3; $j++)
      {
            $newVal = $i + $j;
            echo "<td align='center'>";
            echo (isset($newVal)) ? $myPhoto[$newVal] : '&nbsp;';
            echo "</td>";
      }
      echo "</tr>";
      echo "<tr>";
      for($j = 0; $j < 3; $j++)
      {
            $newVal = $i + $j;
            echo "<td align='center'>";
            echo (isset($myName[$newVal])) ? "<img src='images/{$myName[$newVal]}' />" : '&nbsp;';
            echo "</td>";
      }
      echo "</tr>";
      $i = $i + 3;
}
echo '</table>';
 
mysql_free_result($rs);
mysql_close($conn);
?>

PS: We cannot read your mind dude, you should have given the example in the beginning itself. :)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now