Page 1 of 1
jpeg files and mysql
Posted: Wed Nov 06, 2002 10:39 am
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
Posted: Thu Nov 07, 2002 5:10 am
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
thanks , what about this one
Posted: Mon Nov 11, 2002 10:18 am
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";
?>
Posted: Mon Nov 11, 2002 3:56 pm
by volka
try
Code: Select all
<?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<br>\n", $rowї'imagename']);
printf("Product Description: %s<br>\n", $rowї'imagedescription']);
echo '<img src="',$rowї'imagename'], '"><br>\n';
?>