Hi everyone
First time on this forum, hope someone can help.
I have a search engine that reads data from a mysql database and display 6 different images as a result.
The problem I’m having is, that all of the images are located in one folder, now I’m having a problem to see all files when I use my ftp program, I’ve exceeded the amount of files allowed by my host, so I am forced to split the folder by adding 26 subdirectories (A-Z) to SEArchive directory and move all images that start with “A” will be moved to http://www.mysite/SEArchive/a , the same with “B” “C” etc….
Is there a php or a function code I can add so that it will search through all 26 subdirectories using some sort of loop?
Bellow is how I display the image
<a href="javascript:show_remote('<?php echo addslashes($result['Bloom_Name']); ?>.jpg');"><img src="http://www.mysite/SEArchive/<?php echo $result['Bloom_Name'];?>.jpg" width="200" height="200" border="0" /></a></td>
search subdirectory
Moderator: General Moderators
-
skullmunky
- Forum Newbie
- Posts: 12
- Joined: Fri Apr 17, 2009 10:25 pm
Re: search subdirectory
one way would be by using the 'find' unix command, but you don't have to search. If the first letter of the filename determines which subdirectory it goes in, then just use that. maybe something like this:
Code: Select all
$f=$result['Bloom_Name'];
$subdir = substr($f,0,1);
$fullpath="http://www.mysite/SEArchive/" . $subdir . "/" . $f;
Re: search subdirectory
Hi
Thanks for your quick response, unfortunately I'm a novice and I’ve tried what you suggested, I’m sure it’s correct, my fault. can you add the code in the proper place for me.
Thanks for your quick response, unfortunately I'm a novice and I’ve tried what you suggested, I’m sure it’s correct, my fault. can you add the code in the proper place for me.
Code: Select all
<?PHP
$link = mysql_connect('localhost', 'XXXX_jdimino', 'XXXX');
if (!$link) { die('Could not connect: ' . mysql_error()); }
mysql_select_db('XXXXXX');
// Fetch total number of records
$result = mysql_query("SELECT COUNT(*) AS recordCount FROM ihsreg");
$row = mysql_fetch_assoc($result);
$recordCount = $row['recordCount'];
// Perform Search
$results = array();
if(isset($_REQUEST['search'])){
$limit = 20;
if($_GET['offset']){ $offset = $_GET['offset']; } else { $offset = 0; }
$SQL = "SELECT * FROM ihsreg ";
//$term = strtoupper(addslashes($_REQUEST['search']));
$term = strtoupper($_REQUEST['search']);
if(stristr($term,"'") && !stristr($term,"\'")){
$term = addslashes($term);
}
if($_REQUEST['radiobutton']){
switch($_REQUEST['radiobutton']){
case '1': $SQL.=" WHERE Bloom_Name LIKE \"$term\""; break;
case '2': $SQL.=" WHERE Pod_Name LIKE \"$term\""; break;
case '3': $SQL.=" WHERE Pollen_Name LIKE \"$term\""; break;
case '4': $SQL.=" WHERE Hybridiser LIKE \"$term\""; break;
case '5': $SQL.=" WHERE Origin LIKE \"$term\""; break;
case '6': $SQL.=" WHERE Grower LIKE \"$term\""; break;
case '7': $SQL.=" WHERE Color_Group LIKE \"$term\""; break;
case '8': $SQL.=" WHERE Bloom_Type LIKE \"$term\""; break;
case '9': $SQL.=" WHERE Reg_Mini LIKE \"$term\""; break;
case '10': $SQL.=" WHERE Size_Range LIKE \"$term\""; break;
case '11': $SQL.=" WHERE Propagation LIKE \"$term\""; break;
case '12': $SQL.=" WHERE Bloom_Color LIKE \"$term\""; break;
case '13': $SQL.=" WHERE Bloom_Characteristics LIKE \"$term\""; break;
case '14': $SQL.=" WHERE Leaf_Characteristics LIKE \"$term\""; break;
case '15': $SQL.=" WHERE Bush_Characteristics LIKE \"$term\""; break;
case '24': $SQL.=" WHERE Cross_Made LIKE \"$term\""; break;
case '25': $SQL.=" WHERE date LIKE \"$term\""; break;
default: $SQL.=" WHERE Bloom_Name LIKE \"$term\""; break;
} // switch
} else {
// If they didnt' select a radio button...
$SQL.=" WHERE Bloom_Name LIKE \"$term\"";
}
$result = mysql_query($SQL);
$resultCount = mysql_num_rows($result);
$SQL.= " LIMIT $offset, $limit";
$result = mysql_query($SQL);
if($resultCount > 0){
while($row = mysql_fetch_assoc($result)){
$results[$row['id']] = $row;
} // while
} // if there are results
} // if user performed a search
?>Code: Select all
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html">
<script type="text/javascript">
<!--
function show_remote(imageSrc){
//OpenWindow = window.open("index1.php?Search_box="+imageSrc.split('.')[0], "remoteWin", "resizable=1, scrollbars=1, toolbar=0, left=15, top=10, width=290, height=320");
document.location = 'index1.php?Search_box='+imageSrc.split('.')[0];
/*
OpenWindow.document.write('<img width="250" height="250" src="'+imageSrc+'"><br>');
OpenWindow.document.write('<div align="center"><strong>'+imageSrc.split('.')[0]+'</strong><br>');
OpenWindow.document.write('<a href="javascript:window.close();">Close Window</a></div>');
*/
}
function change_search_value(val){
document.forms["cv"].elements["search"].value = val;
}
//-->
</script>
<style type="text/css">
td.detail {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
font-weight: bold;
}
td.caption {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 13px;
font-weight: bold;
text-align: center;
}
</style>
</HEAD>
<BODY bgcolor="#FFFFFF">
<div align="center"><font color="#000000"><u1></u1></font> </div>
<div align="center">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="cv">
<div align="center"><B></B>
<table width="100%"> <tr valign="top">
<td height="408">
<table width="100%">
<tr bgcolor="#CCCCCC">
<td width="47%">
<div align="CENTER">
<input type=text name="search" value="<?php echo stripslashes($_REQUEST['search']); ?>" size="30">
<input type=submit value="Search!" name="search_button">
</div>
</td>
</tr>
</table>
<table width="100%">
</table>
<table width="100%" cellpadding="0" cellspacing="0">
<?php foreach($results AS $result){ ?>
<tr align="center" valign="top">
<td colspan="5" style="padding-top: 2px;" height="391">
<div align="CENTER"><b></b></div>
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="27%" rowspan="5" bgcolor="#FFFFFF">
<table width="100%" bgcolor="#999999">
<tr valign="top">
<td><a href="javascript:show_remote('<?php echo addslashes($result['Bloom_Name']); ?>.jpg');"><img src="http://mysite/SEArchive/<?php echo $result['Bloom_Name'];?>.jpg" width="200" height="200" border="0" /></a></td>
</tr>
</table>
</td>
<td width="17%" height="97" valign="middle" align="center" bgcolor="#FFFFFF">
<table width="51%" bgcolor="#999999">
<tr>
<td height="21"><a href="javascript:show_remote('<?php echo addslashes($result['Pod_Name']); ?>.jpg');"><img src="http://mysite/SEArchive/<?php echo $result['Pod_Name'];?>.jpg" width="125" height="125" border="0" /></a></td>
</tr>
</table>
</td>
<td width="17%" height="97" valign="middle" align="center" bgcolor="#FFFFFF">
<table width="61%" bgcolor="#999999">
<tr>
<td height="19"><a href="javascript:show_remote('<?php echo addslashes($result['Pollen_Name']); ?>.jpg');"><img src="http://mysite/SEArchive/<?php echo $result['Pollen_Name'];?>.jpg" width="125" height="125" border="0" /></a></td>
</tr>
</table>
</td>
<td width="17%" height="97" valign="middle" align="center" bgcolor="#FFFFFF">
<table width="49%" bgcolor="#999999">
<tr>
<td height="9"><img src="http://mysite/SEArchive/<?php echo $result['Hybridiser'];?>.jpe" width="125" height="125" /></td>
</tr>
</table>
</td>
<td width="22%" height="97" valign="middle" align="center" bgcolor="#FFFFFF">
<table width="46%" bgcolor="#999999">
<tr>
<td height="3"><a href="http://maps.google.com/maps?f=q&hl=it&q=<?php echo $result['Origin'];?>" target="_blank"><img src="http://mysite/SEArchive/<?php echo $result['Origin'];?>.jpe" width="125" height="125" border="0" /></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="4" bgcolor="#FFFFFF" height="54" valign="top" rowspan="12">
<div align="center"><b></b></div>
<div align="center"><b></b></div>
<div align="center"><b></b></div>
<div align="center"><b></b></div>
<div align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="1"><b>
</b> </font> </div>
<font face="Verdana, Arial, Helvetica, sans-serif" size="1"></font></td>
</tr>
<tr> </tr>
<tr> </tr>
<tr> </tr>
<tr>
<td width="27%" height="2" bgcolor="#FFFFFF">
<div align="center"><b></b></div>
</td>
</tr>
<tr>
<td width="27%" rowspan="7" valign="top">
<table width="100%" bgcolor="#999999">
<tr valign="top">
<td height="152"><img src="http://mysite/SEArchive/leaf/<?php echo $result['Leaf_Image'];?>" width="200" height="200" /></td>
</tr>
</table>
</td>
</tr>
<tr> </tr>
</table>
</td>
</tr>
<? } // FOREACH RESULT?> </table></td></tr> </table>
</div>
</form><DIV ALIGN="center"> </DIV></div>
</BODY></HTML>
Last edited by Benjamin on Fri Apr 24, 2009 8:43 pm, edited 1 time in total.
Reason: Added code tags.
Reason: Added code tags.
-
skullmunky
- Forum Newbie
- Posts: 12
- Joined: Fri Apr 17, 2009 10:25 pm
Re: search subdirectory
At the end of your PHP script, try this:
then, in your HTML, replace
with
and see what that does.
Code: Select all
# $f=$result['Bloom_Name'];
# $subdir = substr($f,0,1);
# $bloomImage="http://www.mysite/SEArchive/" . $subdir . "/" . $f . ".jpg";
Code: Select all
<img src="http://mysite/SEArchive/<?php echo $result['Bloom_Name'];?>.jpg" width="200" height="200" border="0" />
Code: Select all
<img src="<?php echo $bloomImage;?>" width="200" height="200" border="0" />
Re: search subdirectory
Hi
Thanks again for your help, I've tried the code and I get the following path http://www.mysite/SEArchive//.jpg
for some reason it does not look at the subdirectory "a"
Thanks again for your help, I've tried the code and I get the following path http://www.mysite/SEArchive//.jpg
for some reason it does not look at the subdirectory "a"
-
skullmunky
- Forum Newbie
- Posts: 12
- Joined: Fri Apr 17, 2009 10:25 pm
Re: search subdirectory
print out the variables to see what they are and what's going wrong.
perhaps the first part where it gets the name out of the array isn't working right?
perhaps the first part where it gets the name out of the array isn't working right?
Code: Select all
$f=$result['Bloom_Name'];
print ("$f<br/>\n");
$subdir = substr($f,0,1);
print ("$subdir<br/>\n");
$bloomImage="http://www.mysite/SEArchive/" . $subdir . "/" . $f . ".jpg";
print ($bloomImage<br/>\n");
Re: search subdirectory
Thanks so much, I got it working