 |
|
|
04-22-2009, 11:32 AM
|
search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Hi everyone
I'm in a desperate situation, I hope someone can help.
I have a search engine that use 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 through my ftp program since 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 the letter “A” to the a subdirectory 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 until it finds the image.
I would appriciate if you add the code to the script, since I'm only a novice and have a lot to learn.
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>
PHP Code:
<?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 ?> <HTML> <?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 ?> <HTML>
|
|
|
|
04-25-2009, 02:00 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
simple. you need to have a code to check on $result['Bloom_Name'] and get the first letter of it and use it as a directory
PHP Code:
$result['Bloom_Name']=$result['Bloom_Name'][0] . '/' . $result['Bloom_Name']
this simply will add a directory name to the name of the image.
bs. the directory will be in lower case letter ex. a or b
to make it upper case you need to use the function strtoupper
PHP Code:
$result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name']
Last edited by nayes84; 04-27-2009 at 04:35 AM..
|
|
|
|
04-27-2009, 03:44 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Hi
Thank you so much it's working just fine, however how can I drop the G/ of G/Grey Lady and echo only the name "Grey Lady"
PHP Code:
<?php echo $result['Bloom_Name'];?>
|
|
|
|
04-27-2009, 04:29 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
oops didn't notice you use the folder name as the label also
ok in that case you need to change your code a little bit
here it goes
PHP Code:
<?php echo $result['Bloom_Label'];?>
then in the past code you need to make it like that
PHP Code:
$result['Bloom_Label']=$result['Bloom_Name']; $result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name'];
|
|
|
|
04-27-2009, 05:32 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Hi
The label echo is fine, but now it only looks at the directory and not the individual subdirectories.
The Label, is the image name, please be patient I'm got lot to learn
PHP Code:
<a href="javascript:show_remote('<?php echo addslashes($result['Bloom_Name']); ?>.jpg');"><img src="http://www.Mysite/SEArchive/<?php $result['Bloom_Label']=$result['Bloom_Name']; $result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name'];?>.jpg" width="200" height="200" border="0" /></a>
|
|
|
|
04-27-2009, 06:28 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
I think you mistaken the place to put the code
the php code need to be at the first before any html then you can use $result['Bloom_label'] to display the name of the directory and use $result['Bloom_Name'] to link to the directory ex: G/Girl ...
PHP Code:
<?php $result['Bloom_Label']=$result['Bloom_Name']; $result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name']; ?>
|
|
|
|
04-28-2009, 04:01 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Hi
I finally got it working, it took me a while but now it's working fine.
Can you help me with this one, I need to add subdirectory to the path, just like the previous one.
Thank you so much for your help
PHP Code:
function displayImageLink($member, $size = array(80,80)){ if($member['Bloom_Name']!='Unknown'){ $return = '<a href="javascript:show_remote(\''.addslashes($member['Bloom_Name']).'.jpg\');">'; $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/'.$member['Bloom_Name'].'.jpg" height="'.$size[1].'" border="0" \></a>'; } else { $return .= '<img width="'.$size[0].'" src="http://www.mysite/SEArchive/Unknown.jpg" height="'.$size[1].'" \>';
|
|
|
|
04-28-2009, 04:12 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
Quote:
Originally Posted by jd57
Hi
I finally got it working, it took me a while but now it's working fine.
Can you help me with this one, I need to add subdirectory to the path, just like the previous one.
Thank you so much for your help
PHP Code:
function displayImageLink($member, $size = array(80,80)){ if($member['Bloom_Name']!='Unknown'){ $return = '<a href="javascript:show_remote(\''.addslashes($member['Bloom_Name']).'.jpg\');">'; $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/'.$member['Bloom_Name'].'.jpg" height="'.$size[1].'" border="0" \></a>'; } else { $return .= '<img width="'.$size[0].'" src="http://www.mysite/SEArchive/Unknown.jpg" height="'.$size[1].'" \>';
|
Is that code in a page different from the other past code? if so then you need to add the same two lines just before calling this function
PHP Code:
$result['Bloom_Label']=$result['Bloom_Name']; $result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name'];
Also you need to modify the function a little bit
PHP Code:
function displayImageLink($member, $size = array(80,80)){ if($member['Bloom_Label']!='Unknown'){ $return = '<a href="javascript:show_remote(\''.addslashes($member['Bloom_Name']).'.jpg\');">'; $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/'.$member['Bloom_Name'].'.jpg" height="'.$size[1].'" border="0" \></a>'; } else { $return .= '<img width="'.$size[0].'" src="http://www.mysite/SEArchive/Unknown.jpg" height="'.$size[1].'" \>';
|
|
|
|
04-28-2009, 05:21 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Hi
this script is in another page, I've tried the same previous code and modified the function. I think I placed them in the right place, but the script does not work.
PHP Code:
<?PHP function loadMember($name){ global $link; // Fetch total number of records //$SQL="SELECT * FROM ihsreg WHERE Bloom_Name ='".addslashes($name)."'"; if(stristr($name,"'") && !stristr($name,"\'")){ $name = addslashes($name); } $SQL="SELECT * FROM ihsreg WHERE Bloom_Name ='".$name."'"; $result = mysql_query($SQL); $row = mysql_fetch_assoc($result); if($row['id'] != 1 && sizeof($row) > 5){ return $row; } else { $row = array('id'=>1,'Bloom_Name'=>'Unknown'); return $row; } } $result['Bloom_Label']=$result['Bloom_Name']; $result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name']; function displayImageLink($member, $size = array(80,80)){ if($member['Bloom_Label']!='Unknown'){ $return = '<a href="javascript:show_remote(\''.addslashes($member['Bloom_Name']).'.jpg\');">'; $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/'.$member['Bloom_Name'].'.jpg" height="'.$size[1].'" border="0" \></a>'; } else { $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/Unknown.jpg" height="'.$size[1].'" \>';
Last edited by jd57; 04-28-2009 at 05:23 AM..
|
|
|
|
04-28-2009, 05:36 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
what does it show in the link?
|
|
|
|
04-28-2009, 06:35 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
Quote:
Originally Posted by jd57
|
I don't know how your code looks exactly cause you posted only part of it.
but anyway you should use $result['Bloom_Label'] instead of $result['Bloom_Name'] when you need to show the name
in that search box replace use $result['Bloom_Label']
|
|
|
|
04-28-2009, 07:05 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Hi
I'm sorry! perhaps I'm bothering you to much, here is the full code
PHP Code:
<?PHP function loadMember($name){ global $link; // Fetch total number of records //$SQL="SELECT * FROM ihsreg WHERE Bloom_Name ='".addslashes($name)."'"; if(stristr($name,"'") && !stristr($name,"\'")){ $name = addslashes($name); } $SQL="SELECT * FROM ihsreg WHERE Bloom_Name ='".$name."'"; $result = mysql_query($SQL); $row = mysql_fetch_assoc($result); if($row['id'] != 1 && sizeof($row) > 5){ return $row; } else { $row = array('id'=>1,'Bloom_Name'=>'Unknown'); return $row; } } $result['Bloom_Label']=$result['Bloom_Name']; $result['Bloom_Name']=strtoupper($result['Bloom_Name'][0]) . '/' . $result['Bloom_Name']; function displayImageLink($member, $size = array(80,80)){ if($member['Bloom_Name']!='Unknown'){ $return = '<a href="javascript:show_remote(\''.addslashes($member['Bloom_Name']).'.jpg\');">'; $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/'.$member['Bloom_Name'].'.jpg" height="'.$size[1].'" border="0" \></a>'; } else { $return .= '<img width="'.$size[0].'" src="http://www.Mysite/SEArchive/Unknown.jpg" height="'.$size[1].'" \>'; } return $return; } function loadMother($child){ return loadMember($child['Pod_Name']); } function loadFather($child){ return loadMember($child['Pollen_Name']); } if(isset($_REQUEST['Search_box'])){ $search = $_REQUEST['Search_box']; $link = mysql_connect('localhost', 'xxxxx, 'xxxxx'); if (!$link) { die('Could not connect: ' . mysql_error()); } mysql_select_db('xxxx'); $main = loadMember($search); $mother = loadMember($main['Pod_Name']); $father = loadMember($main['Pollen_Name']); $grandmother1 = loadMother($father); $grandfather1 = loadFather($father); $grandmother2 = loadMother($mother); $grandfather2 = loadFather($mother); $greatgrandmother1 = loadMother($grandfather1); $greatgrandfather1 = loadFather($grandfather1); $greatgrandmother2 = loadMother($grandmother1); $greatgrandfather2 = loadFather($grandmother1); $greatgrandmother3 = loadMother($grandfather2); $greatgrandfather3 = loadFather($grandfather2); $greatgrandmother4 = loadMother($grandmother2); $greatgrandfather4 = loadFather($grandmother2); //echo "<PRE>".print_r($grandmother2,true)."</PRE>"; } ?>
Last edited by jd57; 04-28-2009 at 08:05 AM..
|
|
|
|
04-28-2009, 07:26 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
Quote:
Originally Posted by jd57
|
you need to fix the page linking to that url not that page
so that it opens like that
http://www.mysite/SEArchive/index1.p...rch_box=A/Adam
ps. when I opened the page it shows error
The page you are looking for ( http://mysite.com/SEArchive/index1.php) is not here.
is this a related error?
Quote:
|
I'm sorry! perhaps I'm bothering you to much, here is the full code
|
never mind it is ok 
Last edited by nayes84; 04-28-2009 at 07:27 AM..
|
|
|
|
04-28-2009, 07:47 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
You mean to change this in the other php script, if so, how would I add the code?
PHP Code:
function show_remote(imageSrc){ //OpenWindow = window.open("http://www.Mysite/SEArchive/index1.php?Search_box="+imageSrc.split('.')[0], "remoteWin", "resizable=1, scrollbars=1, toolbar=0, left=15, top=10, width=290, height=320"); document.location = 'http://www.Mysite/SEArchive/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>'); */
|
|
|
|
04-28-2009, 08:02 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
not that function. but the caller of this function. may be more than one place you should look for it
|
|
|
|
04-28-2009, 08:10 AM
|
Re: search subdirectory
|
Posts: 16
Name: Joe
Location: Italy
|
Can I send you the scripts in your private mail?
|
|
|
|
04-28-2009, 08:24 AM
|
Re: search subdirectory
|
Posts: 232
Name: John
Location: Tokyo
|
sent to you via pm
|
|
|
|
|
« Reply to search subdirectory
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|