PHP - Display Part Of Regex Search
Hi,
I am using a PHP's preg_match() to search through string, and displaying its pattern, but want to display only part of it. E.g. looks like Code: [Select] preg_match('/shape=\'.*\'/sU',$value,$matches); The search displays " class='PHPfreaks' " From the search I would like to display only the part highlighted in bold. " '/shape=\'.*\'/sU' " So the final value to be displayed should be " PHPfreaks " Regards, Abhishek Similar Tutorialshi, also i need to make a new array which includes all regex matches or strstr matches (it doesn't need to be regex) from the old array. now i have it like this: $array=array('cathouse','doghouse','mousehouse'); preg_match_all("@\,([a-zA-Z0-9\|]+dog[a-zA-Z0-9\|]+)\,@i",',|'.implode("|,|",$array).'|,',$matches); print_r($matches[1]); but is there a faster way to do this? (i tryed with loops but it's all slower) i also have all this in another loop. because it must match more words/strings then only "dog". EDITED. Hi, I am not that good with understanding REGEX/REGEXP functions but, Could someone please let me know as how can I search through html code for a particular tag having a definite start and definite end. E.g. HTML Code below, it has definite Start of Code: [Select] <div id="ST and definite End of Code: [Select] house='Anything'></div></div></div> Code: [Select] <div id="ST12345678_st" class="r_right_col"> <div class=""></div> <div id=""><span class=""></span></div> <div class=""></div> <div class=""><span class=""></span></div> <div class=""></div> <div class=""> <div style="" id="" fname=Abhishek lname='madhani' division=8C house='Anything'> </div> </div> </div> So the HTML file which I have, has the this particular tag being repeated atleast more than 50 times in whole code. And I am planning to extract each of them seperately. So if someone could help me with REGEX to search for this particular tags in whole file, would be really helpful. Regards, Abhishek Madhani Hi all, first time here as I am a bit stuck. I am by no means a programmer and I was hoping that someone out there may have a simple solution to my problem?... So here goes" I have a voucher/offers site up-and-running. The site content is generated from an external feed. I want to create other sites and I want to track what sales/clicks have come from where. An example of the feed: (http://www.awin1.com/awclick.php?mid=251&id=28971&clickref=[URL_REFERENCE]&p=http://www.247electrical.co.uk) As you will see, I have [URL_REFERENCE] in each link. I want to automatically change that part of the string in the database. Does anyone have any thoughts? i am having the database consists of morethan one lac rows. we have a search option in our website to search the database for required information. the present code is like this: form.php `<input type="radio" name="tag" value="city" /> CITY <br/>` `<input type="radio" name="tag" value="name" /> NAME OF CUSTOMER <br/>` `<input type="radio" name="tag" value="amount" /> CHEQUE AMOUNT <br/>` `<input type="radio" name="tag" value="somethingelse" /> some thing else ` `Enter the part of any of the above Here :<input type="text" name="value" />` search.php `$tag = $_POST['tag'];` `$value = $_POST['value'];` `$query = "SELECT * FROM database WHERE $tag LIKE '%$value%' "` note: we always input the part field only. with this some times the output comes in thousands of rows. with which we are facing problems. we want to search the two or more fields for getting more precise results. hence i tried this form: `<h3 align="center">ENTER ALL OR DESIRED ITEMS YOU WANT TO SEARCH</h3>` `<div width="80%" align="center">` `<input type="text" name="city" /> CITY <br/>` `<input type="text" name="name" /> NAME OF THE CUSTOMER <br/>` `<input type="text" name="amount" /> AMOUNT <br/>` `<input type="text" name="somethingelse" /> SOME OTHER SEARCH FIELD </div> ` `$query = "SELECT * FROM database WHERE city LIKE %$city%' || name LIKE %$name%' || amount LIKE %$amount%' || somethingelse LIKE %$somethingelse%';` it worked in the mysql console, and even in our website when we give all the variables. but it displaying the entire database when we dont give even one field in the search box. i tried to assign NULL to the variable which was not given. it is also not worked. it works if any variable is replaced with NULL in the query. i don't know how to do that. i tried a lot of queries after searching in lot of code provider websites. but none of them gave the desired results.hence i request you to provide me a sql query code for search the database using all of the above fields or any two or even with one. the code must work independent of number of fields we entered. Let's say I have a variable called $big_paragraph I want to display the variable IF it contains the word "hello". The word may or may not be there AND it could be anywhere in that paragraph (separated by a space before and after it to signify that it is a word). So I can't use substr since it assumes I know the position. Thanks. The program is working for part of the data . It can display in the CSS and HTML code, however, the other data can not display . I do not why . They are same structure . Please tell me the reason. Thank you very much. I have done this successfully in the past, but this time not working. I have 4 different html sections and I only want the individual section to display if a variable is set or is set to a specified term. But this code shows all of the sections no matter what, even though I'm using if() and elseif(). This code sample is the whole page, excuse the length, but only way to fix what I am doing wrong. <head> <?php require_once ('includes/auth.php'); require_once ('includes/config.php'); require_once ('includes/connect.php'); $action = $_POST['action']; $agencyid = $_POST['agencyid']; function clean($str) { $str = @trim($str); if (get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } if (isset($_POST['next1'])) { $fieldrep = clean($_POST['fieldrep']); $agencytype = clean($_POST['typeofagency']); $agencyent = clean($_POST['typeofent']); $exclusive = clean($_POST['exclusivity']); $capcarrier = clean($_POST['formcapt']); $contdate = clean($_POST['contdate']); $agencyname = clean($_POST['agencyname']); $physstr = clean($_POST['physstr']); $physcity = clean($_POST['physcity']); $physstate = clean($_POST['physstate']); $physzip = clean($_POST['physzip']); $physcount = clean($_POST['physcounty']); $mailstr = clean($_POST['mailstr']); $mailcity = clean($_POST['mailcity']); $mailstate = clean($_POST['mailstate']); $mailzip = clean($_POST['mailzip']); $mailcount = clean($_POST['mailcounty']); $fedtaxid = clean($_POST['fedtaxid']); $w9payto = clean($_POST['w9payto']); $agencylic = clean($_POST['agencylic']); $busphone = clean($_POST['bustele']); $busfax = clean($_POST['busfax']); $eandocar = clean($_POST['eocarrier']); $eandopolnum = clean($_POST['eopolnum']); $agencyemail = clean($_POST['agencyemail']); $website = clean($_POST['agencywebsite']); $car1name = clean($_POST['topcar1']); $car1prem = clean($_POST['topcardol1']); $car2name = clean($_POST['topcar2']); $car2prem = clean($_POST['topcardol2']); $car3name = clean($_POST['topcar3']); $car3prem = clean($_POST['topcardol3']); $car4name = clean($_POST['topcar4']); $car4prem = clean($_POST['topcardol4']); $car5name = clean($_POST['topcar5']); $car5prem = clean($_POST['topcardol5']); $perline = clean($_POST['perslineper']); $comline = clean($_POST['commlineper']); $lifeline = clean($_POST['lifelineper']); $sccar1 = clean($_POST['carrier1']); $sccar2 = clean($_POST['carrier2']); $sccar3 = clean($_POST['carrier3']); $sccar4 = clean($_POST['carrier4']); $sccar5 = clean($_POST['carrier5']); $choicepoint = clean($_POST['choicepoint']); $clientinfo = "INSERT INTO agency SET fieldrep = '$fieldrep', agencytype = '$agencytype', agencyent = '$agencyent', exclusive = '$exclusive', capcarrier = '$capcarrier', contdate = '$contdate', agencyname = '$agencyname', physstr = '$physstr', physcity = '$physcity', physstate = '$physstate', physzip = '$physcount', mailstr = '$mailstr', mailcity = '$mailcity', mailstate = '$mailstate', mailzip = '$mailzip', mailcount = '$mailcount', fedtaxid = '$fedtaxid', w9payto = '$w9payto', agencylic = '$agencylic', busphone = '$busphone', busfax = '$busfax', eandcar = '$eandcar', eandopolnum = '$eandopolnum', agencyemail = '$agencyemail', website = '$website', car1name = '$car1name', car1prem = '$car1prem', car2name = '$car2name', car2prem = '$car2prem', car3name = '$car3name', car3prem = '$car3prem', car4name = '$car4name', car4prem = '$car4prem', car5name = '$car5name', car5prem = '$car5prem', perline = '$perline', comline = '$comline', lifeline = '$lifeline', sccar1 = '$sccar1', sccar2 = '$sccar2', sccar3 = '$sccar3', sccar4 = '$sccar4', sccar5 = '$sccar5', choicepoint = '$choicepoint'"; $newclient = mysql_query($clientinfo) or die(mysql_error()); $agencyid = mysql_insert_id(); } if (isset($_POST['next2'])) { $name = clean($_POST['name']); $title = clean($_POST['emptype']); $ownership = clean($_POST['ownership']); $yrsins = clean($_POST['yrsins']); $profdesig = clean($_POST['profdesig']); $resstr = clean($_POST['resstr']); $rescity = clean($_POST['rescity']); $resstate = clean($_POST['resstate']); $reszip = clean($_POST['reszip']); $rescounty = clean($_POST['rescounty']); $social = clean($_POST['social']); $dob = clean($_POST['dob']); $tele = clean($_POST['tele']); $inslicense = clean($_POST['inslicense']); $emptype = clean($_POST['emptype']); $agencyid = clean($_POST['agencyid']); $empinsert = mysql_query("INSERT INTO employees SET name = '$name', title = '$title', ownership = '$ownership', yrsins = '$yrsins', profdesig = '$profdesig', resstr = '$resstr', rescity = '$rescity', resstate = '$resstate', reszip = '$reszip', rescounty = '$rescounty', social = '$social', dob = '$dob', tele = '$tele', inslicense = '$inslicense', emptype = '$emptype', agencyid = '$agencyid'")or die(mysql_error()); } if(isset($_POST['addemp'])) { $name = clean($_POST['name']); $title = clean($_POST['emptype']); $ownership = clean($_POST['ownership']); $yrsins = clean($_POST['yrsins']); $profdesig = clean($_POST['profdesig']); $resstr = clean($_POST['resstr']); $rescity = clean($_POST['rescity']); $resstate = clean($_POST['resstate']); $reszip = clean($_POST['reszip']); $rescounty = clean($_POST['rescounty']); $social = clean($_POST['social']); $dob = clean($_POST['dob']); $tele = clean($_POST['tele']); $inslicense = clean($_POST['inslicense']); $emptype = clean($_POST['emptype']); $agencyid = clean($_POST['agencyid']); $empinsert = mysql_query("INSERT INTO employees SET name = '$name', title = '$title', ownership = '$ownership', yrsins = '$yrsins', profdesig = '$profdesig', resstr = '$resstr', rescity = '$rescity', resstate = '$resstate', reszip = '$reszip', rescounty = '$rescounty', social = '$social', dob = '$dob', tele = '$tele', inslicense = '$inslicense', emptype = '$emptype', agencyid = '$agencyid'")or die(mysql_error()); } if (isset($_POST['submit'])) { $captive = clean($_POST['captive']); $mgastruc = clean($_POST['mgastruc']); $pastdue = clean($_POST['pastdue']); $suits = clean($_POST['suits']); $crimes = clean($_POST['crimes']); $suspensions = clean($_POST['suspensions']); $submitfinal = mysql_query("UPDATE agency SET captive = '$captive', mgastruc = '$mgastruc', pastdue = '$pastdue', suits = '$suits', crimes = '$crimes', suspensions = '$suspensions', completed = 'Yes' WHERE ID = '$agencyid'") or die(mysql_error()); } ?> </head> <body> <div id="containerfull"><!-- Use"containerfull" for 100% width. For fixed width, use "container980", "container760" or "container600" (the number is the layout width in pixels). --> <div id="header"> <h1><a href="http://www.yoursite.com/"><img width="400" height="100" src="images/logo.jpg" /></a></h1> </div> <div id="menu"> <ul> <li><a href="index.html">Home</a></li> <li><a class="current" href="signup.html">Signup a Producer</a></li> </ul> </div> <?php if (isset($_POST['next1'])) { ?> <div id="main"> <div id="containerfull"> <h3>D. Employee Information</h3> <table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <p> <tr> <td>Owner Name</td><td colspan="9"><input type="text" size="50" maxlength="75" name="name" tabindex="1" /></td> </tr> <tr> <td>Employee Type</td><td><select size="1" name="emptype" tabindex="2"> <option value="Owner">Owner</option> <option value="Employee">Employee</option> </select></td> </tr> <tr> <td>% Ownership</td><td> </td><td><input type="text" size="3" maxlength="3" name="ownership" tabindex="2" /></td><td> </td><td>Years In Insurance</td><td><input type="text" size="3" maxlength="3" name="yrsins" tabindex="3" /></td><td> </td><td>Professional Designations</td><td><input type="text" size="25" maxlength="50" name="profdesig" tabindex="4" /></td> </tr> <tr> <td>Resident Address</td><td colspan="8"><input type="text" size="50" maxlength="75" name="resstr" tabindex="5" /></td> </tr> <tr> <td> </td><td>City</td><td><input type="text" size="20" maxlength="45" name="rescity" tabindex="6" /></td><td>State</td> <td> <select tabindex="6" name="resstate" size="1" tabindex="10"> <option value="AL">AL</option> <option value="AK">AK</option> <option value="AZ">AZ</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="CT">CT</option> <option value="DE">DE</option> <option value="DC">DC</option> <option value="FL">FL</option> <option value="GA">GA</option> <option value="HI">HI</option> <option value="ID">ID</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="IA">IA</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="ME">ME</option> <option value="MD">MD</option> <option value="MA">MA</option> <option value="MI">MI</option> <option value="MN">MN</option> <option value="MS">MS</option> <option value="MO">MO</option> <option value="MT">MT</option> <option value="NE">NE</option> <option value="NV">NV</option> <option value="NH">NH</option> <option value="NJ">NJ</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="NC">NC</option> <option value="ND">ND</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OR">OR</option> <option value="PA">PA</option> <option value="RI">RI</option> <option value="SC">SC</option> <option value="SD">SD</option> <option value="TN">TN</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="VT">VT</option> <option value="VA">VA</option> <option value="WA">WA</option> <option value="WV">WV</option> <option value="WI">WI</option> <option value="WY">WY</option> </select> </td><td>Zip</td><td><input type="text" size="10" maxlength="10" name="reszip" tabindex="8" /></td><td>County</td><td><input type="text" size="25" maxlength="45" name="rescounty" tabindex="9" /></td> </tr> <tr> <td>Social Security #</td><td><input type="text" size="11" maxlength="11" name="social" tabindex="10" /></td><td> </td><td>Date Of Birth</td><td><input type="text" size="10" maxlength="10" name="dob" tabindex="11" /></td><td>Home Telephone</td><td><input type="text" size="12" maxlength="12" name="tele" tabindex="12" /></td> </tr> <input type="hidden" value="<?php echo $agencyid; ?>" name="agencyid" /> <input type="hidden" value="addemp" name="action" /> <tr> <td><input type="submit" value="Add Employee" name="addemp" tabindex="12" /></td><td><input type="submit" value="Next" name="next2" tabindex="13" /></td> </tr> </form> </table> <?php } elseif (isset($_POST['next2'])) { ?> <div id="main"> <div id="containerfull"> <h3>F. Questions</h3> <table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td>1. Is agent/agency affiliated with ANY captive entity or carrier?</td><td><select size="1" name="captive" tabindex="1"> <option value="No">No</option> <option value="Yes">Yes</option> </select></td> </tr> <tr> <td>2. Is agent/agency affiliated with ANY MGA structure?</td><td><select size="1" name="mgastruc" tabindex="2"> <option value="No">No</option> <option value="Yes">Yes</option> </select></td> </tr> <tr> <td>3. Any account current or unearned commission balances past due to any company?</td><td><select size="1" name="pastdue" tabindex="3"> <option value="No">No</option> <option value="Yes">Yes</option> </select></td> </tr> <tr> <td>4. Any judgements or suits pending against the Agency?</td><td><select size="1" name="suits" tabindex="4"> <option value="No">No</option> <option value="Yes">Yes</option> </select></td> </tr> <tr> <td>5. Have you or anyone in your Agency ever been convicted of a felony crime in any state or federal court?</td><td><select size="1" name="crimes" tabindex="5"> <option value="No">No</option> <option value="Yes">Yes</option> </select></td> </tr> <tr> <td>6. Any license suspensions in the past five years?</td><td><select size="1" name="suspensions" tabindex="6"> <option value="No">No</option> <option value="Yes">Yes</option> </select></td> </tr> <tr> <td><label for="explainyes">Explain any yes answers:</label><textarea cols="60" rows="10" wrap="VIRTUAL" maxlength="1000" name="explainyes" tabindex="7"></textarea></td> </tr> <tr> <td><h3>G. Checklist (Please include the following paperwork when submitting to corporate office)</h3></td> </tr> <input type="hidden" value="submit" name="action" /> <input type="hidden" value="<?php echo $agencyid; ?>" name="agencyid" /> <tr> <td><input type="submit" value="Submit" name="submit" tabindex="8" /></td> </tr> </form> </table> <?php } elseif (isset($_POST['adduser'])) { ?> <div id="containerfull"> <div class="left"> <p> <table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td>Employee List</td> </tr> <?php $emplistquery = mysql_query("SELECT * FROM employees WHERE agencyid = '$agencyid'") or die(mysql_error()); while ($emplist = mysql_fetch_array($emplistquery)) { ?> <tr> <td>Name:</td><td><?php echo $emplist['name']; ?></td><td>Title:</td><td><?php echo $emplist['title']; ?></td> </tr> <?php } ?> </table> </p> </div> <div class="clear"> </div> </div> <div id="main"> <div id="containerfull"> <h3>D. Employee Information</h3> <table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <p> <tr> <td>Owner Name</td><td colspan="9"><input type="text" size="50" maxlength="75" name="name" tabindex="1" /></td> </tr> <tr> <td>Employee Type</td><td><select size="1" name="emptype" tabindex="2"> <option value="Owner">Owner</option> <option value="Employee">Employee</option> </select></td> </tr> <tr> <td>% Ownership</td><td> </td><td><input type="text" size="3" maxlength="3" name="ownership" tabindex="2" /></td><td> </td><td>Years In Insurance</td><td><input type="text" size="3" maxlength="3" name="yrsins" tabindex="3" /></td><td> </td><td>Professional Designations</td><td><input type="text" size="25" maxlength="50" name="profdesig" tabindex="4" /></td> </tr> <tr> <td>Resident Address</td><td colspan="8"><input type="text" size="50" maxlength="75" name="resstr" tabindex="5" /></td> </tr> <tr> <td> </td><td>City</td><td><input type="text" size="20" maxlength="45" name="rescity" tabindex="6" /></td><td>State</td> <td> <select tabindex="6" name="resstate" size="1" tabindex="10"> <option value="AL">AL</option> <option value="AK">AK</option> <option value="AZ">AZ</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="CT">CT</option> <option value="DE">DE</option> <option value="DC">DC</option> <option value="FL">FL</option> <option value="GA">GA</option> <option value="HI">HI</option> <option value="ID">ID</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="IA">IA</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="ME">ME</option> <option value="MD">MD</option> <option value="MA">MA</option> <option value="MI">MI</option> <option value="MN">MN</option> <option value="MS">MS</option> <option value="MO">MO</option> <option value="MT">MT</option> <option value="NE">NE</option> <option value="NV">NV</option> <option value="NH">NH</option> <option value="NJ">NJ</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="NC">NC</option> <option value="ND">ND</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OR">OR</option> <option value="PA">PA</option> <option value="RI">RI</option> <option value="SC">SC</option> <option value="SD">SD</option> <option value="TN">TN</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="VT">VT</option> <option value="VA">VA</option> <option value="WA">WA</option> <option value="WV">WV</option> <option value="WI">WI</option> <option value="WY">WY</option> </select> </td><td>Zip</td><td><input type="text" size="10" maxlength="10" name="reszip" tabindex="8" /></td><td>County</td><td><input type="text" size="25" maxlength="45" name="rescounty" tabindex="9" /></td> </tr> <tr> <td>Social Security #</td><td><input type="text" size="11" maxlength="11" name="social" tabindex="10" /></td><td> </td><td>Date Of Birth</td><td><input type="text" size="10" maxlength="10" name="dob" tabindex="11" /></td><td>Home Telephone</td><td><input type="text" size="12" maxlength="12" name="tele" tabindex="12" /></td> </tr> <input type="hidden" value="<?php echo $agencyid; ?>" name="agencyid" /> <td><input type="submit" value="Cancel & Next" name="next2" tabindex="12"/></td><td><input type="submit" value="Add Employee" name="addemp" tabindex="13" /></td><td><input type="submit" value="Next" name="next2" tabindex="14" /></td> </form> </table> <?php } elseif (isset($_POST['submit'])) { ?> <table> <form action="print.php" method="POST"> <tr> <td>Information Submitted</td> </tr> <tr> <td>Print</td><td><select size="1" name="printname" tabindex="1"> <option value="Application">Application</option> <option value="Agreement">Agreement</option></td> </tr> <input type="hidden" value="<?php echo $agencyid; ?>" name="agencyid" /> <input type="hidden" value="submit" name="action" /> <tr> <td><input type="submit" value="Print" name="print" tabindex="2" /></td> </tr> </form> </table> <?php } else { ?> <div id="feature"> <div class="left"> <p> <table> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"> <tr> <td>Field Rep:</td><td><input type="text" size="25" maxlength="40" name="fieldrep" tabindex="1" /></td> </tr> <tr> <td>Type of Agency:</td><td><input type="text" size="25" maxlength="40" name="typeofagency" tabindex="2" /></td> </tr> <tr> <td>Type of Entity:</td><td><input type="text" size="25" maxlength="40" name="typeofent" tabindex="3" /></td> </tr> </table> </p> </div> <div class="right"> <p> <table> <tr> <td align="right">Exclusivity:</td><td><input type="text" size="25" maxlength="40" name="exclusivity" tabindex="4" /></td> </tr> <tr> <td align="right">Former Captive Carrier:</td><td><input type="text" size="25" maxlength="40" name="formcapt" tabindex="5" /></td> </tr> <tr> <td align="right">Contract Date:</td><td><input type="text" size="25" maxlength="40" name="contdate" tabindex="6" /></td> </tr> </table> </p> </div> <div class="clear"> </div> </div> <div id="main"> <div id="containerfull"> <h3>A. Agency Information</h3> <p> <table> <tr> <td>Agency Name</td><td colspan="4"><input name="agencyname" type="text" size="65" maxlength="65" tabindex="6" /></td> </tr> <tr> <td>Physical Address</td><td colspan="2"><input type="text" size="25" maxlength="50" name="physstr" tabindex="7" /></td><td>City</td><td><input type="text" size="25" maxlength="40" name="physcity" tabindex="7" /></td> </tr> <tr> <td> </td><td>State</td><td> <select tabindex="6" name="physstate" size="1" tabindex="8"> <option value="AL">AL</option> <option value="AK">AK</option> <option value="AZ">AZ</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="CT">CT</option> <option value="DE">DE</option> <option value="DC">DC</option> <option value="FL">FL</option> <option value="GA">GA</option> <option value="HI">HI</option> <option value="ID">ID</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="IA">IA</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="ME">ME</option> <option value="MD">MD</option> <option value="MA">MA</option> <option value="MI">MI</option> <option value="MN">MN</option> <option value="MS">MS</option> <option value="MO">MO</option> <option value="MT">MT</option> <option value="NE">NE</option> <option value="NV">NV</option> <option value="NH">NH</option> <option value="NJ">NJ</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="NC">NC</option> <option value="ND">ND</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OR">OR</option> <option value="PA">PA</option> <option value="RI">RI</option> <option value="SC">SC</option> <option value="SD">SD</option> <option value="TN">TN</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="VT">VT</option> <option value="VA">VA</option> <option value="WA">WA</option> <option value="WV">WV</option> <option value="WI">WI</option> <option value="WY">WY</option> </select></td><td>Zip</td><td><input type="text" size="5" maxlength="10" name="physzip" tabindex="9" /></td><td>County</td><td><input type="text" size="20" maxlength="40" name="physcounty" tabindex="10" /></td> </tr> <tr> <td>Mailing Address</td><td colspan="2"><input type="text" size="25" maxlength="50" name="mailstr" tabindex="7" /></td><td>City</td><td><input type="text" size="25" maxlength="40" name="mailcity" tabindex="7" /></td> </tr> <tr> <td> </td><td>State</td><td> <select tabindex="6" name="mailstate" size="1" tabindex="8"> <option value="AL">AL</option> <option value="AK">AK</option> <option value="AZ">AZ</option> <option value="AR">AR</option> <option value="CA">CA</option> <option value="CO">CO</option> <option value="CT">CT</option> <option value="DE">DE</option> <option value="DC">DC</option> <option value="FL">FL</option> <option value="GA">GA</option> <option value="HI">HI</option> <option value="ID">ID</option> <option value="IL">IL</option> <option value="IN">IN</option> <option value="IA">IA</option> <option value="KS">KS</option> <option value="KY">KY</option> <option value="LA">LA</option> <option value="ME">ME</option> <option value="MD">MD</option> <option value="MA">MA</option> <option value="MI">MI</option> <option value="MN">MN</option> <option value="MS">MS</option> <option value="MO">MO</option> <option value="MT">MT</option> <option value="NE">NE</option> <option value="NV">NV</option> <option value="NH">NH</option> <option value="NJ">NJ</option> <option value="NM">NM</option> <option value="NY">NY</option> <option value="NC">NC</option> <option value="ND">ND</option> <option value="OH">OH</option> <option value="OK">OK</option> <option value="OR">OR</option> <option value="PA">PA</option> <option value="RI">RI</option> <option value="SC">SC</option> <option value="SD">SD</option> <option value="TN">TN</option> <option value="TX">TX</option> <option value="UT">UT</option> <option value="VT">VT</option> <option value="VA">VA</option> <option value="WA">WA</option> <option value="WV">WV</option> <option value="WI">WI</option> <option value="WY">WY</option> </select></td><td>Zip</td><td><input type="text" size="5" maxlength="10" name="mailzip" tabindex="9" /></td><td>County</td><td><input type="text" size="20" maxlength="40" name="mailcounty" tabindex="10" /></td> </tr> <tr> <td>Federal Tax ID</td><td colspan="2"><input type="text" size="11" maxlength="11" name="fedtaxid" tabindex="11" />(99-9999999)</td><td>W9 Pay to Name</td><td colspan="2"><input type="text" size="25" maxlength="40" name="w9payto" tabindex="12" /></td> </tr> <tr> <td>Agency License Number</td><td><input type="text" size="15" maxlength="15" name="agencylic" /></td> </tr> <tr> <td>Business Telephone</td><td colspan="2"><input type="text" size="25" maxlength="25" name="bustele" tabindex="13" /></td><td>Business Fax</td><td><input type="text" size="25" maxlength="25" name="busfax" tabindex="14" /></td> </tr> <tr> <td>E&O Carrier</td><td colspan="2"><input type="text" size="25" maxlength="50" name="eocarrier" tabindex="14" /></td><td>Policy #</td><td colspan="2"><input type="text" size="25" maxlength="40" name="eopolnum" tabindex="15" /></td> </tr> <tr> <td>Agency Email Address</td><td colspan="4"><input type="text" size="40" maxlength="50" name="agencyemail" tabindex="16" /></td> </tr> <tr> <td>Website Address</td><td colspan="4"><input type="text" size="60" maxlength="75" name="agencywebsite" tabindex="17" /></td> </tr> <tr> <td colspan="10"><h3>B. Top 5 Carriers You Represent Now, Include Premium</h3></td> </tr> <tr> <td colspan="2">1. <input type="text" size="30" maxlength="45" name="topcar1" tabindex="18" /></td><td colspan="2">$ <input type="text" size="30" maxlength="45" name="topcardol1" tabindex="19" /></td> </tr> <tr> <td colspan="2">2. <input type="text" size="30" maxlength="45" name="topcar2" tabindex="20" /></td><td colspan="2">$ <input type="text" size="30" maxlength="45" name="topcardol2" tabindex="21" /></td> </tr> <tr> <td colspan="2">3. <input type="text" size="30" maxlength="45" name="topcar3" tabindex="22" /></td><td colspan="2">$ <input type="text" size="30" maxlength="45" name="topcardol3" tabindex="23" /></td> </tr> <tr> <td colspan="2">4. <input type="text" size="30" maxlength="45" name="topcar4" tabindex="24" /></td><td colspan="2">$ <input type="text" size="30" maxlength="45" name="topcardol4" tabindex="25" /></td> </tr> <tr> <td colspan="2">5. <input type="text" size="30" maxlength="45" name="topcar5" tabindex="26" /></td><td colspan="2">$ <input type="text" size="30" maxlength="45" name="topcardol5" tabindex="27" /></td> </tr> <tr> <td colspan="10"><h3>Percentage of Business Written</h3></td> </tr> <tr> <td align="right">Personal Lines</td><td>%<input type="text" size="3" maxlength="3" name="perslineper" tabindex="28" /></td><td align="right">Commercial Lines</td><td>%<input type="text" size="3" maxlength="3" name="commlineper" tabindex="29" /></td><td align="right">Life/Health</td><td>%<input type="text" size="3" maxlength="3" name="lifelineper" tabindex="30" /></td> </tr> <tr> <td colspan="10"><h3>C. Carriers to be provided through</h3></td> </tr> <tr> <td colspan="10">1.<select size="1" name="carrier1" tabindex="31"> </select></td> </tr> <tr> <td colspan="10">2.<select size="1" name="carrier2" tabindex="32"> <option selected="selected"></option> </select></td> </tr> <tr> <td colspan="10">3.<select size="1" name="carrier3" tabindex="33"> <option selected="selected"></option> </select></td> </tr> <tr> <td colspan="10">4.<select size="1" name="carrier4" tabindex="34"> <option selected="selected"></option> </select></td> </tr> <tr> <td colspan="10">5.<select size="1" name="carrier5" tabindex="35"> <option selected="selected"></option> </select></td> <tr> <td colspan="10"><h3>ChoicePoint Node ID</h3><input type="text" size="40" maxlength="40" name="choicepoint" tabindex="36" /></td> </tr> </tr> <tr><td><input type="submit" value="Next" name="next1" tabindex="37" /></td></tr> </table> <?php } ?> </p> <div class="clear"> </div> </div> <div class="clear"> </div> </div> Can someone show me the correct code to display a group of checkbox values as part of an if statement? For example: in Programme One, lesson 100, lesson 310 and lesson 102 are available. In Programme Two, lesson 302, lesson 201, and lesson 102 are available. The "lesson types" are a checkbox group. I need to output the lesson types depending on whether they are part of Programme One or Two, along with other variables such as instructor student ratio. I put the following code together where field_lessons is the checkbox group; <?php if ($fieldsObjects['field_type']->data == "Programme One") { print '<p class="details_heading03">Instructor Student Ratio</p>'; echo $fieldsFormatted['field_student_ratio']. '<br />'; foreach ($fieldsObjects['field_lessons']->data as $name => $value) { echo $value; echo "<br/>"; } else { echo "no"; } ?> I have also tried using this statement: <?php if ($fieldsObjects['field_type']->data == "Programme One") { print '<p class="details_heading03">Instructor Student Ratio</p>'; echo $fieldsFormatted['field_student_ratio']. '<br />'; echo (isset($fieldsObjects['field_lessons']->data) && is_array($fieldsObjects['field_lessons']->data)) ? } else { echo "no"; } ?> I am new to php, and I am customising a template which is part of Sobi2, which has been installed as a component of Joomla! (CMS)? Thank you jo My query gets the results and orders by one of the fields. Once I get the MySQL results I would like to find the first entry that has a letter as the first character of the same field that the list was ordered by, then split the results in to two parts and swap them. So that the results that have a letter at the start of the same sorted field are as the begining and the results that have the numbers as the start at the end of the array. But also so that the array works the same way as the original results string, so i can use say $results['mysqlfield'] Code: [Select] <? $out = preg_replace('/^(.{701}[^.]*).*/i','$1.',$detrsltnewsrow[news_desc]); echo $out; ?> </td></tr><tr><td colspan="2" class="para" style="padding-left:10px;"> <?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701) ?> </td></tr> I have the above snippet.. The first php statement, basically grasp the first 701 characters with the closet next stop "." character and out puts it. then out puts the HTML tags I have a problem with the second statement. I want to output anything after what has been outputted by: Code: [Select] <? $out = preg_replace('/^(.{701}[^.]*).*/i','$1.',$detrsltnewsrow[news_desc]); echo $out; ?> So need the correct syntax for Code: [Select] <?= substr(stripslashes(trim($detrsltnewsrow[news_desc])),701) ?> Currently it breaks at exactly the 701 character, want it to continue from the sentence the first code ended in. Hi, I have a website which displays products on product display pages and static pages such as 'contact us'. I am now looking to add a search function which directs to the display page so the products are neatly presented. However, all the tutorials I can find are based on displaying the echo on same page as the search and directing the search to another page. Does anyone know how to do this? I'm new to php and been trying to follow along with different tutorials to try and build my own site, i followed a tutorial on making a search feature for the site and have it working perfectly, but i want to change the way how to search displays the results. I want to make it display them how there displayed on the index page. here is the index page how there displayed <div id="table"> <table> <tr class="top"> <th>Account</th> <th>Country</th> <th>Info</th> <th>Login</th> <th>Pass</th> <th>Price</th> <th>Buy</th> </tr> <?php $class = 'grey'; ?> <?php $items = getItems(); ?> <?php if(empty ($items)): ?> <h3>No Items Found</h3> <?php else: ?> <?php foreach($items as $item): ?> <?php $class = ($class == 'grey') ? 'grey2' : 'grey'; ?> <tr class="<?php echo $class; ?>"> <td><?php echo $item['item_account']; ?></td> <td><?php echo $item['item_country']; ?></td> <td><?php echo $item['item_info']; ?></td> <td><?php echo maskUser($item['item_login']); ?></td> <td><?php echo maskPass($item['item_pass']); ?></td> <td><?php echo $item['item_price']; ?> </td> <td><form method="post" action="https://sci.libertyreserve.com/"><input type="submit" name="buy" value="Buy" class="button" /></form></td> </tr> <?php endforeach; ?> <?php endif; ?> how the search is display if (strlen($search) <= 2) { echo 'Search keyword is too short.'; } else { echo "You searched for <b>$search</b><hr size='1'>"; $search_exploded = explode(" ", $search); foreach($search_exploded as $search_each) { $x++; if ($x == 1) $construct .= "item_account LIKE '%$search_each%'"; else $construct .= " OR item_account LIKE '%$search_each%'"; } $construct = "SELECT * FROM items WHERE $construct"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum == 0) { echo 'No results found.'; } else { echo "$foundnum results found!</p>"; while ($numrows = mysql_fetch_assoc($run)) { $item_id = $numrows['item_id']; $itemAccount = $numrows['item_account']; $itemI = $numrows['item_info']; $itemLogin = $numrows['item_login']; $itemPass = $numrows['item_pass']; $itemPrice = $numrows['item_price']; echo " <b>$itemAccount</b><br /> $itemI <br /> " . maskUser($itemLogin) . '<br />' . maskPass($itemPass, 0) . '<br />'; } } } my question is im not sure how to edit the search code to display the results in the same format as the index page thanks I am seeking to learn more about the noted subject, how to use PHP to allow a user to enter search terms and search a database. I have experimented with this with little results save for errors. Please see code listed below: search.php <? //// filename = search.php <form method="post" action="result.php3"> <select name="metode" size="1"> <option value="row_name1">metode1</option> <option value="row_name2">metode2</option> </select> <input type="text" name="search" size="25"> <input type="submit" value="Begin Searching!!"> </form> ?> results.php //// filename = result.php3 <? $hostname = "mysql7.000webhost.com"; // Usually localhost. $username = "a4542527_root"; // If you have no username, leave this space empty. $password = "*******"; // The same applies here. $usertable = "people"; // This is the table you made. $dbName = "a4542527_test1"; // 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 $metode LIKE '%$search%' LIMIT 0, 30 "); while ($row = mysql_fetch_array($query)) { $variable1=$row["row_name1"]; $variable2=$row["row_name2"]; $variable3=$row["row_name3"]; print ("this is for $variable1, and this print the variable2 end so on..."); } //below this is the function for no record!! if (!$variable1) { print ("$XX"); } //end ?> Upon viewing search.php I receive the error message: Parse error: syntax error, unexpected '<' in /home/a4542527/public_html/search.php on line 3 I believe I may be missing something and am a bit lost. Thank-you in in advance for any help or suggestions. ~Matty Hello everyone, Very new to coding - enjoying it but struggling! I think I'm trying to do something pretty common but I seem to have come up against a complete wall now and after hours/days searching the internet and reading books I'm completely stuck! I'm trying to write some code to search a MySQL database of products, then display the results. For some search results there will be lots of products so I want to display 10 products on the first page then allow visitors to go to the next page to see another 10, and so on - a type of pagination, as they should then be able to click back to see the last page etc. I've got to the point of being able to display the first 10 search results, but I can't figure out at all how to create some kind of page scrolling/pagination system. Please, does anybody have any ideas?? I've attached my code, I hope this is the correct way of doing things here. Many thanks for your time! The PHP search code... Code: [Select] <?php //opens connection to mysql server $dbc = mysql_connect('localhost'); if (!$dbc) { die('Not connected :' . mysql_error()); } echo "Connected to mysql database<br />"; //select database $db_selected = mysql_select_db("NAME_OF_DATABASE", $dbc); if (!$db_selected) { die ("Cannot connect :" . mysql_error()); } echo "Connected to database<br /><hr />"; echo "Here are your results"; $term = $_POST['term']; $category = $_POST['category']; $brand = $_POST['brand_name']; $sql = mysql_query("SELECT * FROM products where product_name like '%$term%' AND category_name like '%$category%' AND brand_name like '%$brand%' LIMIT 0, 10"); { while ($row = mysql_fetch_array($sql)){ echo "<table border='1' width='100%'> "; echo "<tr>"; echo "<td style='vertical-align:top' width='25%'>" . '<img src="', $row['image_url'], '" alt="', $row['product_name'], '" width="100" height="100" />' . "</td>"; echo "<td style='vertical-align:top' width='50%'>" . $row['product_name']; echo "<br />"; echo "<span style='font-size: 10px'>" . $row['description'] . "</span>" . "</td>"; echo "<td style='vertical-align:top' width='25%'>" . $row['price']; echo "<br />"; echo "<br />"; echo "<hr />"; echo "$row['merchant_name'] </td>"; echo "</tr>"; } echo "</table>"; } ?> I have a search page and everything works fine but I would like to add the latest 10 rows to the page so there is something to look at or click on before the user searches. The page is at: www.giantstridedives.com/locations. You can see that it's pretty boring. Hit submit and you'll see the entries so far (only 3 right now). I'd like to have the latest 10 display there by default but then when a user searches they are replaced by the search results. Make sense? Here's the code I'm using for the search: Code: [Select] <?php if (isset($_POST['submit'])) { require_once('dbconnection.php'); mysqli_select_db($conn, $dbname); $searchterm = $_POST['search']; $searchterm = strip_tags($searchterm); $searchterm = trim ($searchterm); $q ="SELECT * FROM locations WHERE loc_name LIKE '%" . $searchterm . "%' AND loc_approved != '0'"; $r = mysqli_query($conn, $q) or die(mysql_error($q)); $row = mysqli_fetch_assoc($r); $rowcount = mysqli_num_rows($r); } ?> <h1>Search for Scuba Dive Locations</h1> <form id="searchform" name="searchform" method="post" action="index.php"> <input type="text" name="search" id="search_bar" /> <input type="submit" name="submit" id="submit" value="Submit" /> </form> <span style="color: #333;">Search for the name of the location, ie: Devils Den or USS Oriskany.</span><br /> <?php if (isset($_POST['submit'])) { if ($rowcount == 0) { echo "Sorry, but we can not find an entry to match your query: <strong>$searchterm</strong>"; } else { //this tells the table below to display since $totalRows_Products_res is not 0 ?> <table style="font-size: 14px;" border="0" width="650"> <tr> <td colspan="6"><p>You searched for <strong><?php echo $searchterm; ?></strong>. Results are displayed below.</p></td> </tr> <tr> <td><strong>Location Name</strong></td> <td><strong>City</strong></td> <td><strong>State</strong></td> <td><strong>Depth (ft)</strong></td> <td><strong>Fees</strong></td> <td><strong>Gear Rentals</strong></td> <td><strong>Map</strong></td> </tr> <?php do { ?> <tr> <td><a href="loc_details.php?loc_id=<?php echo $row ['loc_id']; ?>"> <?php echo $row ['loc_name']; ?> </a></td> <td><?php echo $row ['loc_city']; ?></td> <td><?php echo $row ['loc_state']; ?></td> <td><?php echo $row ['loc_depth']; ?></td> <td>$<?php echo $row ['loc_fee']; ?></td> <td><?php if($row['loc_gear'] == 1) { echo 'Yes'; } else { echo 'No'; } ?></td> <td><a href="http://maps.google.com/maps?q=<?php echo $row ['loc_lat'];?>,<?php echo $row ['loc_lon'];?>" target="_blank">View Map</a></td> </tr> <?php } while ($row = mysqli_fetch_assoc($r)); ?> </table> <?php mysqli_free_result($r); } // this closes out results else } ?> I figure I can use the below query to get the results. Code: [Select] select * from table WHERE id > ((SELECT MAX(id) from table) - 10);I'm just not sure how I can display them by default and then have them be replaced by the search results. Anyone have any ideas for me? As always I appreciate the help as I continue to learn this beast. Say a user puts in a support request, and for every request it generates a unqiue string, and enters it into the database. Ok, now say there is a text field, when the user enters their unique string and it finds a match, it displays the data along with it. How can I accomplish this? Im kind of new to mysql, but I know basic SQL. Would be great if somebody could point me in the right direction! Thanks In the code below, I am trying to produce a google-like page where the user can type keywords and pages of search results are displayed. The main difficulty I am encountering is that when the browser changes pages, it forgets everything about current data. Perhaps I should include the display of pages inside the HTML form ? How can I fix this code ? Here is the contents of my searchpage.php file : <?php $keywords=''; $display_search_results=''; if(isset($_POST['search_submitted'])) { $keywords=$_POST['keywords']; $search_results=array(); $totalNbrOfItems=20; for($k=1;$k<=$totalNbrOfItems;$k++) { $search_results[$k]='Your keywords '$keyowrds.' have been found in item number '.$k; } $nbrOfItemsParPage = 5; $nbrOfPages = ceil($totalNbrOfItems / $nbrOfItemsParPage); // Compute current page $current_page = (isset($_GET['page']))?intval($_GET['page']):1; $display_pages=($nbrOfPages<2)?'<p>Page : ':'<p>Pages : '; for ($i = 1 ; $i <= $nbrOfPages ; $i++) { if ($i == $current_page) //No link to the current page { $display_pages=$display_pages.$i.' '; } else { $display_pages=$display_pages.'<a href="searchpage.php?'. 'page='.$i.'">'. $i . '</a> '; } } $display_pages=$display_pages.'</p>'; $display_items=''; $start=$nbrOfItemsPerPage*($current_page-1); for($k=1;$k<=$nbrOfItemsParPage;$k++) { $display_items=$display_items.($search_results[$start+$k]).'<br>'; } $display_search_results=$display_pages.$display_items; } echo '<form method="post" action="searchpage.php">'. ' Type your keywords here : <br><br>'. '<textarea cols="65" rows="1" '. 'id="keywords_id" name="keywords">'.$keywords.'</textarea>'. '<input type="submit" name="search_submitted" id="search_submitted_id" value="Search" /> '. '</fieldset>'. '</form>'; echo $display_search_results; ?> I am building online dictionary with php. The following code allows the user to search a word and display the definition results from the database. The problem is the user has to input the identical words only. If the words are not exactly similar to the database words it returns error message. But in this case I need it to give a suggestion along with the error message based on the few beginning words of the submitted word. eg. if the user type a word "suggestion", and the word "suggestion" is not available in the database .... instead of just the error message to also search and include other stored data closer to the submitted word ... like "TRY the word SUGGEST". can any one help me on this please. Thank you in advance. here is the code Code: [Select] <?php $script = $_SERVER['PHP_SELF']; if(isset($_POST['sbm']) && isset($_POST['word']) ) { submited(); } else { show_form(); } function show_form() { ?> <p><center> Type <span style='font-weight:bold;'>ENGLISH</span> word Only! <span style='font-weight:bold;'>SPELL IT CORRECTLY!!!.</span></center></P> <p><center>Search</center></p> <center><form name=frm method=POST action="<?php echo $script ?>"> <p><input type=text name="word"><br /></p> <p><input type=submit name="sbm" value="Submit"> </form> </center></p> <?php } function submited() { require("dbconn.inc"); $word=$_POST['word']; $sql="select * from words where eng like '".mysql_real_escape_string($word)."'"; $result=mysql_query($sql,$link); // I assume $link is defined in dbconn.inc if(@mysql_num_rows($result)!=0) { $rows=mysql_fetch_array($result); $am=$rows["am"]; echo("<center>The Word <h1><b>$word</b></h1> in Am is : <h1><b>$am </b></h1><br></center>"); } else { echo("<center><span style='font-weight:bold;color:#FF0000;'>Could not find it! Check the spelling and try again !!</span></center>"); } // The connection will close automatically since // this is near the end of the script. mysql_close($link); show_form(); } ?> The result pages is supposed to have pagination like google help me please
|