PHP - Is It Possible To Display An Obscured Value From A Mysql Database?
I want to make a "hint" feature for an app ive been working on. Its a guessing game, and I want to be able to give out hints.
Ok so say there is an answer in the database. Say the value is "firetruck". I want to retrieve that value, and obscure it, displaying only one or two letters that are in the word. Or, for a number, say 178, I want to display only one digit from it. Is this possible? Im sure it is, anything seems possible with PHP & Mysql. If so, how could I implement this? Trust me, I read the manuals. The manuals for both PHP and Mysql are so vast and a little advanced for my level.. then again im not complete novice and know the basics plus more of both. Similar Tutorialsim making a game and i need to show a users money but i dont know how help? I have got connection to the the mysql database, how do I get the data from the database to display on the webpage Hi there. I have this simple code which displays 5 results. How can i grab each element separately instead of displaying all the results at once. Thanks:) Code: [Select] <?php $query = mysql_query("SELECT product_name, product_price FROM products WHERE product_type = 'laptop' LIMIT 5"); $numrows = mysql_num_rows($query); if ($numrows != 0) { while ($row = mysql_fetch_assoc($query)) { $product_name = $row['product_name']; $product_price = $row['product_price']; echo $product_name . '<br />'; echo $product_price . '<br /><br />'; } } ?> Hi, here's my problem: I am trying to make a simple online buying website and I want to display a table with all the fields for each item. So I got that part down which is to just use mysql_fetch_assoc("SELECT * FROM myTable") and use the html table tags stuff, but now I want to display my images in the table, so here's my code to display my mysql database table in html's table tag along w/ php: <html> <head> <title>My Online buying website project</title> </head> <body> <?php mysql_connect("localhost","root"); mysql_select_db("myTable"); $imagesArray=array("Apple_iPhone3GS.jpg","Apple_iPhone4.jpg","product3.jpg","product4.jpg","product5.jpg"); $result=mysql_query("SELECT Name, Manufacturer, Price, Description, SimSupport FROM myTable"); if(mysql_num_rows($result))//if there is at least one entry in bellProducts, make a table { print "<table border='border'>"; print "<tr> <th>Name</th> <th>Manufacturer</th> <th>Price</th> <th>Description</th> <th>SimSupport</th> </tr>"; //NB: now output each row of records while($row=mysql_fetch_assoc($result)) { extract($row); print "<tr> <td>$Name</td> <td>$Manufacturer</td> <td>$Price</td> <td>$Description</td><td>$SimSupport</td> </tr>"; }//END WHILE }//END IF ?> </table> </body> </html> *So how do I go about adding my images in this table? 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 i have 8 division (div), i want to display 4 rows in 4 division and the remain 4 rows in the next 4 division here is my code structure for carousel
<div class="nyie-outer"> second row third row
fourth row fifth row sixth row seven throw eighth row
</div><!--/.second four rows here-->
sql code
CREATE TABLE product( php code
<?php how can i echo that result in those rows
How do I do I prevent a broken image icon if there is no image? Here is my code: Code: [Select] <?php if ($_POST){ $county = $_POST['county']; } $con = mysql_connect("localhost","",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("", $con); $imageLocation = $row['imageurl1']; $result = mysql_query("SELECT * FROM places WHERE `county` = '".mysql_real_escape_string($county)."' order by `date_created` DESC"); if ( mysql_num_rows($result) > 0 ) { echo "<strong>Click Headers to Sort</strong>"; echo "<table border='0' align='center' bgcolor='#999969' cellpadding='3' bordercolor='#000000' table class='sortable' table id='results'> <tr> <th> Title </th> <th> Borough </th> <th> Town </th> <th> Phone </th> <th> Rooms </th> <th> Bath </th> <th> Fees </th> <th> Rent </th> <th> Image </th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr> <td bgcolor='#FFFFFF' style='color: #000' align='center'> <a href='classified/places/index.php?id=".$row['id']."'>" . $row['title'] . "</a></td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['county'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['town'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['phone'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rooms'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['bath'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['feeornofee'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'>" . $row['rent'] . "</td> <td bgcolor='#FFFFFF' style='color: #000' align='center'><img src=user/". $row['imageurl1'] ." width='50'></td> </tr>"; } echo "</table>"; print_r($apts); } else { echo "<p> </p><p> </p> No Results <br /><p> </p><FORM><INPUT TYPE='button' VALUE='Go Back' onClick='history.go(-1);return true;'></FORM> and Refine Your Search <p> </p><p> </p>"; } ?> Thanks in advance At the moment I am creating a search function for my website. The approach I have in mind is a pseudo-PHP database. To give an example: A HTML form will submit the results to a PHP file. HTML FORM - Colour: Black PHP RESULT PAGE - if ($_POST['color'] == 'Black') {readfile("./products/black/*.html");} HTML FORM - Price: <$50 PHP RESULT PAGE - if ($_POST['Price'] == '<$50') {readfile("./products/less50/*.html");} The problem here is if there is an item that is black and costs less than $50, then its going to be listed twice. There is probably some code I can write to ommit the listing of duplicate entries, but it is probably going to be messy, so I am wondering if its better to use a centralized MySQL database, rather than a pseudo-PHP database? I've never used MySQL and don't know much about it and this is my first real attempt at using PHP. Hello i have a SQL db that has some Empty Rows in it .... I Had used a if else statement to make it display N/A If the answer is different than it should be like this <?php if ($string) {echo $string} else {echo"N/A"};?> but i think there are better ways of doing this Can anyone teach me how may i do it? Edit: it should be a way to see if the db row value is empty/null :| Hello, I recently came upon this website and I want to implement something similar. The 'remove' box is what I would like to do with PHP. I have no idea where to start. I would like to be able to search through my database, select one of its components and add it to that window. Within that window I would also like to be able to remove it. Does anyone know where I should go from there? here is the site: http://www.sealandserpent.org/schedgen/schedulegenerator.php I'm writing a highscore board for a game and I can only display one value from a DB... I don't know what I could be doing wrong. I've done this kind of DB work before. <?php $name = $_GET['lvl']; if($_GET['lvl']=="Strength"){ //1/21 $skill = "strlvl"; $exp = "strexp"; } else if($_GET['lvl']=="Attack"){ //2/21 $skill = "atklvl"; $exp = "atkexp"; } else if($_GET['lvl']=="Defence"){ //3/21 $skill = "deflvl"; $exp = "defexp"; } else if($_GET['lvl']=="Hitpoints"){ //4/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Range"){ //5/21 $skill = "rglvl"; $exp = "rgexp"; } else if($_GET['lvl']=="Magic"){ //6/21 $skill = "mglvl"; $exp = "mgexp"; } else if($_GET['lvl']=="Hitpoints"){ //7/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Prayer"){ //8/21 $skill = "prlvl"; $exp = "prexp"; } else if($_GET['lvl']=="Runecraft"){ //9/21 $skill = "rclvl"; $exp = "rcexp"; } else if($_GET['lvl']=="Slayer"){ //10/21 $skill = "sllvl"; $exp = "slexp"; } else if($_GET['lvl']=="Thieve"){ //11/21 $skill = "thlvl"; $exp = "thexp"; } else if($_GET['lvl']=="Agility"){ //12/21 $skill = "hplvl"; $exp = "hpexp"; } else if($_GET['lvl']=="Firemaking"){ //13/21 $skill = "fmlvl"; $exp = "fmexp"; } else if($_GET['lvl']=="Woodcut"){ //14/21 $skill = "wclvl"; $exp = "wcexp"; } else if($_GET['lvl']=="Cooking"){ //15/21 $skill = "cklvl"; $exp = "ckexp"; } else if($_GET['lvl']=="Herblore"){ //16/21 $skill = "hblvl"; $exp = "hbexp"; } else if($_GET['lvl']=="Mining"){ //17/21 $skill = "mnlvl"; $exp = "mnexp"; } else if($_GET['lvl']=="Farming"){ //18/21 $skill = "frmlvl"; $exp = "frmexp"; } else if($_GET['lvl']=="Fishing"){ //19/21 $skill = "fshlvl"; $exp = "fshexp"; } else if($_GET['lvl']=="Smithing"){ //20/21 $skill = "smlvl"; $exp = "smexp"; } else if($_GET['lvl']=="Fletching"){ //21/21 $skill = "fltlvl"; $exp = "fltexp"; } else if($_GET['lvl']==""){ //0/21 echo "<center><br /><br />No skill selected!</center><br />"; } mysql_connect("mysql", "15557_test", "**************") or die("Could not connect: " . mysql_error()); mysql_select_db("15557_test"); //STARTS HERE $result = mysql_query("SELECT playerName, $skill, $exp FROM skills ORDER BY $exp ASC LIMIT 5000"); while ($row = mysql_fetch_array($result, MYSQL_NUM)) { echo"Skill: " . $name . "<br />"; printf("Player: %s - Rank: %s - EXP: %s<br />", $row[0],$row[1],$row[2]); mysql_free_result($result //ENDS HERE } ?> I'm trying to simply display the contents of an entire database for the purpose of building an administrative super-user into the back-end to remove login credentials without having to resort to having to manually interact with Mariadb or PHPmyadmin. However, the code is only returning the last row that was entered into the database. I can't seem to figure out why it's not working as intended. The code is intended to simply display the entire contents of the database into an html table. The code i'm using: <?php $link = mysqli_connect("127.0.0.1", "database user", "password", "login"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } if ($result = mysqli_query($link, "SELECT * FROM accounts", MYSQLI_STORE_RESULT)) { while ($row = $result->fetch_assoc()) { $id = $row["id"]; $username = $row["username"]; $pass = $row["password"]; $email = $row["email"]; $su = $row["su"]; } } mysqli_close($link); ?> <!DOCTYPE html> <html> <head> </head> <body> <table> <tr> <th>id</th><th><th>user name</th><th>password</th><th>email</th><th>elevated privlege</th></tr> <tr> <td> <?php echo $id; ?> </td> <td> <?php echo $username; ?> </td> <td> <?php echo $pass; ?> </td> <td> <?php echo $email; ?> </td> <td> <?php echo $su; ?> </td> </tr> </table> </body> </html> Edited August 31, 2020 by bakertaylor28 correction of the code used. I'm currently trying...struggling....to teach myself PHP and I'm really bugged with this database stuff. I am slowly managing but I'm a tad bit stuck now. I want to show a specific piece of information from a table. Lets say my table is structured like so: id user email 1 Bob Bob@Name.com 2 Fred Fred@Name.com 3 Matt Matt@Name.com What would I need to do to display ONLY Freds user? One way I tried only displayed the first rows info (Bob) the second way I tried (with a while loop) only displayed the last rows info (Matt) Heres my current code: <html> <body> <?php include 'dbwire.php'; $query = mysql_query('SELECT * FROM user'); $row = mysql_fetch_array($query); while ($row = mysql_fetch_array($query)) { echo '<b>User:</b> ' . $row['user'] . '<br />'; } ?> </body> </html> <?php require_once('upper.php'); require_once('database.php'); if(isset($_COOKIE['LoginIdCookie'])) { echo '<h4>Welcome '.$_COOKIE['LoginIdCookie'].'</h4>'; } else{ echo '<h4>Events</h4>';} $result=mysqli_query($dbc,"select * from events") or die('Not Connected'); echo "<html> <body>"; echo "<form method='post' action='EventParticipator.php'>"; echo "<u><h4>Please tick events in which you want to participate</h4></u>"; /*echo "<table cellspacing='0' cellpadding='15'> <th><b>Event Title:</b></th> <th ><b>Event City:</b></th> <th><b>Content:</b></th> <th><b>Images:</b></th> <th><b>Event Date:</b></th>";*/ //while($row=mysqli_fetch_array($result)) $row=mysqli_fetch_array($result); for($i=0;$i<5;$i++) { $Title=$row['Title']; $City=$row['City']; $Content=$row['Content']; //$Photo=$row['Photo']; $Date=$row['Date']; $EventId=$row['EventId']; $Photo=$row['Photo']; //echo $Photo; echo "<tr><td><img src='$Photo' width='120' height='90'/></td><td>$City</td><td>,</td><td>$Date</td><td>:</td><td>$Title</td></tr> <tr><td>$Content</td></tr> <tr><td><a href='#'>Know more</a></td><td>/</td><td><a href='#'>Click here to participate</a></td></tr>"; } //echo "<tr><td><input type='submit' name='submit' value='Participate'</td>"; if(isset($_COOKIE['LoginIdCookie'])) { echo "<td><a href='log_out.php'>Log out</a></td>"; echo "<td><a href='EditActivity.php'>Edit Your Activities</a></td></tr>"; } echo "</table></form></body></html>"; require_once('lower.php'); ?> Quote Hi friends .......... I write above code to display top 5 rows from the database but it not works properly. It displays first row 5 times which is undesireable. Anyone please help????????????????? thanks in advance.................. Hi, Would someone please give me some assistance on how to display random products from my database I need to display a maximum of 6 images and there link in two rows of 3 so; [image] [image] [image] [image] [image] [image] and each image would have something like; <a href="<? echo $row['product_link'] ?>"><img src="<? echo $row['product_image'] ?>"/></a> but i don't know how to display these at random and make sure only 6 appear at a time. Thanks for any help, hope you understand what im trying to explain <?php require_once('upper.php'); require_once('database.php'); require_once('LoginStatement.php'); $LoginId=$_COOKIE['LoginIdCookie']; $query="select * from activity_participation where LoginId='$LoginId'"; $result=mysqli_query($dbc,$query) or die ('Not Connected'); //echo "<div class='search_output_data'> echo "<table border='0' cellspacing='0' cellpadding='0'>"; while($row=mysqli_fetch_array($result)) { echo "<tr><th align='left' valign='top'>Activity Title</th> <th align='left' valign='top'>Date of Participation</th> </tr> <tr><td colspan='4' align='left' valign='top'><table align='left' border='0' cellspacing='0' cellpadding='0'><tr><td align='left' valign='top'>".$row['Title']."</td> <td align='left' valign='top'>".$row['Date']."</td> </tr></table> </td></tr>"; } echo "</table>"; //echo "</div>"; require_once('lower.php'); ?>In table activity_participation many rows have same values. I want to display only different rows to user not to display same rows again and again. Or Anybody have idea to prevent the row duplication in database.... Help me please......... thanks in advance............. Hi guys its me again, I am having a problem that I cant figure out... Here is my code: <?php $sqlCommand = "SELECT image FROM background"; $query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error()); $sqlCommand2 = "SELECT backgroundimage FROM site"; $query2 = mysqli_query($myConnection, $sqlCommand2) or die (mysqli_error()); while ($row = mysqli_fetch_array($query)) { while ($row2 = mysqli_fetch_array($query2)) { if($row['image'] == $row2['backgroundimage']){ echo '<img src="site_background/'.$row['image'].'" width="75px" height="75px" style="border:2px solid red;" /><br /><br />'; } if($row['image'] != $row2['backgroundimage']){ echo '<img src="site_background/'.$row['image'].'" width="50px" height="50px" style="border:2px solid black;" />'; } } } mysqli_free_result($query); mysqli_free_result($query2); ?> What is will do is get the images from the "backgrounds" table and the image from the "site" table (the current image). I am then wanting to pick out the current image and give it a red border and then display the other left over images smaller with a black border. I can get the images to all display with the black border or the current image to display with a red border but the other images dont show... I have tried mixing things around but I have not been able to get all the images to display with the formatting I want. I dont know if it is a simple syntax error or I am doing things completely wrong... I have been looking at it for so long its just become one big mess of code to me lol Any help to get this working as I want would be great! Cheers Ben This is my code is display my database (member_details) after user sign up but when a user register first name = <script>window.location="google.com"</script> This error occur=(The requested URL /yy2/html/google.com was not found on this server) Code: [Select] <?php session_start(); include ('includes/database_connection.inc.php'); $conn = connectDatabase(); if($_SESSION['uid'] == ''){ // redirect unauthenticate user to login page. header('Location: login.php'); } if($_GET['task'] == 'delete' && $_GET['id'] != ''){ // delete function here $sql="DELETE FROM Newest Where ID='".mysql_real_escape_string($_GET['id'])."'"; mysql_query($sql,$conn); header('Location: member_list.php'); } if($_POST['Logout']){ session_destroy(); header('Location: login.php'); } ?> <html><head><title>Member Details</title> </head> <body> <div style=" margin: 350px "> <?php $sql="SELECT * FROM Newest"; $rs = mysql_query($sql,$conn) or die( mysql_error() ); $list = "<table border=\"1\" cellpadding= \"2\">"; $list .= "<tr><th>First Name</th>"; $list .="<th>Last Name</th>"; $list .= "<th>User Name</th>"; $list .= "<th>Email</th>"; $list .= "<th>Edit User</th>"; $list .= "<th>Delete User</th>"; $list .= "<th>Change Password</th>"; While( $row = mysql_fetch_array($rs) ) { $list .= "<tr>"; $list .= "<td>".$row["name"]."</td>"; $list .= "<td>".$row["last"]."</td>"; $list .= "<td>".$row["user"]."</td>"; $list .= "<td>".$row["email"]."</td>"; $list .= "<td><a href='member_details.php?id=".$row['ID']."'>Edit</a></td>"; $list .= "<td><a onclick='return confirm(\"Are you sure to delete ".$row["name"]." \")' href='member_list.php?id=".$row["ID"]."&task=delete'>Delete</a></td>"; $list .= "<td><a href='Password.php?id=".$row['ID']."'>Click Here</a></td> </tr>"; } $list .= "</table>"; echo ( $list ); ?> <form method="post" action="member_list.php"><br> <div style="margin : 0px 600px"> <style type="text/css"> body {background:#F5F5F5 url('http://images.apple.com/downloads/dashboard/travel/images/traveltodolist_20070724165034.jpg') no-repeat top;; }</style> <input type="submit" name="Logout" value="logout" /> </form> </body> </html> MOD EDIT: [code] . . . [/code] BBCode tags added. Hello. I want to display all photos from the database. The problem is that it displays nothing. I added a foreach loop in html but further it not display. I'am beginner, I hope someone help me where I make mistake. I care about separation logic from view.
class photo_display { private $database; private $userData; public function __construct($database) { $this->database = $database; } public function display() { $query = $this->database->connect()->prepare("SELECT photo FROM photo"); $query->execute(); if ($query->rowcount()) { $row = $query->fetchAll(); } $this->userData = $row; } public function display_Photos(string $colName) { return (isset($this->userData[$colName])) ? $this->userData[$colName] : []; } } <div class='container-fluid bg-dark' id='profil'> <div class='row'> <div class=" col-12 col-sm-12 col-md-4 col-lg-4 col-xl-4 order-5 order-12 order-6 order-md-4"> <div class="row" id="margin"> <div class="col-xl-12 d-flex justify-content-center" id="test"> <?php foreach ($photo_display->display_Photos('photo') as $value) { ?> <img src ="<?php echo var_dump($value) ?>" />; <?php } ?> </div> </div> </div>
|