I have a database and I am trying to display data from the table all in one box.
I am not sure if there is another way besides tables but I am trying to do something like this.
I am using roblox as an example.
Example:
Right now this is my code for the table.
<div class="row2">
<div class="column">
<?php
include_once("includes/config.php");
$sql = "SELECT * FROM communities";
$result = $conn->query($sql);
if ($result->num_rows > 1) {
while($row = $result->fetch_assoc()) {
echo '<hr />';
echo '<table>';
echo '<tr><td>Name: </td><td>'.$row["name"].'</td></tr>';
echo '<tr><td>Discription:</td><td>'.$row["description"].'</td></tr>';
echo '<tr><td></td><td><img src="'.$row["logo"].'" width="100px" /></td></tr>';
echo '</table>';
echo '<button name="button">Join</button>';
echo '<hr />';
}
}
?>
</div>
Related
I want my data to be displayed in a row.
Inside my database there are a lot iPhone pictures and some text associated to that particular picture.
I want that data to be shown left to right , I tried and it's working fine for picture NOT for text.
I would like the text to be displayed from left to right instead of top to bottom.
<h2 class="apple">Apple</h2>
<br>
<?php include 'config.php';
$sql="SELECT * FROM apple";
$result=mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0){
while ($fetch=mysqli_fetch_assoc($result)) {
?>
<img src="<?php ECHO $fetch["url"];?>"width="100" height="100" alt="">
<h1> Hello</h1>
<?php
}
}
?>
You can try to display the data in a table with table rows and table data inside it.
<?php
include ('config.php');
echo '<h2 class="apple">Apple</h2>';
$sql = "SELECT * FROM apple";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
echo '<table>';
while ($fetch = mysqli_fetch_all($result)) {
echo '<tr>';
foreach ($fetch as $values) {
echo '<td>'. $values['index of image'] . '</td>';
}
echo '</tr>';
echo '<tr>';
foreach ($fetch as $values) {
echo '<td>'. $values['index of names'] . '</td>';
}
echo '</tr>';
}
echo '</table>';
}
This should get the job done.
I am bit new to php and sql.
I am simply reading from a database table and echoing images to a page. The images are then styled with a text aligned in the middle saying 'Play Video'.
In the table 'adcTable' some entries do not have a video stored.
I would like to have the rows/entries with video say 'Play Video' and the ones without just show the image.
Not to sure how bess to explain. Hope to get some assistance.
<php
$sql = "SELECT client_id, images, video FROM adcTable";
$result = $conn->query($sql);
$count = 1;
echo "<table border = '0' width='720'><tr>";
while($row = $result->fetch_assoc()) {
echo "<td><div class='ccontainer'>"; ?><img class="cimage" src= "<?php echo $row ["images"];?> " ><?php echo "
<div class='middle'>
<div class='text'>Play Video</div>
</div>
</div>
</td>";
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
echo "</tr></table>";
?>
Thanks guys, I was able to use the example provided by BusinessPlanQuickBuilder to solve.
$sql = "SELECT client_id, files, file FROM adcTable";
$result = $conn->query($sql);
$count = 1;
echo "<table border = '0' width='720'><tr>";
while($row = $result->fetch_assoc()) {
if ($row['file'] == "VidUploads/"){
echo "<td>"; ?><img class="cimage" src= "<?php echo $row ["files"];?> " ><?php echo "
</td>";
echo '<script type="text/javascript">',
'$( ".text" ).css( "border", "3px solid red" );',
'</script>';
} else{
echo "<td><div class='ccontainer'>"; ?><img class="cimage" src= "<?php echo $row ["files"];?> " ><?php echo "
<div class='middle'>
<div class='text'>Video</div>
</div>
</div>
</td>";
}
if ($count++ % 2 == 0) {
echo "</tr><tr>";
}
}
echo "</tr></table>";
?>
Use if empty condition on video column. This is the fundamental code, add your formatting as required.
<?php
while($row = $result->fetch_assoc()) {
if (empty ($row['video']) ) {
echo $row ["images"];
} else {
echo "Play Video";
}
}
?>
SO reference to related post
I'm a beginner in PHP and MySQL. I can display data in a table from MySQL database. That's ok. But what I want is to know how to display a popup window with selected data from a table.
I have done this so far, But what I need is when a user clicks or select the table row, a popup window must appear near the table with the select data.
This is my code, please tell me what I have to do:
<?php
include('config.php');
?>
<html>
<head>
<title>Event Patrol</title>
</head>
<body>
<br />
<center>
<?php
$conn = mysql_connect('I have', 'I have', 'I have');
mysql_select_db('I have', $conn);
echo '<table>';
'<tr>';
'<td>Event</td>';
'<td>Record Date</td>';
'</tr>';
$sql = "SELECT * from people where PersonId = '".$_GET["PersonId"]."'";
$rs = mysql_query($sql,$conn) or die(mysql_error());
while($result= mysql_fetch_array($rs)) {
echo '<tr>
<td>'.$result["Event"].'</td>
<td>'.$result["RecordDate"].'</td>
</tr>';
}
echo '</table>';
?>
</div>
</center>
<div id="r" style="width:600px; align:centre"> </div>
<center>
<div id="content">
<?php
// Open database connection
$con = mysql_connect("sql14.cpt1.host-h.net","rootaccess1","Screen_1");
mysql_select_db("sentinelcrm", $con);
$sql = "SELECT * FROM people";
$result = mysql_query($sql);
echo '<table cellpadding="5" cellspacing="0" border="1">';
echo '<tr>';
echo '<th>ID</th>';
echo '<th>Event</th>';
echo '<th>Control Room</th>';
echo '<th>Date</th>';
echo '<th>Site ID </th>';
echo '<th>Action</td>';
echo '</tr>';
while ($rows = mysql_fetch_array($result)) {
echo '<tr>';
echo '<td>';
echo $rows['PersonId'];
echo'</td>';
echo '<td>';
echo $rows['Event'];
echo '</td>';
echo '<td>';
echo $rows['Control_Room_ID'];
echo '</td>';
echo '<td>';
echo $rows['RecordDate'];
echo '</td>';
echo '<td><a href="" >';
echo $rows['Site_ID'];
echo '</a></td>';
echo '<td><input type="button" value="Edit" id="opener"/>';
echo '</tr>';
}
?>
</div>
</center>
</body>
</html>
You have a vulnerability in your code:
$sql= "SELECT * from people where PersonId = '".$_GET["PersonId"]."'";
Since you have not checked what is in this user input, a hacker could inject their own SQL and run that on your database in a way you did not intend. In the case of this library, the hacker cannot run absolutely anything, since it has to make sense in the context of your SELECT query, and (thankfully) this library does not support running many queries at once. That would allow them to issue a DELETE or DROP or something else destructive.
Nevertheless, hackers can modify SELECT statements to give themselves access to accounts or data they should not have access to. This specific query may not be security-sensitive, but nevertheless, security is a mindset you should have all the time, not only when you think it is important.
A simple way to remove the security vulnerability is to cast the number to an integer (assuming this field is indeed an integer and not a string variable). It's not ideal, but it will work:
$personId = (int) $_GET["PersonId"];
$sql= "SELECT * from people where PersonId = '{$personId}'";
That is now safe. However, it is recommended to take both of the following actions:
Switch to a modern library such as PDO/mysql or mysqli, since your library is deprecated
Use query parameterisation (search for it)
How would I go about Limiting the amount of Columns that an HTML Table can Show.The data is Pulled from an SQL table and it is then displayed in a table but I only want the table to Show 6 In a Row then start a New one Instead it Adds Infinate amounts to the single row how can I get around this?
<?php
$con=mysqli_connect("localhost","Username","Password","Database");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM menus");
echo "<table width='400'>";
echo "<tr>";
while($row = mysqli_fetch_array($result))
{
echo'<td>';
?>
<a href="<?php echo $row['link']; ?>" class="tip" alt="<?php echo $row['game']; ?>">
<img src="<?php echo $row['picture']; ?>" alt="" width="150" height="120" class="fade" />
</td>
<?php
}
mysqli_close($con);
?>
</table>
$cols = 0;
echo '<table><tr>';
while($row = fetch()) {
$cols++;
if ($cols >= 6) {
echo '</tr><tr>';
$cols = 0;
}
echo '<td> ...</td>';
}
echo '</tr></table>';
I have a web page with images and when user clicks on any of the image, it has to derive data of that particular image from MYSQL database. What I am doing is using a simple JavaScript popup and putting the data from database. However I am just getting the first item from database on all images.
This is the code:
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=0;
$i = 0;
while($row = mysql_fetch_array($result))
{
if ($colCnt%4==0)
echo '<tr>';
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo($i);
$num = $files[$i];
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br> <div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow">
<div>
<p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>
Ok
</div>
</div>';
echo '</td>';
$colCnt++;
if ($colCnt==4)
{
echo '</tr>';
$colCnt=0;
}
$i++;
}
mysql_close($con);
include 'footer.php';
?>
$row['name'] is just giving out the first name as it is in a while loop. I am not being able to get other names for other images. How can this be done. Any help would be appreciated.
Does one iteration in your while fetch single image data? And what I can understand according to your code is that you are displaying 4 image in a row.
Can you please format your code a bit..its looking too ugly.
I need to know which statement is calling your modal window.
<?php
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=0;
$i = 0;
echo '<tr>';
while($row = mysql_fetch_array($result))
{
$num = $files[$i];
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br>
<div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow"><div><p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>Ok</div>
</div></td>';
$colCnt++;
if ($colCnt % 4 == 0)
{
echo '</tr>';
$colCnt=0;
}
$i++;
}
mysql_close($con);
include 'footer.php';
?>
Try this.
Also see how beautiful the code looks if its properly formatted..
try this
<?php
$files = glob("admin/images/paintings/*.*");
echo '<div id="painting"><table border="0" style="width:590px;">';
$colCnt=4;
while($row = mysql_fetch_array($result))
{
for ($i = 0; $i < $colCnt; $i++) {
echo '<tr>';
echo '<td width="25%" style="font-size:8.5px; font-family:arial">';
echo($i);
$num = $files[$i];
echo '<img id="indPainting" src="'.$num.'" align="absmiddle" /> <br> <div id="paintingName">';
print $row['name'];
echo '<div id="openModal" class="modalWindow">
<div>
<p>This is a sample modal window that can be created using CSS3 and HTML5.'.$row['name'].'</p>
Ok
</div>
</div>';
echo '</td>';
}
if ($colCnt==4)
{
echo '</tr>';
$colCnt=0;
}
}
mysql_close($con);
include 'footer.php';
?>