<? include "header.php" ?>
<?
$hostname = "www.www.com"; // Usually localhost.
$username = "fluffy"; // If you have no username, leave this space empty.
$password = "fluffy"; // The same applies here.
$usertable = "Prezime"; // This is the table you made.
$dbName = "ifluffy"; // This is the main database you connect to.
MYSQL_CONNECT($hostname, $username, $password) OR DIE("Unable to connect to database");
@mysql_select_db( "$dbName") or die( "Unable to select database");
?>
<?
//error message (not found message)
$XX = "No Record Found";
$query = mysql_query("SELECT * FROM $usertable WHERE surname LIKE '%$search%' LIMIT 0, 1 ") or die (mysql_errno() . ' ' . mysql_error());
while ($row = mysql_fetch_array($query))
{
echo('<b>Surname:</b> ' . $rowї"surname"] . '<br>');
echo('<b>Place:</b> ' . $rowї"place"] . '<br>');
echo('<b>Region:</b> ' . $rowї"region_country"] . '<br>');
echo('<b>Family Saint:</b> ' . $rowї"family_saint "] . '<br>');
echo('<b>Information:</b> ' . $rowї"information"] . '<br>');
echo('<br>');
}
//below this is the function for no record!!
if (!mysql_num_rows($query))
{
print ("$XX");
}
//end
?>
<? include "footer.php" ?>
As you can see I have a table with in which this form is searching. Now I wish to add pictures to this database to be displayed in the search results. How can I do this?
You could add a field (varchar perhaps) where you store links to images in the form: "images/1.gif", "images/2.gif" as example, for each of the users. When retrieving the data, you get the above info, and you can printout an img src-tag.
Personally, I dont like storing images as binary in the database as I'm not yet over-convinced that it's any good (exceptions in some areas).
If you want your users to store their own images, you use a similar way, but store the users images in one folder, the image-name in the database, adding some checks if the image being uploaded is not allready available.
Yes, I already saw some galleries that use this storing way but I am afraid my dbase will go nuts since I had this before.
I think the solution you mentioned at first I what I need to do. BTW, is there something about the code that needs to be altered since it was written for PHP 3?
Well, except from that you dont need to declare $XX ("No Record Found" can be put into the no-rows-returned area directly), you should read up on 'Passing Variables'.
Take a peek at the last link in my signatur...
<?php
function db_error($type) {
echo "<b>database $type failed:</b><br><br>error number: " . mysql_errno() . "<br>" . mysql_error();
}
include 'header.php';
$hostname = 'www.www.com'; // Usually localhost.
$username = 'fluffy'; // If you have no username, leave this space empty.
$password = 'fluffy'; // The same applies here.
$usertable = 'Prezime'; // This is the table you made.
$dbName = 'ifluffy'; // This is the main database you connect to.
mysql_connect($hostname, $username, $password) or die (db_error('connection'));
mysql_select_db( "$dbName") or die (db_error('selection'));
$query = mysql_query("SELECT * FROM $usertable WHERE surname LIKE '%$search%' LIMIT 0, 1 ") or die (db_error('query'));
if (!mysql_num_rows($query)) {
echo 'No Record Found';
} else {
while ($row = mysql_fetch_array($query))
{
echo('<b>Surname:</b> ' . $rowї"surname"] . '<br>');
echo('<b>Place:</b> ' . $rowї"place"] . '<br>');
echo('<b>Region:</b> ' . $rowї"region_country"] . '<br>');
echo('<b>Family Saint:</b> ' . $rowї"family_saint "] . '<br>');
echo('<b>Information:</b> ' . $rowї"information"] . '<br>');
echo('<br>');
}
}
include 'footer.php';
?>
The if-then-else 'No Record Found' is allright. Still, the more vital part you should look into is viewtopic.php?t=511.
To continue, you are using $search, as it is sendt from the user directly into the database (presuming). That might be a problem, so take a look at the links I posted earlier.