Hi there, i've a database created in MySQL, and many doubs are comming coz i'm a beginner, hope you can all help me: 1. How do i show the data in the database fields? I know that i have to connect to server 1st but cant create the <table> tag after. 2. How can i create a htm form thats deals text and image (file) fields and post them on the db? I have the text form working. but when i add the file upload on the php script nothing works. Hope to recxeive an answer soon coz its very urgent regards and many thanks to all
You have to be more specific. A database structure would also be helpful. And which fields you want to display... Here a very basic example $query = mysql_query("SELECT * FROM tabe WHERE foo = 'bar'") OR die( mysql_error() ); $data = mysql_fetch_array($query); echo $data['foo']; PHP: As for the uploader, I would not store the images in the database, I would upload them to a separate folder and only save the filename in the database. It would help if you could post your code so far.
Thanks Nico for answer it: I have as fields: data name client description image (jpg file) please ask more doubts that i will aswer fast
Okay, so this are the fields. And how do we know which row you want to pull? Or do you want to pull all rows and show them in a table?
I would like to pull all the rows. Each time i add a record, he will show at fist. for example in the database: data inserted in jan 2006 data inserted in fev 2006 data inserted in may 2006 he will show in this order may fev jan
We need an ID or time field in order to order the rows like you wish. Here an example for the unordered table. (You have to edit the highlighted strings) <?php $con = mysql_connect('localhost', 'username', 'password'); mysql_select_db('databasename', $con); $query = mysql_query("SELECT * FROM tablename") OR die( mysql_error() ); ?> <table border="1" width="80%"> <tr> <td>data</td> <td>name</td> <td>client</td> <td>description</td> <td>image</td> </tr> <?php while ($row = mysql_fetch_array($query)) { ?> <tr> <td><?php echo $row['data']; ?></td> <td><?php echo $row['name']; ?></td> <td><?php echo $row['client']; ?></td> <td><?php echo $row['description']; ?></td> <td><?php echo $row['image']; ?></td> </tr> <?php } ?> </table> Code (markup): Does every row have a unique ID or something that would allow us to order it like you want to?
Hi, I dindt have any id field. I've created one Id field but what must be the type of it? Thanks for everything
Nico, thanks very much! Its works perfectly. Now my only problem is the image part. The image on the data base is defined as blob. The images are stored in the images directory on the server. My question is how can i "load" the image on the page? I read that if the image file is called 01.jpg and if i upload her directly in the MySQL admin how can i show her?
If you have the image name in the DB, then do following. <img src="/path/to/folder/<?php echo $row['image']; ?>" /> Code (markup):
the image field on the database is a blob field. If i only have the name of the file, what type must be? txt?
Hm, wait, are the images stored in a folder or in the database? If it's stored in the database, then you can load them via an external file like this. <?php $query = mysql_query("SELECT * FROM images WHERE name = '". mysql_real_escape_string($_GET['name']) ."'"); $image = mysql_fetch_array($query); header('Content-type: image/jpg'); echo $image['content']; ?> Code (markup): And load it like this <img src="image.php?name=<?php echo $name; ?>" /> Code (markup):
Hi there, What is the most easy? The images stored in database or in a directory? The last post did not work with the images stored in the database, and it turned "error" in the last part of the loader no image icon + " />
I personally would say that saving the image in a directory is the easiest way to go. Less messing about with file headers, less files and in all likelihood faster as well.
And how do i do that? What type should be the image field on the database? txt? I have the images stored in a directory how do i display them with the rest of the records?
Varchar (100) for example. As I said earlier, like this if the images are in a directory, and the image names in the database. <img src="/path/to/folder/<?php echo $row['image']; ?>" /> Code (markup):
$query = mysql_query("SELECT * FROM prpa") OR die( mysql_error() ); ?> <?php while ($row = mysql_fetch_array($query)) { ?> <tr> <td width="115" rowspan="4" valign="top"><div align="center"><font color="#000000" size="2" face="Arial, Helvetica, sans-serif"><?php echo $row['data']; ?></font></div></td> <td width="275" height="42" bgcolor="#CC0000"><font color="#FFFFFF" size="+2" face="Arial, Helvetica, sans-serif"> <?php echo $row['nome']; ?></font></td> <td width="310" height="40" bgcolor="#FFFFFF"><font size="5" face="Times New Roman, Times, serif"><em> <?php echo $row['cliente']; ?></em></font></td> <td width="300" height="58" rowspan="2" valign="top" bgcolor="#FFFFFF"><font color="#000000" size="1" face="Arial, Helvetica, sans-serif"> <?php echo $row['desc']; ?></font></td> </tr> <tr> <td width="275" height="18" bgcolor="#666666"><font color="#FFFFFF" size="1" face="Arial, Helvetica, sans-serif"> <?php echo $row['url']; ?></font></td> <td width="310" height="18" bgcolor="#FFFFFF"> </td> </tr> <tr> <td colspan="3"> <?php $query = mysql_query("SELECT * FROM img WHERE name = '". mysql_real_escape_string($_GET['name']) ."'"); $image = mysql_fetch_array($query); echo $image['content']; ?> <img src="/img/<?php echo $row['img']; ?>" /></td> </tr> <tr> <td height="29" colspan="3" align="right"><img src="images/linha.gif" width="885" height="29"></td> </tr> <?php } ?>
$query = mysql_query("SELECT * FROM prpa") OR die( mysql_error() ); $query1 = mysql_query("SELECT * FROM img WHERE name = '". mysql_real_escape_string($_GET['name']) ."'"); $image = mysql_fetch_array($query1); <- this is line 64 echo $image['content']; ?> ERROR: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/www/final.php on line 64