Jump to content

vzwhaley

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

vzwhaley's Achievements

Member

Member (2/5)

0

Reputation

  1. I have a directory of files with filenames such as 20070704_A_01.pdf, 20070704_B_03.pdf, etc. I am trying to get the letter, such as A and B, exploded out of the filename. There will be several instances of the same letter, such as 5 letter A's and 6 letter B's, etc. I want to get a unique list of all of the letters. But when I use array_unique, it does not recognize that there are multiple instances of the same letter. The array still looks like: AAAAAAABBBBBBBBCCCCCCCCDDDDDDDD Instead of: ABCD Any suggestions would be appreciated. //The date is passed through a URL in the form of 2007_07_04 $Date = $_REQUEST['Date']; $tempDate0 = explode("_", $Date); $Year = $tempDate0[0]; $Month = $tempDate0[1]; $Day = $tempDate0[2]; $tempDate = $Month . "/" . $Day . "/" . $Year; $dirName = $Year."/".$Month."/".$Day."/pdf/"; $dir = opendir($dirName); $files = array(); if ($handle = $dir) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != ".." && !(is_dir($file))) { $files[] = $file; } } } closedir($dir); sort($files); foreach($files as $file) { $file2 = $file; $temp = explode("_", $file2); $i = 0; while ($i < count($temp)) { $Section = $temp[$i + 1]; $i += 1; $i++; $Sections = array($Section); $newArray = array_unique($Sections); print_r($newArray); } }
  2. thanks for the help. I switched it around, but it still doesn't work, unfortunately.
  3. Hello everyone and thanks much for your past help. I am still trying to work out problems associated with a restaurant directory I am creating. I have two tables - Restaurants and RestaurantsCuisine. The RestaurantsCuisine has two fields, ID and CuisineType, in which I store the autonumber ID and name of the cuisine, such as American, Italian, Mexican, etc. I am storing the values of a restaurants cuisines in a field in the Restaurants table named Cuisine and am storing all of the cuisine IDs in an array with a pipe symbol, such as 1 | 22 | 17, etc. I can successfully explode the Cuisine field and get the individual cuisine ID numbers, but I am designing a jump menu to be able to search by cuisine name from the Restaurants table. So I am wanting to take the cuisine ID numbers in the array and match any restaurant that has a particular cuisine and return just those restaurants back to the search results page. I am trying to dynamically create the SQL statement for the Cuisine Search page by exploding the Cuisine ID numbers and matching the ID of the cuisine passed in the URL to bring back the appropriate restaurant matches to the search page. However, I am having difficulty in getting my code to properly loop through each of the ID numbers in the Cuisine array stored in the Restaurants table. In the following code, I receive the following information from searching for restaurants with a cuisine ID of 22: 9 Array ( [0] => 11 [1] => 16 [2] => 22 ) 16 Array ( [0] => 6 [1] => 20 ) 14 Array ( [0] => 4 ) 10 Array ( [0] => 16 ) 15 Array ( [0] => 8 ) 17 Array ( [0] => 17 [1] => 22 ) Here is my code: $sql5 = "SELECT * FROM Restaurants ORDER BY Name ASC"; $Recordset5 = mysql_query($sql5); $ID = $_REQUEST['ID']; $str = array(); while ($row_CID = mysql_fetch_assoc($Recordset5)) { $tempC = explode(" | ", $row_CID['Cuisine']); echo $row_CID['ID'] . " "; print_r($tempC ); echo "<br>"; if(in_array($ID, $tempC)) { $str[] = "ID = " . $row_CID['ID']; } if($str > 0) { $str = implode (" OR ", $str); } } The code should give me a SQL statement that looks something like SELECT * FROM Restaurants WHERE ID = 17 OR ID = 9 ORDER BY Name ASC when passing a cuisine ID of 22 to the search page. The problem with the above code is that the SQL statement will sometimes choose one restaurant but not all restaurants who have a value of 22 in the Cuisine array that I am exploding. And sometimes, it will not choose any restaurants, although the ID is plainly in the cuisine array. I just essentially want to be able to parse the contents of the cuisine array in the Restaurants table and pull any restaurants back to the search page that match a particular Cuisine ID passed in the URL to the search page. I know there has to be an easy way to do this. Any suggestions would be much appreciated.
  4. I have changed the names of the ID fields in the cuisines, features and loc tables to CuisineID, FeaturesID and LocID. What would be the best way to create the SQL statement and joins now? Thanks for your help!
  5. Hello everyone and thanks much for your past help. I would like some guidance on how to set up one SQL statement using joins for four MySQL tables. I am creating a restaurant guide and have four tables - Restaurants, RestaurantsCuisine, RestaurantsFeatures and RestaurantsLoc. The Restaurants table holds all of the details for the restaurant itself. The RestaurantsCuisine table holds a list of several different cuisines, such as American, Mexican, Greek, etc. The RestaurantsFeatures table holds a list of different restaurant features, such as Full Bar, All You Can Eat, Wireless Internet Access, etc. The RestaurantsLoc table holds a list of cities that the restaurants can be located in. I am wondering how I can combine all four tables using joins to load several dropdown lists to be used as jump menus for a search. Each restaurant can have multiple cuisines and features, so should I just create an array of the cuisines and features using LIKE '%".$search_array."%' in the SQL statement? Some of the schema of the Restaurants table: ID City Cuisine Features The RestaurantsCuisine table: ID CuisineType The RestaurantsFeatures table: ID FeatureType The RestaurantsLoc table: ID Loc The Restaurants table can be joined to these tables using: Restaurants.Cuisine = RestaurantsCuisine.CuisineType Restaurants.Features = RestaurantsFeatures.FeaturesType Restaurants.City = RestaurantsLoc.Loc I just don't know how to form the joins in the SQL statement and still be able to use the IDs for each table separately. Should I rename the ID fields for the cuisine, features and loc tables so I can pull in the actual ID numbers separately in separate dropdown menus? Any help with all of these questions would be much appreciated. Thank you in advance.
  6. I cannot get the following in_array to loop through all of the values of the $CuisineListS array. Does anyone know how to correctly loop through an in_array? In the following code, I should have 5 matches, but it only echoes one match. Any tips will be appreciated. PHP Code: $sql = "SELECT * FROM Restaurants WHERE ID = '6'"; $Recordset = mysql_query($sql); $RS = mysql_fetch_assoc($Recordset); $sql1 = "SELECT * FROM RestaurantsCuisine ORDER BY CuisineType ASC"; $Recordset1 = mysql_query($sql1); $Cuisine = $RS['Cuisine']; $CuisineListS = explode("|", $Cuisine); while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)) { if(in_array($row_Recordset1['ID'], $CuisineListS)) { echo "Match: " . $row_Recordset1['ID'] . "<br><br>"; } }
  7. I am creating a restaurant directory and have two tables, one named Restaurants and another named RestaurantsCuisine. I have created an array of Cuisine ID values that I store in a field called Cuisines in the Restaurants table. I then explode the Cuisine ID values and am trying to check multiple checkboxes in an edit script for the restaurant. The Cuisine IDs in the array from the Restaurants table should match with ID fields from the RestaurantsCuisine table. I cannot get the foreach loop to work correctly. It will check one of the checkboxes, but not all of the checkboxes that need to be checked. I have tested the foreach statement to ensure that it is pulling in each Cuisine ID and it is successful, but I just cannot get the loop to work correctly. Any help would be appreciated. <? $sql = "SELECT * FROM Restaurants WHERE ID = '4' "; $Recordset = mysql_query($sql); $RS = mysql_fetch_assoc($Recordset); $sql1 = "SELECT * FROM RestaurantsCuisine ORDER BY CuisineType ASC"; $Recordset1 = mysql_query($sql1); $Cuisine = $RS['Cuisine']; $CuisineListS = explode("|", trim($Cuisine)); while ($row_Recordset1 = mysql_fetch_array($Recordset1)) { ?> <input name="Cuisine[]" type="checkbox" value="<?php echo $row_Recordset1['ID']; ?>"<?php foreach ($CuisineListS as $CuisineList2) { if($CuisineList2 == $row_Recordset1['ID']) { echo " CHECKED"; } } ?> ><?php echo $row_Recordset1['CuisineType']; ?><br> <? } ?>
  8. Does anybody know of a good way to convert single digits, i.e. 1, 2, 3, 4, in a string to double double digits, i.e. 01, 02, 03, 04. I used the following code, but it places a 0 in front of numbers like 10, 11, 12, etc. Any help would be appreciated. [code] $Section = $temp[$i]; $search = array("1", "2", "3", "4", "5", "6", "7", "8", "9"); $replace = array("01", "02", "03", "04", "05", "06", "07", "08", "09"); $Section3 = str_replace($search, $replace, $Section); [/code]
  9. How do you format the relevance or score in results from a full text MySQL search? I just can't seem to get the math correct. My results are displaying fine, and I realize that the results are sorted based on the highest relevance or score, but I would like to display the relevance, such as 100%, 99%, etc. and have the number rounded so the viewer can see for themselves how high the ranking is for a certain search. Any suggestions would be much appreciated. Thanks! [code][PHP]<? $strTemp = trim($_REQUEST['txtSearch']);   mysql_select_db($database);   $sql = "SELECT *, MATCH(Name) AGAINST ('$strTemp') AS score FROM ObitData WHERE MATCH(Name) AGAINST('$strTemp') ORDER BY score DESC"; while ($Search = mysql_fetch_array($Recordset1)) { $val = round(($Search['score'] / mysql_num_rows($Search)) * 100); echo "Result: " . $val . "% " . $Search['Name'] . "<br>"; } ?>[/PHP][/code]
  10. thanks, jordie. unfortunately, that didn't help either. i rewrote the code like this, but it still can't exit out of the function once it determines if a value is true or false. any other suggestions? [code] function LoginErrorFocus($FieldNum) {     if ($FieldNum == "01") {       return "document.EmailObit.txtTo.focus()";       exit();     } elseif ($FieldNum == "02") {       return "document.EmailObit.txtName.focus()";       exit();     } elseif ($FieldNum == "03") {       return "document.EmailObit.txtEmail.focus()";       exit();     } else {     return $fOnLoad = "document.EmailObit.txtTo.focus()";       exit();     } }[/code]
  11. Hello everyone and thanks much for your past help. On my current project, I have created an "E-mail Story to a Friend" script with a form that has three fields that are being validated. I simply want the cursor to land on the first field that is not validated. In other words, the three fields for validation are To (the e-mail address for the recipient), Name (the name of the person sending the story), and E-mail (the sender's e-mail address). So if the To field is validated true, then the cursor should focus on the Name field, and if the To and Name fields are validated true, then the cursor should focus on the E-mail field. Make sense? I am new to php functions and have the following code, which does not work. Any suggestions would be much appreciated! [code]<? session_start(); function LoginErrorFocus($FieldNum) { if (strlen($FieldNum) > 0 && strlen($FieldNum) < 3) {     if ($FieldNum == "01") {       $fOnLoad = "document.EmailObit.txtTo.focus()";       return false;     }     if ($FieldNum == "02") {       $fOnLoad = "document.EmailObit.txtName.focus()";       return false;     }     if ($FieldNum == "03") {       $fOnLoad = "document.EmailObit.txtEmail.focus()";       return false;     }   }   return; } $FieldNum = ""; $fOnLoad = "document.EmailObit.txtTo.focus()"; if ($_SESSION['Errors'] == 0) {   $Instruction = "Please fill in the following form and a copy of this obituary will be sent to the e-mail address(es) you provide. Please separate multiple e-mail addresses with a comma. The <i>Johnson City Press</i> does not keep records of e-mail addresses when you e-mail an obituary to a friend.<br><font color=#FF0000><br>* Denotes a required field</font>"; } else {   $_SESSION['Errors'] = "0";   $Instruction = "<font color=FF0000>There are errors in your data. Please make the following changes:</font> &nbsp;"; } if ($_SESSION['BadTo'] == "T") {   $eEmail = "<br><span class=Author><font color=FF0000>Please enter a valid e-mail address.</font></span>";   $_SESSION['BadTo'] = "F";   $FieldNum = $FieldNum."01";   LoginErrorFocus($FieldNum); } if ($_SESSION['BadName'] == "T") {   $eName = "<br><span class=Author><font color=FF0000>Please enter your name.</font></span>";   $_SESSION['BadName'] = "F";   $FieldNum = $FieldNum."02";   LoginErrorFocus($FieldNum); } if ($_SESSION['BadEmail'] == "T") {   $eEmail2 = "<br><span class=Author><font color=FF0000>Please enter a valid e-mail address.</font></span>";   $_SESSION['BadEmail'] = "F";   $FieldNum = $FieldNum."03";   LoginErrorFocus($FieldNum); } ?>[/code]
  12. Can anyone tell me why the following code will not redirect to the page when the recordset is true? [code]  $sql = "SELECT Username, Pass, Security FROM Admin WHERE Username = '$Username' AND Pass = '$Password'";   $RS = mysql_query($sql);   $num = mysql_num_rows($RS);      if ($num != 0) {   $redirectLoginSuccess = "default.php";   $_SESSION['Username'] = $RSLogin['Username'];   $_SESSION['Security'] = $RSLogin['Security'];      header("Location: ".$redirectLoginSuccess);      }[/code]
  13. Hello everyone and thanks much for your past help. I am wanting to pull two records from a database and give each of them a named anchor link based on a number, such as $i = 0; and increment that number for each record. In other words, the first named anchor would be #0 and the second one would be #1, and so on. I can't seem to get this to work with the following code. Any tips or suggestions would be greatly appreciated. [code] do { for ($i = 0; $i <= 1; $i++) {             echo "<b><a href=#".$i." class=\"TopStories\">".$RSMiddle2['Title']."</a></b><br>"; } } while ($RSMiddle2 = mysql_fetch_array($Recordset2)); [/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.