PHP - Masking Php Results?
Lets say I have a 'Red Widget' and 'Red Ball' in my database.
At the moment I am searching for: phpproductdisplay.php?description=red - this displays both items. However, if I search for: phpproductdisplay.php?description=red%widget This displays only the red widget which works fine. However, I want to display the search terms on my site and in the title. So at the moment. I am displaying "red%widget". But I want to display "Red Widget". Is it possible to get 'Red Widget'? Similar TutorialsHey guys, This is my first post... hopefully I'll remember my password with the restrictions applied to my usual password but anyway... I've just started using GD to mask two images together and present users the end result and am noticing that it's quite slow and nowhere near as quick as I first expected... Basically I'm devving a game where players explore a map. I'm creating a world map where there are separate transparent images for each terrain type and players can turn these layers on and off on their world map view as they please. On top of this players shouldn't be able to view the raw images as they must first explore the squares to reveal them. So what I have is per player/clan a Fog of war mask image is created and cached per player by querying the database. I then merge this Fog of War mask on top of the terrain pictures to return to the player a picture of each terrain on the map they have explored. <img src="worldmap.php?terrain=1" /> <img src="worldmap.php?terrain=2" /> <img src="worldmap.php?terrain=3" /> Inside worldmap.php the player's session is grabbed so players only ever receive their own fog of war image I originally thought this was going to be a simple put one image on top of the other with transparency to hide pixels they have not yet explored but instead the code snippet I grabbed is a loop that checks each pixel and writes it to a new image. Again I was expecting this to be almost instant but instead it takes about 2-3 seconds per picture and there are about 15 different images being grabbed per player. The images are 501x501 each. At the current rate its looking like I'll also have to cache each of the fow and terrain merged images to deliver them as quick as I wanted. Is this really a slow process or am I doing something wrong? I'll paste some of the PHP to give you an idea of how I'm doing it... function imagealphamask( &$picture, $mask ) { // http://php.net/manual/en/function.imagesavealpha.php // Get sizes and set up new picture $xSize = imagesx( $picture ); $ySize = imagesy( $picture ); $newPicture = imagecreatetruecolor( $xSize, $ySize ); imagesavealpha( $newPicture, true ); imagefill( $newPicture, 0, 0, imagecolorallocatealpha( $newPicture, 0, 0, 0, 127 ) ); // Perform pixel-based alpha map application for( $y = 0; $y < $ySize; $y++ ) { for( $x = 0; $x < $xSize; $x++ ) { $maskColor = imagecolorat( $mask, $x, $y); $maskAlpha = imagecolorsforindex( $mask, $maskColor ); $maskAlpha = floor( $maskAlpha[ 'red' ] / 2 ); $pictureColor = imagecolorat( $picture, $x, $y); $pictureAlpha = imagecolorsforindex( $picture, $pictureColor ); $pictureAlpha = floor( $pictureAlpha[ 'red' ] / 2 ); // Todo: switch colour based on terrain type? // Also respect picture alpha if ($pictureAlpha == 127){ $maskAlpha = 127; } $color = imagecolorsforindex( $picture, $pictureColor ); imagesetpixel( $newPicture, $x, $y, imagecolorallocatealpha( $newPicture, $color[ 'red' ], $color[ 'green' ], $color[ 'blue' ], $maskAlpha ) ); } } // Copy back to original picture imagedestroy( $picture ); $picture = $newPicture; } Thanks alot guys Hi, Im developing a program and it contains bank details in some of the fields stored in the MySQL database. As part of the upload, I need to find bank details and then mask them by replacing them with XXXXXX for security purposes. An example of a field could be "TRANSFER 540021 61782457" and I need to replace to "TRANSFER XXXXXX XXXXX457" Any ideas to the best possible method? Maybe I would mask blocks of numbers (ie numbers in blocks of 6 or 9) to cover this...im not sure what the best possible way is. Thanks! Hi, I am building a website created from a database and I would like to mask the domain, can anyone advise how to do this and the best method. I have also heard that Google disliks PHP query links. This is an link, can I choose what appears in the link? Code: [Select] <a href="product.php?price=<?php echo $row['price']; ?>&discount=<?php echo $row['discount']; ?>&description=<?php echo $row['description']; ?>&awImage=<?php echo $row['awImage']; ?>&link=<?php echo $row['link']; ?>&fulldescription=<?php echo $row['fulldescription']; ?>" class='productlink' rel="nofollow" ><?php echo $row['description']; ?></a> Hi I am trying to mask the url link and have not found a way to do that yet can anyone help please. The reason I want to mask the url is because it is for a users profile page when logged in. The individual users profile page sections is broken up to multiple pages within multiple tabs and each tab content is requested via ajax. So when i hover over each tab it displays the url link eg: http://example.com/user/profilepage1.php etc. Is their a way where i can have it display just nothing when hovering over the tabs. Below is the basic structure for the tabs links if anyone can help I would greatly appreciate it been at this for a coupe of hours and trying to avoid using javascript if possible. Code: [Select] <ul class="nav"> <li><a href="content1.php"><span>tab1</span></a></li> <li><a href="content2.php"><span>tab2</span></a></li> <li><a href="content3.php"><span>tab3</span></a></li> <li><a href="content4.php"><span>tab4</span></a></li> <li><a href="content5.php"><span>tab5</span></a></li> </ul> hi all, Okay, after successfully getting a form to input data to a MySQL database, I'm now trying to get the data back out by searching. Search form code: Code: [Select] <form name="search" method="post" action="process_search.php"> Seach for: <input type="text" name="find" /> in <select name="columns"> <option value="">Please choose one:</option> <option value="status">Status</option> <option value="date">Date</option> <option value="species">Species</option> <option value="breed">Breed</option> <option value="sex">Sex</option> <option value="primary_colour">Primary Colour</option> <option value="colour">Colour</option> <option value="distinctive_traits">Distinctive Traits</option> <option value="fur_length">Fur Length</option> <option value="age">Age</option> <option value="desexed">Desexed</option> <option value="microchipped">Microchipped</option> <option value="suburb">Suburb</option> <option value="pound_area">Pound Area</option> <option value="contact">Contact</option> <option value="link">Link</option> </Select> <input type="hidden" name="searching" value="yes" /> <input type="submit" name="search" value="Search" /> </form> All good there! Form displays how I want it to, and submits correctly. The bit I'm struggling with is the process_search.php side of things. This is what I have (note that i'm trying to get the results into a formatted table and I'd like more results if the match is in more than one column): Code: [Select] <? //Here we display stuff if they have submitted the form if ($searching =="yes") { echo "<h2>Results</h2><p>"; //If they stuffed up and didn't search for anything, we show them this if ($find == "") { echo "<p>Oh, Bianca, you need to enter SOMETHING to search!"; exit; } //If everything is all good, we connect to the database mysql_connect("localhost", "******", "******") or die(mysql_error()); mysql_select_db("******") or die(mysql_error()); //Let's not forget the register globals off crap $status = $_POST['status']; $date = $_POST['date']; $species = $_POST['species']; $breed = $_POST['breed']; $sex = $_POST['sex']; $primary_colour = $_POST['primary_colour']; $colour = $_POST['colour']; $distinctive_traits = $_POST['distinctive_traits']; $fur_length = $_POST['fur_length']; $age = $_POST['age']; $desexed = $_POST['desexed']; $microchipped = $_POST['microchipped']; $suburb = $_POST['suburb']; $pound_area = $_POST['pound_area']; $contact = $_POST['contact']; $link = $_POST['link']; $columns = $_POST['columns']; // We perform a bit of filtering $find = strtoupper($find); $find = strip_tags($find); $find = trim ($find); //Now we search for our search term, in the field the user specified $data = mysql_query("SELECT * FROM animal_info WHERE upper($columns) LIKE'%$find%'"); //And we display the results where($result = mysql_fetch_array( $data )) { echo "<tr>"; echo "<td>".$row['status']."</td>"; echo "<td>".$row['date']."</td>"; echo "<td>".$row['species']."</td>"; echo "<td>".$row['breed']."</td>"; echo "<td>".$row['sex']."</td>"; echo "<td>".$row['primary_colour']."</td>"; echo "<td>".$row['colour']."</td>"; echo "<td>".$row['distinctive_traits']."</td>"; echo "<td>".$row['fur_length']."</td>"; echo "<td>".$row['age']."</td>"; echo "<td>".$row['desexed']."</td>"; echo "<td>".$row['microchipped']."</td>"; echo "<td>".$row['suburb']."</td>"; echo "<td>".$row['pound_area']."</td>"; echo "<td>".$row['contact']."</td>"; echo "<td>".$row['link']."</td>"; echo "</tr>"; } else { echo "ERROR: ".mysql_error(); } //This counts the number or results - and if there wasn't any it gives them a little message explaining that $anymatches=mysql_num_rows($data); if ($anymatches == 0) { echo "Nope, couldn't find anything here! Maybe refine your search criteria?<br><br>"; } //And we remind them what they searched for echo "<b>Searched For:</b> " .$find; } ?> Trouble with this is that I'm not getting any errors OR results! ANY help would be appreciated HUGELY! Cheers, Dave I am testing live and the data is downloading to the database but when it goes to the next page it gets this message. Warning: Wrong parameter count for mysql_result() in /home/ebermy5/public_html/html/login.php on line 25 Could not execute query THIS IS MY CODING ANY IDEAS WHERE I AM GOING WRONG. YES I HAVE THE OPEN AND CLOSE PHP? if (@$_SESSION['auth'] != "yes") @include('Connections/connect_to_mysql.php'); $query = "SELECT firstName, lastName FROM `Members` WHERE email='{$_SESSION['id']}'"; $result = mysql_result($query) or die("Could not execute query"); echo "<html> <head><title>New Member Welcome</title></head> <body> <h2 style='margin-top: .7in; text-align: center'> Welcome $firstName </h2>\n"; Hi, I have a problem if users search something which doesn't match the data in the table I'm selecting from. At the moment I'm trying this code: Code: [Select] <?php require_once('inc/global.inc.php'); # search.inc.php /* * This is the search content module. * This page is included by index.php. * This page expects to receive $_GET['terms']. */ // Redirect if this page was accessed directly: if (!defined('BASE_URL')) { // Need the BASE_URL, defined in the config file: require_once ('../includes/config.inc.php'); // Redirect to the index page: $url = BASE_URL . 'index.php?p=search'; // Pass along search terms? if (isset($_GET['terms'])) { $url .= '&terms=' . urlencode($_GET['terms']); } header ("Location: $url"); exit; } // End of defined() IF. // Print a caption: echo '<h2>Search Results</h2>'; // Display the search results if the form // has been submitted. if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { $terms = $_GET['terms']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server'); // Query the database. $query = "SELECT * FROM product WHERE title LIKE '%$terms%'"; // Fetch the results. //$row = mysqli_fetch_array($result); // Print the results: $result=mysqli_query($dbc,$query); if ($result == 0){ echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } while($row=mysqli_fetch_assoc($result)) { $output[] = '<ul>'; $output[] = '<li>'.$row['title'] .': £'.$row['price'].'<br /><img src="'.$row['img'].'" alt="'.$row['title'].'" /></li>'; $output[] = '</ul>'; } echo join('',$output); } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search this site.</p>'; } ?> But I'm getting this error: Object of class mysqli_result could not be converted to int So that little if statement here doesn't work: Code: [Select] if ($result == 0){ echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } Is there another way I can display no search matched results? Thank you for reading, Andrew. Lets say I have an array of different values... for example, $alreadyViewed = array("hi.jpg","cow.jpg","dog.png"); Lets say my database contains: Code: [Select] animals.jpg cat.jpg cow.jpg hi.jpg dog.png How do you I tell MySQL to only fetch the remaining entries? And ignore everything in the $alreadyViewed array? My aim is for this what if the table is empty which means no results will be retrieved in the first query then I want it to repeat the $testArray as "TBD" as well. Code: [Select] function getTop5() { $this->db->select('character1_id, character2_id, character3_id, character4_id, character5_id'); $this->db->from('site_top5'); $this->db->where('status_id', '1'); $this->db->order_by('id', 'desc'); $query = $this->db->get(); $row = $query->row(); $ids = array( $row->character1_id, $row->character2_id, $row->character3_id, $row->character4_id, $row->character5_id ); $testArray = array(); foreach ($ids as $id) { if($id !== "0") { $this->db->select('character_name'); $this->db->from('characters'); $this->db->where('id', $id); $query = $this->db->get(); $row = $query->row(); $testArray[] = $row->character_name; } else { $testArray[] = "TBA"; } } return $testArray; } Can someone please give me some ideas as to what might be wrong with this query...I keep getting no result and am echoing $count for debugging (and usernames and passwords) but get nothing for $count (expecting a 0 or a 1) or $dbusername or $dbpassword $sql="SELECT * FROM `users` WHERE `User name` = '$fusername' and `Password` = '$fpassword'"; $result=mysql_query($sql); $dbusername=mysql_result($result,0,"User name"); $dbpassword=mysql_result($result,0,"Password"); echo $dbusername; echo $dbpassword; // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $fusername and $fpassword, table row must be 1 row echo $fusername; echo $fpassword; echo $count; if($count==1){ (This is where I keep going to the else) hi friends. to fetch results from the database i made a function and how i call the function on a page like $results = GetResults($someID); when i print_r the $results i get all the results, but now im confused on how do i print the rows individually? say i got Title row how will i only get the Title row from the $results VAR? Code: [Select] <?php $going=''; $name='<span id="name"></span>'; echo "$name"; //results : stevengoh --- wanted $going=substr($name, 1, 17); echo "$name"; //results : <span id="going"> ---- don't want ?> Is it possible to store in php the results of variable id="going" javascript instead of <span id="going"></span>?. What I expect: - The function to loop output all of the rows which match the search results. The problems: - Only 1 row is matched. - Notice: Undefined index: id in G:\xampp\htdocs\xampp\dsa\search_func.php on line 57 - The image is not showing Line 57: Code: [Select] $id = $_REQUEST['id']; Entire Code: Code: [Select] <?php /* return the details of an employee parameter empno - employee number eg empHTML.php?empno=7521 This is very basic e.g no error checking */ function search($dbc, $id) { if (isset($_GET['terms']) && ($_GET['terms'] != 'Search...') ) { $terms = $_GET['terms']; $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) or die *('Error connecting to MySQL server'); $query = "SELECT * FROM stick, location, identification WHERE make LIKE '%$terms%' AND stick.sid = location.lid AND identification.stickID = stick.sid AND identification.stickID = $id"; $result=mysqli_query($dbc,$query); $num_rows = mysqli_num_rows($result); $output = Array(); $image = mysqli_fetch_object($result); if ($num_rows > 0){ if($result=mysqli_query($dbc,$query)){ $output[] = '<ul>'; $output[] = '<li> Type: '.$image->make .'<br />Size: '.$image->size .$image->type .'<br />Colour: '.$image->colour . '<br /> Street Missing in: ' .$image->street.'<br />Town missing in: '.$image->town .'<br />City missing in: '.$image->city.'</li>'; $output[] = '</ul>'; } return join('',$output); } else { echo "<h3>Sorry,</h3>"; echo "<p>your search: "" .$terms. "" returned zero results</p>"; } } else { // Tell them to use the search form. echo '<p class="error">Please use the search form at the top of the window to search this site.</p>'; } } // connect $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // get the id from the URL $id = $_REQUEST['id']; print search($dbc, $id); print "<img src='getPhoto.php?id=$id'/>"; // close the database mysqli_close($dbc); I have a variable called clientid being passed via a url. I place that in a variable called $clientid I have two tables, client and web_info I want to select all from client and web_info for the appropriate clientid. I may not have my tables set up correctly. The primary key on the table client is auto genereated and titled client_id the primary key on web_info is e_mail and I want to pull information from the table web_info where the e_mail columns match. Below is my PHP: $query = "SELECT * FROM client WHERE $clientid = client_id and FROM web_info WHERE client.e_mail = web_info.e_mail"; $result = mysqli_query($connection,$query); $row = mysqli_fetch_array($result); I know I probably screwed all this up but please help hello, is there a wat to limit the following to only the first 25 characters? $customername=$row1["customer"]; thanks I have this code and Im using a while to fetch all the data where users comments are but i want to change it to fetch only 25 rows at a time and each time it refreshes it fetch's 25 more different rows. Code: [Select] <?php include "../../connect.php"; Header('Cache-Control: no-cache'); Header('Pragma: no-cache'); $username = mysql_real_escape_string($_GET['username']); //If friend is set, then query for it, otherwise return all of the friends comments. $friend = (isset($_GET['friend'])) ? ' AND b.friend = \'' . mysql_real_escape_string($_GET['friend']) . '\' ' : NULL; $sql = "SELECT a.username,a.comment,a.timestamp,a.title,a.picture,a.pic_status,a.pic_url,b.id,c.avatar,c.atimestamp,c.onlinestatus FROM (user_comments as a JOIN accounts as c USING(username))JOIN `user_friends_list` as b ON (b.friend = a.username)WHERE (b.username = '$username' $friend AND b.status = 1) ORDER BY a.id DESC"; $result = mysql_query($sql); $user_xml = "<?xml version=\"1.0\"?>\n"; //$user_xml .= "<root>\n"; if(mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $user_xml .= "<comment>\n"; $user_xml .= "<image>" . $row['avatar'] . "</image>\n"; $user_xml .= "<name>" . $row['username'] . "</name>\n"; $user_xml .= "<text>\n"; $user_xml .= "<![CDATA[ ". $row['comment'] ."]]>\n"; $user_xml .= "</text>\n"; $user_xml .= "<time>" . $row['timestamp'] . "</time>\n"; $user_xml .= "<title>" . $row['title'] . "</title>\n"; $user_xml .= "<picture>" . $row['picture'] . "</picture>\n"; $user_xml .= "<status>" . $row['pic_status'] . "</status>\n"; $user_xml .= "<url>" . $row['pic_url'] . "</url>\n"; $user_xml .= "<ntimestamp>" . $row['atimestamp'] . "</ntimestamp>\n"; $user_xml .= "<online>" . $row['onlinestatus'] . "</online>\n"; $user_xml .= "</comment>\n"; } } //$user_xml .= "</root>\n"; echo $user_xml; ?> So i think i can do something like this but im not to sure. just add a if statement Code: [Select] while ($row = mysql_fetch_assoc($result)) { $user_xml .= "<comment>\n"; $user_xml .= "<image>" . $row['avatar'] . "</image>\n"; $user_xml .= "<name>" . $row['username'] . "</name>\n"; $user_xml .= "<text>\n"; $user_xml .= "<![CDATA[ ". $row['comment'] ."]]>\n"; $user_xml .= "</text>\n"; $user_xml .= "<time>" . $row['timestamp'] . "</time>\n"; $user_xml .= "<title>" . $row['title'] . "</title>\n"; $user_xml .= "<picture>" . $row['picture'] . "</picture>\n"; $user_xml .= "<status>" . $row['pic_status'] . "</status>\n"; $user_xml .= "<url>" . $row['pic_url'] . "</url>\n"; $user_xml .= "<ntimestamp>" . $row['atimestamp'] . "</ntimestamp>\n"; $user_xml .= "<online>" . $row['onlinestatus'] . "</online>\n"; $user_xml .= "</comment>\n"; } I only wnat to read 25 comments at a time and when i click a button to read more then it reads 25 more rows but it dose not read the data unless requested... can any one help me? quick question, I have this code that returns over 100 buttons: Code: [Select] <?php // Query member data from the database and ready it for display $sql = mysql_query("SELECT * FROM products"); while($row = mysql_fetch_array($sql)){ $product = $row["product"]; $id =$row["id"]; $price =$row["price"]; ?> <div id="products"> <form action="" method="POST" name="myform<?php echo $id; ?>" class="myform<?php echo $id; ?>"> <input type="hidden" name="hiddenField" class="hiddenField" value="<?php echo $product; ?>" /> <input type="hidden" name="hiddenField2" class="hiddenField2" value="<?php echo $id; ?>" /> <input type="hidden" name="hiddenField1" class="hiddenField1" value="<?php echo $price; ?>" /> <input type="submit" name="submit" class="submit" value="<?php echo $product; ?>" style="background-color:lightgreen; height:50px; width:100px;"> </form> </div> <?php } ?> What I would like is for the buttons to form columns of nine. ie 9 buttons in a column then a new column form.... how do I do this? Hi Just a quick one. I want my output result to look like this. In its simplistic form I have 2 columns, NAME and NUMBER. Adam 1 2 3 Becky 1 2 3 Charlie 1 2 3 So the output results are grouped by the "name" field, then ordered by the "number" field. I thought it was GROUP BY, but that function is something else. Iv tried searching around but im unsure what you call this form of grouping results. Many Thanks! I am trying to write a script that will allow me visitors to my site to search my database for items. I followed a tutorial that I had found and tweaked it to fit my needs. I am not getting any results it keeps telling that there was no search results found. Even though I have the items that I have been testing on in my database. I have two files the main search.php file and the search_func.php file Here is the search.php file Code: [Select] <form method='post' action='search.php'> <fieldset> <input type='text' name='search' id='search' value='type name here'/> <input type='submit' name='search_submit' id='search_submit' value='search'/> </fieldset> </form> <?php include('includes/search_func.php'); if(isset($_POST['search'])) { $keywords = mysql_real_escape_string(htmlentities(trim($_POST['search']))); $errors = array (); if (empty($keywords )){ $errors[] = 'Please enter a search term'; } else if (strlen($keywords ) < 3 ) { $errors[] = 'Search term must be more then three characters long'; } else if (search_results($keywords == false)) { $errors[] = 'Your search for ' .$keywords . ' showed no results'; } if (empty($errors)) { $results = search_results($keywords ); $results_num = count($results); $suffix = ($results_num != 1) ? 's' : ''; echo 'Your search for <strong>'. $keywords .'</strong> returned <strong>' .$results_num.'</strong> result'.$suffix.''; foreach($results as $result) { echo $result['first']; } } else { foreach($errors as $error){ echo $error; } } } ?> Here is the search_func.php file Code: [Select] <?php include('includes/config.php'); connect(); function search_results($keywords ) { $returned = array(); $where = ""; $keywords = preg_split('/[\s+]/', $keywords ); $total = count($keywords ); foreach($keywords as $key=>$keyword) { $where .= "`l_name` LIKE '%$keyword%'"; if($key != ($total - 1)){ $where .= "OR"; } } $results = "SELECT `l_name`,`f_name`,`image`,`item_return` FROM `ttmautos` WHERE $where"; $results_num = ($results = mysql_query($results)) ? mysql_num_rows($results): 0 ; if ($results_num === 0) { return false; } else { while($results_row = mysql_fetch_assoc($results)) { $returned_results[] = array( 'last' => $results_row['l_name'], 'first' => $results_row['f_name'], 'image' => $results_row['image'], 'item' => $results_row['item_return'] ); } return $returned_results; } } ?> If anyone could give me an idea of what I am doing wrong I would appreciate it. |