jpeg files and mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
massiveone
Forum Commoner
Posts: 29
Joined: Tue Jun 18, 2002 4:39 pm
Location: Canada
Contact:

jpeg files and mysql

Post by massiveone »

Quick question I am learning php+mysql so please forgive this newb question.

if i have a mysql database with 2 fields as follows

imagename,imagedescription

how do i have it display the image and the description side by side in a table if possible so it looks neet.

example mysql data

/images/1.jpg , picture of a boat
/images/2.jpg , picture of a car

Thanks
DmitriyPlakhotnik
Forum Newbie
Posts: 1
Joined: Thu Nov 07, 2002 5:10 am

Post by DmitriyPlakhotnik »

<?
mysql_connect("localhost", "root", "");
mysql_select_db("test");

$query = "SELECT * FROM mytable";
$result = MYSQL_QUERY($query);
$number = MYSQL_NUMROWS($result);

$i=0;

if ($number == 0) { echo "<CENTER> Empty base.</CENTER>";}
ELSEIF ($number > 0)
{
WHILE ($i < $number){
$img_path = mysql_result($result,$i,"img_path");
$text = mysql_result($result,$i,"text");
?>
<TR>

<TD>
<img src="<? echo $img_path; ?>
</TD>

<TD>
<? echo $text; ?>
</TD>
</TR>

<?
$i++;
}
}
?>

</TABLE>
</BODY>

Sincerely,
Dmitriy S.Plakhotnik
Programmer of Rapid Internet Development Department
Alar Information Technologies
http://www.alarit.com
User avatar
massiveone
Forum Commoner
Posts: 29
Joined: Tue Jun 18, 2002 4:39 pm
Location: Canada
Contact:

thanks , what about this one

Post by massiveone »

Thanks for the previous script, can anyone tell me where i am going wrong with this one? (it displays nothing)

<?
mysql_connect("localhost", "mylogin", "mypass");
mysql_select_db("mydb");
$result = mysql_query("SELECT * FROM mytable",$db);
printf("Image Name: %s<br>\n", mysql_result($result,"imagename"));
printf("Product Description: %s<br>\n", mysql_result($result,"imagedescription"));
echo "<img src=$imagename><br>\n";

?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

try

Code: Select all

&lt;?php
mysql_connect("localhost", "mylogin", "mypass") or die(mysql_error());
mysql_select_db("mydb") or die(mysql_error());
$query = 'SELECT * FROM mytable';
$result = mysql_query($query,$db) or die($query.' :'.mysql_error());
$row = mysql_fetch_assoc($query) or die ('no record');
printf("Image Name: %s&lt;br&gt;\n", $row&#1111;'imagename']);
printf("Product Description: %s&lt;br&gt;\n", $row&#1111;'imagedescription']);
echo '&lt;img src="',$row&#1111;'imagename'], '"&gt;&lt;br&gt;\n';
?&gt;
Post Reply