Jump to content

FutonGuy

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

FutonGuy's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi I am using the if..else statement to help me to solve some queries. Here's the code: ///////////////////// /// /// LATEST DATA /// ///////////////////// while ($row_export = mysql_fetch_array($result_export, MYSQL_ASSOC)) { ///////////////////////////////// /// /// OPTION 1 /// DATABASE ON EXISTING TABLE /// ///////////////////////////////// $sql_test = "SELECT * FROM wsdevice "; if (trim($pib_bracket_num) !='' and trim($HW_design) !='' ) { $sql_test .=" WHERE ((wsdevice_pibid like '%$pib_bracket_num%') and (device_designid = '$HW_design')) "; $results = mysql_query($sql_test) or die ("NO SEARCH TERMS"); while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) { ///////////////////////////////// /// /// OPTION 2 /// DISPLAY EXISTING DATA IN /// TABLE FORM ///////////////////////////////// ///////////////////////////////// /// /// DISPLAY UPDATE ON LATEST DATA /// IN TABLE FORM ///////////////////////////////// } } else { ///////////////////////////////// /// /// OPTION 3 /// DISPLAY LATEST DATA NOT UPDATED /// ///////////////////////////////// } } Just wondering if there's any code i can use in order to satisfy the query statement whereby if $sql_test .=" WHERE ((wsdevice_pibid like '%$pib_bracket_num%') and (device_designid = '$HW_design')) "; is true, it will proceed to option 2 and if it doesn't satisfy the query, it will move to option 3 ?
  2. Will you be able to show me some examples how should i do it? Thanks
  3. Hi, HW_Dev is a value that might look like this : BNM1234CO I want to extract just the number, 1234, out from this HW_Dev. thanks
  4. Hi, I am trying to extract numbers out from a field which is in alphanumeric. Did a search on the web and found that i can actually use "number_format" to extract the numbers out from the field. However i receive some notices and warning which read: 1) Notice: A non well formed numeric value encountered in C:\db\update.php on line 50 2) Warning: number_format() expects parameter 1 to be double, string given in C:\db\date.php on line 50 my code is : $HW_dev = $row_export['HW_dev_num' $HW_dev_num = number_format($HW_dev,0,'',''); Can someone able to assist on this issue? thank you and your help is greatly appreciated. Cheers
  5. $_GET['val_d'] is an input that came from another php file. This code here is to allow user to save the results which is shown on the web browser. So when user clicked on [save result], $_GET['val_d'] will pass the value to this code here. Here's my code: $val_d = $_GET['val_d']; $sql = "SELECT * FROM device"; $sql .="WHERE device_num LIKE '%$val_d%' "; $results = mysql_query($sql) or die (mysql_error()); $count = mysql_num_fields($results); for ($i = 0; $i < $count; $i++){ $header .= mysql_field_name($results, $i)."\t"; } while($row = mysql_fetch_row($results)){ $line = ''; foreach($row as $value){ if(!isset($value) || $value == ""){ $value = "\t"; }else{ # important to escape any quotes to preserve them in the data. $value = str_replace('"', '""', $value); # needed to encapsulate data in quotes because some data might be multi line. # the good news is that numbers remain numbers in Excel even though quoted. $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } # this line is needed because returns embedded in the data have "\r" # and this looks like a "box character" in Excel $data = str_replace("\r", "", $data); # Nice to let someone know that the search came up empty. # Otherwise only the column name headers will be output to Excel. if ($data == "") { $data = "\nno matching records found\n"; } # This line will stream the file to the user rather than spray it across the screen header("Content-type: application/octet-stream"); # replace excelfile.xls with whatever you want the filename to default to header("Content-Disposition: attachment; filename=excelfile.xls"); header("Pragma: no-cache"); header("Expires: 0"); echo $header."\n".$data;
  6. Hi, I am having problem solving my query error, would appreciate if someone can assist me. $val_d = $_GET['val_d']; $sql = "SELECT * FROM device"; $sql .="WHERE device_num LIKE '%$val_d%' "; the error code i had was: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE '%" . urlencode($val_d) . "%'' at line 2" There is no problem if my query is $sql = "SELECT * FROM device WHERE device_num LIKE '%$val_d%' "; I did the 1st method is because i need it in my later script. Appreciate if someone can assist me and guide me along. Cheers
  7. Hi does anyone know how to work on a combination of search queries of 2 or more different fields to narrow down the search option? Scenario: dev number: [free text-wildcard will be use] site : [option-drop down list] board number: [free text-wildcard will be use] [sEARCH BUTTON] User can search by either one of the options or all of the option to narrow down the search queries. here's the code i have. Hopefully someone can help me with my queries.. $val_d = $_POST['device_search']; $val_sub = $_POST['subconsite']; echo "$val_d"; echo "<br>"; echo "$val_sub"; if (trim($val_d) != '' or trim($val_sub) != ''){ $sql = "select * from wsdevice"; if (trim($val_d) != ''){ $sql .= " where wsdevice_num like '%$val_d%' "; //'%" . trim($val_d) . "%' $where = true; } if (trim($val_sub) != ''){ if (!$where){ $sql .= " where subcon_site like '%$val_sub%' "; // '%" . trim($val_sub) . "%' } else { $sql = str_replace("where ", "where (", $sql); $sql .= " and subcon_site like '%$val_sub%') or (wsdevice_num like '%$val_d%' or subcon_site like '%$val_sub%')"; } // '%" . trim($val_sub) . "%' '%" . trim($val_sub) . "%' '%" . trim($val_d) . "%' } else { die("NO SEARCH TERMS"); } $results = mysql_query($sql) or die (mysql_error()); $numrows = mysql_num_rows($results); // This is where i output my results include "WSsearchtable.php"; Cheers..
  8. Hi, i have been trying for days but couldn't get this sorted out. Would like some professional help here. Basically I got a basic pagination script from google search and the script works absolutely well if i am to display the full results. However i am using the 'SELECT...WHERE.. LIKE %$val%' and the result works well for the 1st page but not on the 2nd or 3rd page. i had a search form to submit my value. Some help as to where i should proceed is greatly appreciated! Cheers Here's my coding: form.php <form action="FTsearch.php" method="post"> <table border=0 cellspace=1 cellpadding=3 bgcolor;"#353535" align="center"> <tr> <td bgcolor="#eeeeff" width="50%"> Device Number </td> <td bgcolor="#eeeeff" width="50%"> <INPUT type = "TEXT" name = "devicesearch"> </td> </tr> <tr> <td bgcolor ="eeeeff" colspan=2 align="center"> <INPUT Type="SUBMIT" name="submit" value="Device Search"> </td> </tr> </table> </form> FTsearch.php $val_d = $_POST['devicesearch']; if ($_POST['SEARCH'] = 'Device Search') { $sql = "SELECT * FROM device WHERE device_num LIKE '%$val_d%' or '%$val_d'"; $results1 = mysql_query($sql) or die ("Sorry no match found!".mysql_error()); //This checks to see if there is a page number. If not, it will set it to page 1 if (!(isset($pagenum))) { $pagenum = 1; } $pagenum = $_GET['pagenum']; echo "<center>"; /* if(!isset($_GET['page'])) { $pagenum = 1; } else { $pagenum = $_GET['page']; } */ $numrows = mysql_num_rows($results1); $page_rows = 10; //This is the number of results displayed per page $last = ceil($numrows/$page_rows); //This tells us the page number of our last page if ($pagenum < 1) //this makes sure the page number isn't below one, or more than our maximum pages { $pagenum = 1; } elseif ($pagenum > $last) { $pagenum = $last; } $max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows; //This sets the range to display in our query $sql = "SELECT * FROM device WHERE device_num LIKE '%$val_d%' or '%$val_d' $max"; $results = mysql_query($sql) or die (mysql_error()); // this is the result display include "FTsearchtable.php"; echo "<br><br><center>Page $pagenum of $last<br><br>"; // This shows the user what page they are on, and the total number of pages // First we check if we are on page one. //If we are then we don't need a link to the previous page or the first page so we do nothing. //If we aren't then we generate links to the first page, and to the previous page. if($pagenum>1) { echo " <a href='{$_SERVER['PHP_SELF']}?&pagenum=1'>First</a> "; $previous = $pagenum-1; echo " <a href='{$_SERVER['PHP_SELF']}?&pagenum=$previous'>Previous</a> "; } //This does the same as above, only checking if we are on the last page, and then generating the Next and Last links if ($pagenum == $last) { } else { $next = $pagenum+1; echo " <a href='{$_SERVER['PHP_SELF']}?&pagenum=$next'>Next</a> "; echo " "; echo " <a href='{$_SERVER['PHP_SELF']}?&pagenum=$last'>Last</a> "; } }
  9. Dear all, I am new to PHP and MySql. I am trying to submit my data on a php created form to mysql database where it is separate by 2 tables (device) and (site). Below is a clearer pic using table to explain what i intend to do in order for you guys to assist me. Device Table ID Device_num Device_loc 1 AD192C 2 2 AD23O 3 3 FT432 3 4 GH324 1 Site Table ID area 1 Single 2 Dual 3 Quad 4 Octal I created a form where device_num is to be keyed in by user and a drop down option for Site table of 4 fields (see Site table above) to choose from. I managed to use the INSERT function to insert the device number into the database, however when i chose the area (say Dual), the Site_ID '2' will reflect '2' in the device table as well - cant seem to get that work out!. Below is my code i used : $val_d = $_POST['Device_num']; $val_s = $_POST['site_model']; $site_insert = "INSERT INTO site (site_id, site_model) VALUES (NULL, '$val_s')"; $results = mysql_query($site_insert) or die (mysql_error()); $siteid = "SELECT site_id FROM site WHERE site_id = device_site"; $siteid_id = mysql_query($siteid) or die (mysql_error()); $device_insert = "INSERT INTO device (device_id, device_num, device_site) VALUES (NULL, '$val_d', '$siteid_id')"; $results = mysql_query($device_insert) or die (mysql_error()); Thanks in advance for the help. Cheers
×
×
  • 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.